@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,46 +1,30 @@
1
+ import "core-js/modules/es.array.push.js";
2
+ import "core-js/modules/es.iterator.constructor.js";
3
+ import "core-js/modules/es.set.difference.v2.js";
4
+ import "core-js/modules/es.set.intersection.v2.js";
5
+ import "core-js/modules/es.set.is-disjoint-from.v2.js";
6
+ import "core-js/modules/es.set.is-subset-of.v2.js";
7
+ import "core-js/modules/es.set.is-superset-of.v2.js";
8
+ import "core-js/modules/es.set.symmetric-difference.v2.js";
9
+ import "core-js/modules/es.set.union.v2.js";
1
10
  /* global document */
2
11
 
3
- import {
4
- type ComponentType,
5
- type FunctionComponent,
6
- type ReactNode,
7
- type RefObject,
8
- Suspense,
9
- lazy,
10
- useInsertionEffect,
11
- } from 'react';
12
-
12
+ import { Suspense, lazy, useInsertionEffect } from 'react';
13
13
  import { Barrier } from '@dr.pogodin/js-utils';
14
-
15
- import { type ChunkGroupsT, getSsrContext } from './globalState';
16
-
17
- import {
18
- IS_CLIENT_SIDE,
19
- IS_SERVER_SIDE,
20
- getBuildInfo,
21
- } from './isomorphy';
22
-
23
- // Note: At the client side we can get chunk groups immediately when loading
24
- // the module; at the server-side we only can get them within React render flow.
25
- // Thus, we set and use the following variable at the client-side, and then when
26
- // needed on the server side, we'll fetch it differently.
27
- let clientChunkGroups: ChunkGroupsT;
28
-
29
- if (IS_CLIENT_SIDE) {
30
- // TODO: Rewrite to avoid these overrides of ESLint rules.
31
- /* eslint-disable @typescript-eslint/no-unsafe-assignment,
32
- @typescript-eslint/no-require-imports,
33
- @typescript-eslint/no-unsafe-call,
34
- @typescript-eslint/no-unsafe-member-access */
35
- clientChunkGroups = require('client/getInj').default().CHUNK_GROUPS ?? {};
36
- /* eslint-enable @typescript-eslint/no-unsafe-assignment,
37
- @typescript-eslint/no-require-imports,
38
- @typescript-eslint/no-unsafe-call,
39
- @typescript-eslint/no-unsafe-member-access */
14
+ import { getSsrContext } from "./globalState";
15
+ import { IS_CLIENT_SIDE, IS_SERVER_SIDE, getBuildInfo } from "./isomorphy";
16
+ import { jsx as _jsx } from "react/jsx-runtime";
17
+ function getClientChunkGroups() {
18
+ if (!IS_CLIENT_SIDE) return undefined;
19
+ return (async () => {
20
+ const {
21
+ default: getInj
22
+ } = await import(/* webpackChunkName: "react-utils-client-side-code" */"../../client/getInj");
23
+ const inj = await getInj();
24
+ return inj.CHUNK_GROUPS ?? {};
25
+ })();
40
26
  }
41
-
42
- const refCounts: Record<string, number> = {};
43
-
27
+ const refCounts = {};
44
28
  function getPublicPath() {
45
29
  return getBuildInfo().publicPath;
46
30
  }
@@ -54,26 +38,19 @@ function getPublicPath() {
54
38
  * @param refCount
55
39
  * @return
56
40
  */
57
- function bookStyleSheet(
58
- name: string,
59
- loadedSheets: Set<string>,
60
- refCount: boolean,
61
- ): Promise<void> | undefined {
62
- let res: Barrier<void> | undefined;
41
+ function bookStyleSheet(name, loadedSheets, refCount) {
42
+ let res;
63
43
  const path = `${getPublicPath()}/${name}`;
64
44
  const fullPath = `${document.location.origin}${path}`;
65
-
66
45
  if (!loadedSheets.has(fullPath)) {
67
46
  let link = document.querySelector(`link[href="${path}"]`);
68
-
69
47
  if (!link) {
70
48
  link = document.createElement('link');
71
49
  link.setAttribute('rel', 'stylesheet');
72
50
  link.setAttribute('href', path);
73
51
  document.head.appendChild(link);
74
52
  }
75
-
76
- res = new Barrier<void>();
53
+ res = new Barrier();
77
54
  link.addEventListener('load', () => {
78
55
  if (!res) throw Error('Internal error');
79
56
  void res.resolve();
@@ -83,12 +60,10 @@ function bookStyleSheet(
83
60
  void res.resolve();
84
61
  });
85
62
  }
86
-
87
63
  if (refCount) {
88
64
  const current = refCounts[path] ?? 0;
89
65
  refCounts[path] = 1 + current;
90
66
  }
91
-
92
67
  return res;
93
68
  }
94
69
 
@@ -96,19 +71,19 @@ function bookStyleSheet(
96
71
  * Generates the set of URLs for currently loaded, linked stylesheets.
97
72
  * @return
98
73
  */
99
- function getLoadedStyleSheets(): Set<string> {
100
- const res = new Set<string>();
101
- const { styleSheets } = document;
102
- for (const { href } of styleSheets) {
74
+ function getLoadedStyleSheets() {
75
+ const res = new Set();
76
+ const {
77
+ styleSheets
78
+ } = document;
79
+ for (const {
80
+ href
81
+ } of styleSheets) {
103
82
  if (href) res.add(href);
104
83
  }
105
84
  return res;
106
85
  }
107
-
108
- function assertChunkName(
109
- chunkName: string,
110
- chunkGroups: ChunkGroupsT,
111
- ) {
86
+ function assertChunkName(chunkName, chunkGroups) {
112
87
  if (chunkGroups[chunkName]) return;
113
88
  throw Error(`Unknown chunk name "${chunkName}"`);
114
89
  }
@@ -122,27 +97,18 @@ function assertChunkName(
122
97
  * @return Resolves once all pending stylesheets, necessary for
123
98
  * the chunk, are either loaded, or failed to load.
124
99
  */
125
- export async function bookStyleSheets(
126
- chunkName: string,
127
- chunkGroups: ChunkGroupsT,
128
- refCount: boolean,
129
- ): Promise<void> {
100
+ export async function bookStyleSheets(chunkName, chunkGroups, refCount) {
130
101
  const promises = [];
131
102
  const assets = chunkGroups[chunkName];
132
103
  if (!assets) return Promise.resolve();
133
-
134
104
  const loadedSheets = getLoadedStyleSheets();
135
-
136
105
  for (const asset of assets) {
137
106
  if (asset.endsWith('.css')) {
138
107
  const promise = bookStyleSheet(asset, loadedSheets, refCount);
139
108
  if (promise) promises.push(promise);
140
109
  }
141
110
  }
142
-
143
- return promises.length
144
- ? Promise.allSettled(promises).then()
145
- : Promise.resolve();
111
+ return promises.length ? Promise.allSettled(promises).then() : Promise.resolve();
146
112
  }
147
113
 
148
114
  /**
@@ -152,21 +118,16 @@ export async function bookStyleSheets(
152
118
  * the reference counter).
153
119
  * @param {string} chunkName
154
120
  */
155
- export function freeStyleSheets(
156
- chunkName: string,
157
- chunkGroups: ChunkGroupsT,
158
- ): void {
121
+ export function freeStyleSheets(chunkName, chunkGroups) {
159
122
  const assets = chunkGroups[chunkName];
160
123
  if (!assets) return;
161
-
162
124
  for (const asset of assets) {
163
125
  if (asset.endsWith('.css')) {
164
126
  const path = `${getPublicPath()}/${asset}`;
165
-
166
127
  const pathRefCount = refCounts[path];
167
128
  if (pathRefCount) {
168
129
  if (pathRefCount <= 1) {
169
- document.head.querySelector(`link[href="${path}"]`)!.remove();
130
+ document.head.querySelector(`link[href="${path}"]`).remove();
170
131
  delete refCounts[path];
171
132
  } else refCounts[path] = pathRefCount - 1;
172
133
  }
@@ -176,11 +137,6 @@ export function freeStyleSheets(
176
137
 
177
138
  // Holds the set of chunk names already used for splitComponent() calls.
178
139
  const usedChunkNames = new Set();
179
-
180
- type ComponentOrModule<PropsT> = ComponentType<PropsT> | {
181
- default: ComponentType<PropsT>;
182
- };
183
-
184
140
  /**
185
141
  * Given an async component retrieval function `getComponent()` it creates
186
142
  * a special "code split" component, which uses <Suspense> to asynchronously
@@ -191,26 +147,23 @@ type ComponentOrModule<PropsT> = ComponentType<PropsT> | {
191
147
  * @param {React.Element} [options.placeholder]
192
148
  * @return {React.ElementType}
193
149
  */
194
- export default function splitComponent<
195
- ComponentPropsT extends { children?: ReactNode; ref?: RefObject<unknown> },
196
- >({
150
+ export default function splitComponent({
197
151
  chunkName,
198
152
  getComponent,
199
- placeholder,
200
- }: {
201
- chunkName: string;
202
- getComponent: () => Promise<ComponentOrModule<ComponentPropsT>>;
203
- placeholder?: ReactNode;
204
- }): FunctionComponent<ComponentPropsT> {
205
- // On the client side we can check right away if the chunk name is known.
206
- if (IS_CLIENT_SIDE) assertChunkName(chunkName, clientChunkGroups);
207
-
153
+ placeholder
154
+ }) {
208
155
  // The correct usage of splitComponent() assumes a single call per chunk.
209
156
  if (usedChunkNames.has(chunkName)) {
210
157
  throw Error(`Repeated splitComponent() call for the chunk "${chunkName}"`);
211
158
  } else usedChunkNames.add(chunkName);
159
+ const LazyComponent = /*#__PURE__*/lazy(async () => {
160
+ const clientChunkGroups = await getClientChunkGroups();
212
161
 
213
- const LazyComponent = lazy(async () => {
162
+ // On the client side we can check right away if the chunk name is known.
163
+ if (IS_CLIENT_SIDE) {
164
+ if (!clientChunkGroups) throw Error('Internal error');
165
+ assertChunkName(chunkName, clientChunkGroups);
166
+ }
214
167
  const resolved = await getComponent();
215
168
  const Component = 'default' in resolved ? resolved.default : resolved;
216
169
 
@@ -218,10 +171,10 @@ export default function splitComponent<
218
171
  // the component (the lazy load function is executed by React one at
219
172
  // the frist mount).
220
173
  if (IS_CLIENT_SIDE) {
174
+ if (!clientChunkGroups) throw Error('Internal error');
221
175
  await bookStyleSheets(chunkName, clientChunkGroups, false);
222
176
  }
223
-
224
- const Wrapper: FunctionComponent<ComponentPropsT> = ({
177
+ const Wrapper = ({
225
178
  children,
226
179
  ref,
227
180
  ...rest
@@ -229,7 +182,10 @@ export default function splitComponent<
229
182
  // On the server side we'll assert the chunk name here,
230
183
  // and also push it to the SSR chunks array.
231
184
  if (IS_SERVER_SIDE) {
232
- const { chunkGroups, chunks } = getSsrContext()!;
185
+ const {
186
+ chunkGroups,
187
+ chunks
188
+ } = getSsrContext();
233
189
  assertChunkName(chunkName, chunkGroups);
234
190
  if (!chunks.includes(chunkName)) chunks.push(chunkName);
235
191
  }
@@ -237,39 +193,36 @@ export default function splitComponent<
237
193
  // This takes care about stylesheets management every time an instance of
238
194
  // this component is mounted / unmounted.
239
195
  useInsertionEffect(() => {
196
+ if (!clientChunkGroups) throw Error('Internal error');
240
197
  void bookStyleSheets(chunkName, clientChunkGroups, true);
241
198
  return () => {
242
199
  freeStyleSheets(chunkName, clientChunkGroups);
243
200
  };
244
201
  }, []);
245
-
246
- return (
247
- <Component
248
- // eslint-disable-next-line react/jsx-props-no-spreading
249
- {...(rest as unknown as ComponentPropsT)}
250
- ref={ref}
251
- >
252
- {children}
253
- </Component>
254
- );
202
+ return /*#__PURE__*/_jsx(Component
203
+ // eslint-disable-next-line react/jsx-props-no-spreading
204
+ , {
205
+ ...rest,
206
+ ref: ref,
207
+ children: children
208
+ });
209
+ };
210
+ return {
211
+ default: Wrapper
255
212
  };
256
-
257
- return { default: Wrapper };
258
213
  });
259
-
260
- const CodeSplit: React.FunctionComponent<ComponentPropsT> = ({
214
+ const CodeSplit = ({
261
215
  children,
262
216
  ...rest
263
- }: ComponentPropsT) => (
264
- <Suspense fallback={placeholder}>
265
- <LazyComponent
266
- // eslint-disable-next-line react/jsx-props-no-spreading
267
- {...rest as Parameters<typeof LazyComponent>[0]}
268
- >
269
- {children}
270
- </LazyComponent>
271
- </Suspense>
272
- );
273
-
217
+ }) => /*#__PURE__*/_jsx(Suspense, {
218
+ fallback: placeholder,
219
+ children: /*#__PURE__*/_jsx(LazyComponent
220
+ // eslint-disable-next-line react/jsx-props-no-spreading
221
+ , {
222
+ ...rest,
223
+ children: children
224
+ })
225
+ });
274
226
  return CodeSplit;
275
227
  }
228
+ //# sourceMappingURL=splitComponent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"splitComponent.js","names":["Suspense","lazy","useInsertionEffect","Barrier","getSsrContext","IS_CLIENT_SIDE","IS_SERVER_SIDE","getBuildInfo","jsx","_jsx","getClientChunkGroups","undefined","default","getInj","inj","CHUNK_GROUPS","refCounts","getPublicPath","publicPath","bookStyleSheet","name","loadedSheets","refCount","res","path","fullPath","document","location","origin","has","link","querySelector","createElement","setAttribute","head","appendChild","addEventListener","Error","resolve","current","getLoadedStyleSheets","Set","styleSheets","href","add","assertChunkName","chunkName","chunkGroups","bookStyleSheets","promises","assets","Promise","asset","endsWith","promise","push","length","allSettled","then","freeStyleSheets","pathRefCount","remove","usedChunkNames","splitComponent","getComponent","placeholder","LazyComponent","clientChunkGroups","resolved","Component","Wrapper","children","ref","rest","chunks","includes","CodeSplit","fallback"],"sources":["../../../../src/shared/utils/splitComponent.tsx"],"sourcesContent":["/* global document */\n\nimport {\n type ComponentType,\n type FunctionComponent,\n type ReactNode,\n type RefObject,\n Suspense,\n lazy,\n useInsertionEffect,\n} from 'react';\n\nimport { Barrier } from '@dr.pogodin/js-utils';\n\nimport { type ChunkGroupsT, getSsrContext } from './globalState';\n\nimport {\n IS_CLIENT_SIDE,\n IS_SERVER_SIDE,\n getBuildInfo,\n} from './isomorphy';\n\nfunction getClientChunkGroups(): Promise<ChunkGroupsT> | undefined {\n if (!IS_CLIENT_SIDE) return undefined;\n\n return (async () => {\n const { default: getInj } = await import(/* webpackChunkName: \"react-utils-client-side-code\" */ '../../client/getInj');\n\n const inj = await getInj();\n return inj.CHUNK_GROUPS ?? {};\n })();\n}\n\nconst refCounts: Record<string, number> = {};\n\nfunction getPublicPath() {\n return getBuildInfo().publicPath;\n}\n\n/**\n * Client-side only! Ensures the specified CSS stylesheet is loaded into\n * the document; loads if it is missing; and does simple reference counting\n * to facilitate future clean-up.\n * @param name\n * @param loadedSheets\n * @param refCount\n * @return\n */\nfunction bookStyleSheet(\n name: string,\n loadedSheets: Set<string>,\n refCount: boolean,\n): Promise<void> | undefined {\n let res: Barrier<void> | undefined;\n const path = `${getPublicPath()}/${name}`;\n const fullPath = `${document.location.origin}${path}`;\n\n if (!loadedSheets.has(fullPath)) {\n let link = document.querySelector(`link[href=\"${path}\"]`);\n\n if (!link) {\n link = document.createElement('link');\n link.setAttribute('rel', 'stylesheet');\n link.setAttribute('href', path);\n document.head.appendChild(link);\n }\n\n res = new Barrier<void>();\n link.addEventListener('load', () => {\n if (!res) throw Error('Internal error');\n void res.resolve();\n });\n link.addEventListener('error', () => {\n if (!res) throw Error('Internal error');\n void res.resolve();\n });\n }\n\n if (refCount) {\n const current = refCounts[path] ?? 0;\n refCounts[path] = 1 + current;\n }\n\n return res;\n}\n\n/**\n * Generates the set of URLs for currently loaded, linked stylesheets.\n * @return\n */\nfunction getLoadedStyleSheets(): Set<string> {\n const res = new Set<string>();\n const { styleSheets } = document;\n for (const { href } of styleSheets) {\n if (href) res.add(href);\n }\n return res;\n}\n\nfunction assertChunkName(\n chunkName: string,\n chunkGroups: ChunkGroupsT,\n) {\n if (chunkGroups[chunkName]) return;\n throw Error(`Unknown chunk name \"${chunkName}\"`);\n}\n\n/**\n * Client-side only! Ensures all CSS stylesheets required for the specified\n * code chunk are loaded into the document; loads the missing ones; and does\n * simple reference counting to facilitate future clean-up.\n * @param chunkName Chunk name.\n * @param refCount\n * @return Resolves once all pending stylesheets, necessary for\n * the chunk, are either loaded, or failed to load.\n */\nexport async function bookStyleSheets(\n chunkName: string,\n chunkGroups: ChunkGroupsT,\n refCount: boolean,\n): Promise<void> {\n const promises = [];\n const assets = chunkGroups[chunkName];\n if (!assets) return Promise.resolve();\n\n const loadedSheets = getLoadedStyleSheets();\n\n for (const asset of assets) {\n if (asset.endsWith('.css')) {\n const promise = bookStyleSheet(asset, loadedSheets, refCount);\n if (promise) promises.push(promise);\n }\n }\n\n return promises.length\n ? Promise.allSettled(promises).then()\n : Promise.resolve();\n}\n\n/**\n * Client-side only! Frees from the document all CSS stylesheets that are\n * required by the specified chunk, and have reference counter equal to one\n * (for chunks with larger reference counter values, it just decrements\n * the reference counter).\n * @param {string} chunkName\n */\nexport function freeStyleSheets(\n chunkName: string,\n chunkGroups: ChunkGroupsT,\n): void {\n const assets = chunkGroups[chunkName];\n if (!assets) return;\n\n for (const asset of assets) {\n if (asset.endsWith('.css')) {\n const path = `${getPublicPath()}/${asset}`;\n\n const pathRefCount = refCounts[path];\n if (pathRefCount) {\n if (pathRefCount <= 1) {\n document.head.querySelector(`link[href=\"${path}\"]`)!.remove();\n delete refCounts[path];\n } else refCounts[path] = pathRefCount - 1;\n }\n }\n }\n}\n\n// Holds the set of chunk names already used for splitComponent() calls.\nconst usedChunkNames = new Set();\n\ntype ComponentOrModule<PropsT> = ComponentType<PropsT> | {\n default: ComponentType<PropsT>;\n};\n\ntype GenericComponentPropsT = {\n children?: ReactNode;\n ref?: RefObject<unknown>;\n\n // NOTE: This is necessary, as without it this type (with only optional\n // fields) will be conisdered as \"weak\" by TypeScript, and it will be\n // a error to assign to it any type that does not use \"children\", or \"ref\".\n [propName: string]: unknown;\n};\n\n/**\n * Given an async component retrieval function `getComponent()` it creates\n * a special \"code split\" component, which uses <Suspense> to asynchronously\n * load on demand the code required by `getComponent()`.\n * @param options\n * @param options.chunkName\n * @param {function} options.getComponent\n * @param {React.Element} [options.placeholder]\n * @return {React.ElementType}\n */\nexport default function splitComponent<\n ComponentPropsT extends GenericComponentPropsT,\n>({\n chunkName,\n getComponent,\n placeholder,\n}: {\n chunkName: string;\n getComponent: () => Promise<ComponentOrModule<ComponentPropsT>>;\n placeholder?: ReactNode;\n}): FunctionComponent<ComponentPropsT> {\n // The correct usage of splitComponent() assumes a single call per chunk.\n if (usedChunkNames.has(chunkName)) {\n throw Error(`Repeated splitComponent() call for the chunk \"${chunkName}\"`);\n } else usedChunkNames.add(chunkName);\n\n const LazyComponent = lazy(async () => {\n const clientChunkGroups = await getClientChunkGroups();\n\n // On the client side we can check right away if the chunk name is known.\n if (IS_CLIENT_SIDE) {\n if (!clientChunkGroups) throw Error('Internal error');\n assertChunkName(chunkName, clientChunkGroups);\n }\n\n const resolved = await getComponent();\n const Component = 'default' in resolved ? resolved.default : resolved;\n\n // This pre-loads necessary stylesheets prior to the first mount of\n // the component (the lazy load function is executed by React one at\n // the frist mount).\n if (IS_CLIENT_SIDE) {\n if (!clientChunkGroups) throw Error('Internal error');\n await bookStyleSheets(chunkName, clientChunkGroups, false);\n }\n\n const Wrapper: FunctionComponent<ComponentPropsT> = ({\n children,\n ref,\n ...rest\n }) => {\n // On the server side we'll assert the chunk name here,\n // and also push it to the SSR chunks array.\n if (IS_SERVER_SIDE) {\n const { chunkGroups, chunks } = getSsrContext()!;\n assertChunkName(chunkName, chunkGroups);\n if (!chunks.includes(chunkName)) chunks.push(chunkName);\n }\n\n // This takes care about stylesheets management every time an instance of\n // this component is mounted / unmounted.\n useInsertionEffect(() => {\n if (!clientChunkGroups) throw Error('Internal error');\n void bookStyleSheets(chunkName, clientChunkGroups, true);\n return () => {\n freeStyleSheets(chunkName, clientChunkGroups);\n };\n }, []);\n\n return (\n <Component\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...(rest as unknown as ComponentPropsT)}\n ref={ref}\n >\n {children}\n </Component>\n );\n };\n\n return { default: Wrapper };\n });\n\n const CodeSplit: React.FunctionComponent<ComponentPropsT> = ({\n children,\n ...rest\n }: ComponentPropsT) => (\n <Suspense fallback={placeholder}>\n <LazyComponent\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...rest as Parameters<typeof LazyComponent>[0]}\n >\n {children}\n </LazyComponent>\n </Suspense>\n );\n\n return CodeSplit;\n}\n"],"mappings":";;;;;;;;;AAAA;;AAEA,SAKEA,QAAQ,EACRC,IAAI,EACJC,kBAAkB,QACb,OAAO;AAEd,SAASC,OAAO,QAAQ,sBAAsB;AAE9C,SAA4BC,aAAa;AAEzC,SACEC,cAAc,EACdC,cAAc,EACdC,YAAY;AACO,SAAAC,GAAA,IAAAC,IAAA;AAErB,SAASC,oBAAoBA,CAAA,EAAsC;EACjE,IAAI,CAACL,cAAc,EAAE,OAAOM,SAAS;EAErC,OAAO,CAAC,YAAY;IAClB,MAAM;MAAEC,OAAO,EAAEC;IAAO,CAAC,GAAG,MAAM,MAAM,CAAC,2EAA4E,CAAC;IAEtH,MAAMC,GAAG,GAAG,MAAMD,MAAM,CAAC,CAAC;IAC1B,OAAOC,GAA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,CAAC;MACH,CAAC,EAAE,EAAE,CAAC;MAEN,oBACE1D,IAAA,CAAC4D;MACC;MAAA;QAAA,GACKI,IAAI;QACTD,GAAG,EAAEA,GAAI;QAAAD,QAAA,EAERA;MAAQ,CACA,CAAC;IAEhB,CAAC;IAED,OAAO;MAAE3D,OAAO,EAAE0D;IAAQ,CAAC;EAC7B,CAAC,CAAC;EAEF,MAAMM,SAAmD,GAAGA,CAAC;IAC3DL,QAAQ;IACR,GAAGE;EACY,CAAC,kBAChBhE,IAAA,CAACT,QAAQ;IAAC6E,QAAQ,EAAEZ,WAAY;IAAAM,QAAA,eAC9B9D,IAAA,CAACyD;IACC;IAAA;MAAA,GACIO,IAAI;MAAAF,QAAA,EAEPA;IAAQ,CACI;EAAC,CACR,CACX;EAED,OAAOK,SAAS;AAClB","ignoreList":[]}
@@ -1,19 +1,9 @@
1
1
  import { serialize } from 'cookie';
2
2
  import { useEffect } from 'react';
3
3
  import dayjs from 'dayjs';
4
-
5
- import {
6
- DAY_MS,
7
- HOUR_MS,
8
- MIN_MS,
9
- SEC_MS,
10
- YEAR_MS,
11
- timer,
12
- } from '@dr.pogodin/js-utils';
13
-
14
- import { type ForceT, useGlobalState } from '@dr.pogodin/react-global-state';
15
-
16
- import { getSsrContext } from './globalState';
4
+ import { DAY_MS, HOUR_MS, MIN_MS, SEC_MS, YEAR_MS, timer } from '@dr.pogodin/js-utils';
5
+ import { useGlobalState } from '@dr.pogodin/react-global-state';
6
+ import { getSsrContext } from "./globalState";
17
7
 
18
8
  /**
19
9
  * This react hook wraps Date.now() function in a SSR friendly way,
@@ -28,23 +18,20 @@ import { getSsrContext } from './globalState';
28
18
  export function useCurrent({
29
19
  autorefresh = false,
30
20
  globalStatePath = 'currentTime',
31
- precision = 5 * SEC_MS,
32
- } = {}): number {
33
- const [now, setter] = useGlobalState<ForceT, number>(
34
- globalStatePath,
35
- Date.now,
36
- );
21
+ precision = 5 * SEC_MS
22
+ } = {}) {
23
+ const [now, setter] = useGlobalState(globalStatePath, Date.now);
37
24
  useEffect(() => {
38
- let timerId: NodeJS.Timeout | undefined;
39
- const update = (): void => {
40
- setter((old) => {
25
+ let timerId;
26
+ const update = () => {
27
+ setter(old => {
41
28
  const neu = Date.now();
42
29
  return Math.abs(neu - old) > precision ? neu : old;
43
30
  });
44
31
  if (autorefresh) timerId = setTimeout(update, precision);
45
32
  };
46
33
  update();
47
- return (): void => {
34
+ return () => {
48
35
  if (timerId) clearTimeout(timerId);
49
36
  };
50
37
  }, [autorefresh, precision, setter]);
@@ -64,28 +51,25 @@ export function useCurrent({
64
51
  // to verify the give globalStatePath is correct?
65
52
  export function useTimezoneOffset({
66
53
  cookieName = 'timezoneOffset',
67
- globalStatePath = 'timezoneOffset',
68
- } = {}): number {
54
+ globalStatePath = 'timezoneOffset'
55
+ } = {}) {
69
56
  const ssrContext = getSsrContext(false);
70
- const [offset, setOffset] = useGlobalState<ForceT, number>(
71
- globalStatePath,
72
- () => {
73
- const value = cookieName
74
- && ssrContext?.req.cookies[cookieName] as string;
75
- return value ? parseInt(value) : 0;
76
- },
77
- );
57
+ const [offset, setOffset] = useGlobalState(globalStatePath, () => {
58
+ const value = cookieName && ssrContext?.req.cookies[cookieName];
59
+ return value ? parseInt(value) : 0;
60
+ });
78
61
  useEffect(() => {
79
62
  const date = new Date();
80
63
  const value = date.getTimezoneOffset();
81
64
  setOffset(value);
82
65
  if (cookieName) {
83
- document.cookie = serialize(cookieName, value.toString(), { path: '/' });
66
+ document.cookie = serialize(cookieName, value.toString(), {
67
+ path: '/'
68
+ });
84
69
  }
85
70
  }, [cookieName, setOffset]);
86
71
  return offset;
87
72
  }
88
-
89
73
  const time = {
90
74
  DAY_MS,
91
75
  HOUR_MS,
@@ -95,7 +79,7 @@ const time = {
95
79
  now: Date.now,
96
80
  timer,
97
81
  useCurrent,
98
- useTimezoneOffset,
82
+ useTimezoneOffset
99
83
  };
100
-
101
84
  export default Object.assign(dayjs, time);
85
+ //# sourceMappingURL=time.js.map
@@ -0,0 +1 @@
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,SAASA,SAAS,QAAQ,QAAQ;AAClC,SAASC,SAAS,QAAQ,OAAO;AACjC,OAAOC,KAAK,MAAM,OAAO;AAEzB,SACEC,MAAM,EACNC,OAAO,EACPC,MAAM,EACNC,MAAM,EACNC,OAAO,EACPC,KAAK,QACA,sBAAsB;AAE7B,SAAsBC,cAAc,QAAQ,gCAAgC;AAE5E,SAASC,aAAa;;AAEtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,UAAUA,CAAC;EACzBC,WAAW,GAAG,KAAK;EACnBC,eAAe,GAAG,aAAa;EAC/BC,SAAS,GAAG,CAAC,GAAGR;AAClB,CAAC,GAAG,CAAC,CAAC,EAAU;EACd,MAAM,CAACS,GAAG,EAAEC,MAAM,CAAC,GAAGP,cAAc,CAClCI,eAAe,EACfI,IAAI,CAACF,GACP,CAAC;EACDd,SAAS,CAAC,MAAM;IACd,IAAIiB,OAAmC;IACvC,MAAMC,MAAM,GAA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AU,EAAEI,KAAK,CAACQ,QAAQ,CAAC,CAAC,EAAE;QAAEC,IAAI,EAAE;MAAI,CAAC,CAAC;IAC1E;EACF,CAAC,EAAE,CAACb,UAAU,EAAEG,SAAS,CAAC,CAAC;EAC3B,OAAOD,MAAM;AACf;AAEA,MAAMY,IAAI,GAAG;EACXtC,MAAM;EACNC,OAAO;EACPC,MAAM;EACNC,MAAM;EACNC,OAAO;EACPQ,GAAG,EAAEE,IAAI,CAACF,GAAG;EACbP,KAAK;EACLG,UAAU;EACVe;AACF,CAAC;AAED,eAAegB,MAAM,CAACC,MAAM,CAACzC,KAAK,EAAEuC,IAAI,CAAC","ignoreList":[]}
@@ -0,0 +1,67 @@
1
+ import "core-js/modules/es.iterator.constructor.js";
2
+ import "core-js/modules/es.iterator.for-each.js";
3
+ // eslint-disable-next-line import/enforce-node-protocol-usage
4
+ import { createRequire } from 'module';
5
+ import { IS_CLIENT_SIDE, IS_SERVER_SIDE } from "./isomorphy";
6
+ let require;
7
+ if (IS_SERVER_SIDE) require = createRequire(import.meta.url);
8
+
9
+ /**
10
+ * Requires the specified module without including it into the bundle during
11
+ * Webpack build.
12
+ * @param modulePath
13
+ * @param [basePath]
14
+ * @return Required module.
15
+ */
16
+ export function requireWeak(modulePath,
17
+ // TODO: For now `basePath` can be provided directly as a string here,
18
+ // for backward compatibility. Deprecate it in future, if any other
19
+ // breaking changes are done for requireWeak().
20
+ basePathOrOptions) {
21
+ if (IS_CLIENT_SIDE) return null;
22
+ let basePath;
23
+ let ops;
24
+ if (typeof basePathOrOptions === 'string') {
25
+ basePath = basePathOrOptions;
26
+ } else {
27
+ ops = basePathOrOptions ?? {};
28
+ ({
29
+ basePath
30
+ } = ops);
31
+ }
32
+
33
+ // eslint-disable-next-line @typescript-eslint/unbound-method
34
+ const {
35
+ resolve
36
+ } = require('node:path');
37
+ const path = basePath ? resolve(basePath, modulePath) : modulePath;
38
+ const module = require(path);
39
+ if (!('default' in module) || !module.default) return module;
40
+ const {
41
+ default: def,
42
+ ...named
43
+ } = module;
44
+ const res = def;
45
+ Object.entries(named).forEach(([name, value]) => {
46
+ const assigned = res[name];
47
+ if (assigned === undefined) {
48
+ res[name] = value;
49
+ } else if (assigned !== value) {
50
+ throw Error('Conflict between default and named exports');
51
+ }
52
+ });
53
+ return res;
54
+ }
55
+
56
+ /**
57
+ * Resolves specified module path with help of Babel's module resolver.
58
+ * Yes, the function itself just returns its argument to the caller, but Babel
59
+ * is configured to resolve the first argument of resolveWeak(..) function, thus
60
+ * the result will be the resolved path.
61
+ * @param {string} modulePath
62
+ * @return {string} Absolute or relative path to the module.
63
+ */
64
+ export function resolveWeak(modulePath) {
65
+ return modulePath;
66
+ }
67
+ //# sourceMappingURL=webpack.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webpack.js","names":["createRequire","IS_CLIENT_SIDE","IS_SERVER_SIDE","require","import","meta","url","requireWeak","modulePath","basePathOrOptions","basePath","ops","resolve","path","module","default","def","named","res","Object","entries","forEach","name","value","assigned","undefined","Error","resolveWeak"],"sources":["../../../../src/shared/utils/webpack.ts"],"sourcesContent":["import type PathNS from 'node:path';\n\n// eslint-disable-next-line import/enforce-node-protocol-usage\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":";;AAEA;AACA,SAASA,aAAa,QAAQ,QAAQ;AAEtC,SAASC,cAAc,EAAEC,cAAc;AAUvC,IAAIC,OAA+C;AAEnD,IAAID,cAAc,EAAEC,OAAO,GAAGH,aAAa,CAACI,MAAM,CAACC,IAAI,CAACC,GAAG,CAAC;;AAE5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,WAAWA,CACzBC,UAAkB;AAElB;AACA;AACA;AACAC,iBAAgD,EACrB;EAC3B,IAAIR,cAAc,EAAE,OAAO,IAAI;EAE/B,IAAIS,QAA4B;EAChC,IAAIC,GAAwB;EAC5B,IAAI,OAAOF,iBAAiB,KAAK,QAAQ,EAAE;IACzCC,QAAQ,GAAGD,iBAAiB;EAC9B,CAAC,MAAM;IACLE,GAAG,GAAGF,iBAAiB,IAAI,CAAC,CAAC;IAC7B,CAAC;MAAEC;IAAS,CAAC,GAAGC,GAAG;EACrB;;EAEA;EACA,MAAM;IAAEC;EAAQ,CAAC,GAAGT,OAAO,CAAE,WAAW,CAAkB;EAE1D,MAAMU,IAAI,GAAGH,QAAQ,GAAGE,OAAO,CAACF,QAAQ,EAAEF,UAAU,CAAC,GAAGA,UAAU;EAElE,MAAMM,MAAM,GAAGX,OAAO,CAAEU,IAAI,CAAM;EAElC,IAAI,EAAE,SAAS,IAAIC,MAAM,CAAC,IAAI,CAACA,MAAM,CAACC,OAAO,EAAE,OAAOD,MAAM;EAE5D,MAAM;IAAEC,OAAO,EAAEC,GAAG;IAAE,GAAGC;EAAM,CAAC,GAAGH,MAAM;EAEzC,MAAMI,GAAG,GAAGF,GAAyB;EAErCG,MAAM,CAACC,OAAO,CAACH,KAAK,CAAC,CAACI,OAAO,CAAC,CAAC,CAACC,IAAI,EAAEC,KAAK,CAAC,KAAK;IAC/C,MAAMC,QAAQ,GAAGN,GAAG,CAACI,IAAI,CAA6B;IACtD,IAAIE,QAAQ,KAAKC,SAAS,EAAE;MACzBP,GAAG,CAACI,IAAI,CAA6B,GAAeC,KAAK;IAC5D,CAAC,MAAM,IAAIC,QAAQ,KAAKD,KAAK,EAAE;MAC7B,MAAMG,KAAK,CAAC,4CAA4C,CAAC;IAC3D;EACF,CAAC,CAAC;EACF,OAAOR,GAAG;AACZ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASS,WAAWA,CAACnB,UAAkB,EAAU;EACtD,OAAOA,UAAU;AACnB","ignoreList":[]}
@@ -34,7 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.default = getConfig;
37
- const lodash_1 = require("lodash");
37
+ const lodash_es_1 = require("lodash-es");
38
38
  const webpack_1 = __importStar(require("./webpack"));
39
39
  /**
40
40
  * Creates a new base config.
@@ -48,12 +48,21 @@ const webpack_1 = __importStar(require("./webpack"));
48
48
  */
49
49
  function newBase(babel, options = {}) {
50
50
  var _a;
51
- const config = (0, webpack_1.default)(babel, Object.assign({ modules: 'cjs', targets: 'current node' }, options));
51
+ const config = (0, webpack_1.default)(babel, Object.assign({
52
+ // NOTE: It make sense to have "modules": false here,
53
+ // but it needs a bunch of build configuration updates,
54
+ // and ends-up with conflict of Jest with ES modules (as now
55
+ // Jest relies on babel.config.js, which transpiles everything
56
+ // into CJS).
57
+ modules: 'cjs', targets: 'maintained node versions' }, options));
52
58
  const baseAssetsOutputPath = (_a = options.baseAssetsOutputPath) !== null && _a !== void 0 ? _a : '';
53
59
  config.plugins.push(['@dr.pogodin/transform-assets', {
54
60
  extensions: ['gif', 'jpeg', 'jpg', 'png'],
55
61
  name: `${baseAssetsOutputPath}/images/[md4:hash:20].[ext]`,
56
62
  }]);
63
+ if (options.modules === false) {
64
+ config.plugins.push('babel-plugin-add-import-extension');
65
+ }
57
66
  const moduleResolverPluginOps = config.plugins.find((x) => Array.isArray(x) && x[0] === 'module-resolver')[1];
58
67
  moduleResolverPluginOps.transformFunctions = [
59
68
  'requireWeak',
@@ -62,7 +71,7 @@ function newBase(babel, options = {}) {
62
71
  'webpack.resolveWeak',
63
72
  ];
64
73
  if (babel.env() === webpack_1.ENVIRONMENTS.DEV) {
65
- (0, lodash_1.pull)(config.plugins, 'react-refresh/babel');
74
+ (0, lodash_es_1.pull)(config.plugins, 'react-refresh/babel');
66
75
  }
67
76
  return config;
68
77
  }
@@ -30,13 +30,18 @@ function newBaseConfig(options) {
30
30
  './src',
31
31
  ],
32
32
  }],
33
- '@babel/transform-runtime',
33
+ ['@babel/transform-runtime', {
34
+ useESModules: true,
35
+ }],
34
36
  ],
35
37
  presets: [
36
38
  ['@babel/env', {
39
+ bugfixes: true,
40
+ corejs: '3.46',
37
41
  // Leaves it to the Webpack to deal with modules.
38
42
  modules: (_a = options.modules) !== null && _a !== void 0 ? _a : false,
39
43
  targets: (_b = options.targets) !== null && _b !== void 0 ? _b : 'defaults',
44
+ useBuiltIns: 'usage',
40
45
  }],
41
46
  // TODO: Starting from Babel 8, "automatic" will be the default runtime,
42
47
  // thus once upgraded to Babel 8, runtime should be removed from
@@ -5,6 +5,13 @@ const path = require('node:path');
5
5
 
6
6
  const globalLibDir = path.resolve(process.execPath, '../../lib/node_modules');
7
7
 
8
+ const modulesToTransform = [
9
+ '@dr.pogodin/react-global-state',
10
+ '@dr.pogodin/react-utils',
11
+ 'lodash-es',
12
+ 'uuid',
13
+ ];
14
+
8
15
  module.exports = {
9
16
  collectCoverage: true,
10
17
  collectCoverageFrom: [
@@ -36,7 +43,6 @@ module.exports = {
36
43
  '\\.((j|t)sx?|svg)$': 'babel-jest',
37
44
  },
38
45
  transformIgnorePatterns: [
39
- '/node_modules/(?!@dr.pogodin/react-utils|uuid)',
46
+ `/node_modules/(?!${modulesToTransform.join('|')})`,
40
47
  ],
41
-
42
48
  };
@@ -1,4 +1,6 @@
1
- /* global globalThis, require */
1
+ /* global globalThis, require, window */
2
+
3
+ import { subtle } from 'node:crypto';
2
4
 
3
5
  // eslint-disable-next-line import/no-unassigned-import
4
6
  import 'raf/polyfill';
@@ -11,3 +13,8 @@ if (!globalThis.TextEncoder || !globalThis.TextDecoder) {
11
13
  globalThis.TextEncoder = TextEncoder;
12
14
  globalThis.TextDecoder = TextDecoder;
13
15
  }
16
+
17
+ // Polyfill of crypto.subtle in JSDOM environments.
18
+ if (typeof window !== 'undefined') {
19
+ window.crypto.subtle = subtle;
20
+ }