@dr.pogodin/react-utils 1.47.0-alpha.1 → 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 (306) hide show
  1. package/babel.config.js +1 -1
  2. package/babel.module.config.js +11 -0
  3. package/bin/build.js +8 -4
  4. package/bin/setup.js +2 -3
  5. package/build/development/client/getInj.js +57 -44
  6. package/build/development/client/getInj.js.map +1 -1
  7. package/build/development/client/index.js +15 -21
  8. package/build/development/client/index.js.map +1 -1
  9. package/build/development/client/init.js +2 -6
  10. package/build/development/client/init.js.map +1 -1
  11. package/build/development/index.js +3 -183
  12. package/build/development/index.js.map +1 -1
  13. package/build/development/server/Cache.js +1 -8
  14. package/build/development/server/Cache.js.map +1 -1
  15. package/build/development/server/index.js +22 -50
  16. package/build/development/server/index.js.map +1 -1
  17. package/build/development/server/renderer.js +83 -92
  18. package/build/development/server/renderer.js.map +1 -1
  19. package/build/development/server/server.js +58 -62
  20. package/build/development/server/server.js.map +1 -1
  21. package/build/development/server/utils/errors.js +8 -31
  22. package/build/development/server/utils/errors.js.map +1 -1
  23. package/build/development/server/utils/index.js +2 -9
  24. package/build/development/server/utils/index.js.map +1 -1
  25. package/build/development/shared/components/Button/index.js +9 -16
  26. package/build/development/shared/components/Button/index.js.map +1 -1
  27. package/build/development/shared/components/Checkbox/index.js +6 -13
  28. package/build/development/shared/components/Checkbox/index.js.map +1 -1
  29. package/build/development/shared/components/GenericLink/index.js +4 -10
  30. package/build/development/shared/components/GenericLink/index.js.map +1 -1
  31. package/build/development/shared/components/Input/index.js +11 -18
  32. package/build/development/shared/components/Input/index.js.map +1 -1
  33. package/build/development/shared/components/Link.js +6 -13
  34. package/build/development/shared/components/Link.js.map +1 -1
  35. package/build/development/shared/components/Modal/index.js +16 -22
  36. package/build/development/shared/components/Modal/index.js.map +1 -1
  37. package/build/development/shared/components/NavLink.js +6 -13
  38. package/build/development/shared/components/NavLink.js.map +1 -1
  39. package/build/development/shared/components/PageLayout/index.js +7 -14
  40. package/build/development/shared/components/PageLayout/index.js.map +1 -1
  41. package/build/development/shared/components/TextArea/index.js +15 -22
  42. package/build/development/shared/components/TextArea/index.js.map +1 -1
  43. package/build/development/shared/components/Throbber/index.js +7 -14
  44. package/build/development/shared/components/Throbber/index.js.map +1 -1
  45. package/build/development/shared/components/WithTooltip/Tooltip.js +12 -18
  46. package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
  47. package/build/development/shared/components/WithTooltip/index.js +16 -23
  48. package/build/development/shared/components/WithTooltip/index.js.map +1 -1
  49. package/build/development/shared/components/YouTubeVideo/index.js +10 -17
  50. package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
  51. package/build/development/shared/components/index.js +16 -130
  52. package/build/development/shared/components/index.js.map +1 -1
  53. package/build/development/shared/components/selectors/CustomDropdown/Options/index.js +18 -19
  54. package/build/development/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  55. package/build/development/shared/components/selectors/CustomDropdown/index.js +24 -28
  56. package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  57. package/build/development/shared/components/selectors/NativeDropdown/index.js +19 -19
  58. package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  59. package/build/development/shared/components/selectors/Switch/index.js +12 -17
  60. package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
  61. package/build/development/shared/components/selectors/common.js +1 -7
  62. package/build/development/shared/components/selectors/common.js.map +1 -1
  63. package/build/development/shared/components/selectors/index.js +3 -27
  64. package/build/development/shared/components/selectors/index.js.map +1 -1
  65. package/build/development/shared/utils/config.js +40 -21
  66. package/build/development/shared/utils/config.js.map +1 -1
  67. package/build/development/shared/utils/globalState.js +3 -8
  68. package/build/development/shared/utils/globalState.js.map +1 -1
  69. package/build/development/shared/utils/index.js +12 -89
  70. package/build/development/shared/utils/index.js.map +1 -1
  71. package/build/development/shared/utils/isomorphy/buildInfo.js +2 -9
  72. package/build/development/shared/utils/isomorphy/buildInfo.js.map +1 -1
  73. package/build/development/shared/utils/isomorphy/environment-check.js +2 -8
  74. package/build/development/shared/utils/isomorphy/environment-check.js.map +1 -1
  75. package/build/development/shared/utils/isomorphy/index.js +7 -32
  76. package/build/development/shared/utils/isomorphy/index.js.map +1 -1
  77. package/build/development/shared/utils/jest/E2eSsrEnv.js +24 -31
  78. package/build/development/shared/utils/jest/E2eSsrEnv.js.map +1 -1
  79. package/build/development/shared/utils/jest/global.js +1 -7
  80. package/build/development/shared/utils/jest/global.js.map +1 -1
  81. package/build/development/shared/utils/jest/index.js +20 -44
  82. package/build/development/shared/utils/jest/index.js.map +1 -1
  83. package/build/development/shared/utils/splitComponent.js +54 -46
  84. package/build/development/shared/utils/splitComponent.js.map +1 -1
  85. package/build/development/shared/utils/time.js +22 -31
  86. package/build/development/shared/utils/time.js.map +1 -1
  87. package/build/development/shared/utils/webpack.js +17 -16
  88. package/build/development/shared/utils/webpack.js.map +1 -1
  89. package/build/production/client/getInj.js +13 -11
  90. package/build/production/client/getInj.js.map +1 -1
  91. package/build/production/client/index.js +3 -3
  92. package/build/production/client/index.js.map +1 -1
  93. package/build/production/client/init.js +2 -2
  94. package/build/production/client/init.js.map +1 -1
  95. package/build/production/index.js +2 -6
  96. package/build/production/index.js.map +1 -1
  97. package/build/production/server/Cache.js +3 -3
  98. package/build/production/server/Cache.js.map +1 -1
  99. package/build/production/server/index.js +8 -8
  100. package/build/production/server/index.js.map +1 -1
  101. package/build/production/server/renderer.js +24 -25
  102. package/build/production/server/renderer.js.map +1 -1
  103. package/build/production/server/server.js +9 -11
  104. package/build/production/server/server.js.map +1 -1
  105. package/build/production/server/utils/errors.js +9 -9
  106. package/build/production/server/utils/errors.js.map +1 -1
  107. package/build/production/server/utils/index.js +2 -1
  108. package/build/production/server/utils/index.js.map +1 -1
  109. package/build/production/shared/components/Button/index.js +4 -4
  110. package/build/production/shared/components/Button/index.js.map +1 -1
  111. package/build/production/shared/components/Checkbox/index.js +1 -1
  112. package/build/production/shared/components/Checkbox/index.js.map +1 -1
  113. package/build/production/shared/components/GenericLink/index.js +4 -4
  114. package/build/production/shared/components/GenericLink/index.js.map +1 -1
  115. package/build/production/shared/components/Input/index.js +5 -5
  116. package/build/production/shared/components/Input/index.js.map +1 -1
  117. package/build/production/shared/components/Link.js +3 -3
  118. package/build/production/shared/components/Link.js.map +1 -1
  119. package/build/production/shared/components/Modal/index.js +7 -7
  120. package/build/production/shared/components/Modal/index.js.map +1 -1
  121. package/build/production/shared/components/NavLink.js +2 -2
  122. package/build/production/shared/components/NavLink.js.map +1 -1
  123. package/build/production/shared/components/PageLayout/index.js +2 -2
  124. package/build/production/shared/components/PageLayout/index.js.map +1 -1
  125. package/build/production/shared/components/TextArea/index.js +5 -5
  126. package/build/production/shared/components/TextArea/index.js.map +1 -1
  127. package/build/production/shared/components/Throbber/index.js +2 -2
  128. package/build/production/shared/components/Throbber/index.js.map +1 -1
  129. package/build/production/shared/components/WithTooltip/Tooltip.js +4 -4
  130. package/build/production/shared/components/WithTooltip/Tooltip.js.map +1 -1
  131. package/build/production/shared/components/WithTooltip/index.js +4 -4
  132. package/build/production/shared/components/WithTooltip/index.js.map +1 -1
  133. package/build/production/shared/components/YouTubeVideo/index.js +4 -4
  134. package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
  135. package/build/production/shared/components/index.js +3 -1
  136. package/build/production/shared/components/index.js.map +1 -1
  137. package/build/production/shared/components/selectors/CustomDropdown/Options/index.js +2 -2
  138. package/build/production/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  139. package/build/production/shared/components/selectors/CustomDropdown/index.js +2 -2
  140. package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  141. package/build/production/shared/components/selectors/NativeDropdown/index.js +4 -4
  142. package/build/production/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  143. package/build/production/shared/components/selectors/Switch/index.js +1 -1
  144. package/build/production/shared/components/selectors/Switch/index.js.map +1 -1
  145. package/build/production/shared/components/selectors/common.js +2 -2
  146. package/build/production/shared/components/selectors/common.js.map +1 -1
  147. package/build/production/shared/components/selectors/index.js +1 -1
  148. package/build/production/shared/components/selectors/index.js.map +1 -1
  149. package/build/production/shared/utils/config.js +8 -6
  150. package/build/production/shared/utils/config.js.map +1 -1
  151. package/build/production/shared/utils/globalState.js +2 -2
  152. package/build/production/shared/utils/globalState.js.map +1 -1
  153. package/build/production/shared/utils/index.js +1 -1
  154. package/build/production/shared/utils/index.js.map +1 -1
  155. package/build/production/shared/utils/isomorphy/buildInfo.js +3 -3
  156. package/build/production/shared/utils/isomorphy/buildInfo.js.map +1 -1
  157. package/build/production/shared/utils/isomorphy/environment-check.js +3 -3
  158. package/build/production/shared/utils/isomorphy/environment-check.js.map +1 -1
  159. package/build/production/shared/utils/isomorphy/index.js +4 -4
  160. package/build/production/shared/utils/isomorphy/index.js.map +1 -1
  161. package/build/production/shared/utils/jest/E2eSsrEnv.js +14 -14
  162. package/build/production/shared/utils/jest/E2eSsrEnv.js.map +1 -1
  163. package/build/production/shared/utils/jest/global.js +1 -1
  164. package/build/production/shared/utils/jest/global.js.map +1 -1
  165. package/build/production/shared/utils/jest/index.js +11 -11
  166. package/build/production/shared/utils/jest/index.js.map +1 -1
  167. package/build/production/shared/utils/splitComponent.js +11 -22
  168. package/build/production/shared/utils/splitComponent.js.map +1 -1
  169. package/build/production/shared/utils/time.js +3 -3
  170. package/build/production/shared/utils/time.js.map +1 -1
  171. package/build/production/shared/utils/webpack.js +6 -6
  172. package/build/production/shared/utils/webpack.js.map +1 -1
  173. package/build/types-code/client/getInj.d.ts +1 -2
  174. package/build/types-code/client/index.d.ts +1 -1
  175. package/build/types-code/index.d.ts +1 -7
  176. package/build/types-code/server/index.d.ts +6 -11
  177. package/build/types-code/server/utils/index.d.ts +1 -1
  178. package/build/types-code/shared/utils/config.d.ts +4 -2
  179. package/build/types-code/shared/utils/index.d.ts +2 -2
  180. package/build/types-code/shared/utils/splitComponent.d.ts +6 -4
  181. package/build/web/client/getInj.js +55 -44
  182. package/build/web/client/getInj.js.map +1 -1
  183. package/build/web/client/index.js +15 -21
  184. package/build/web/client/index.js.map +1 -1
  185. package/build/web/client/init.js +2 -4
  186. package/build/web/client/init.js.map +1 -1
  187. package/build/web/index.js +1 -15
  188. package/build/web/index.js.map +1 -1
  189. package/build/web/server/index.js +12 -21
  190. package/build/web/server/index.js.map +1 -1
  191. package/build/web/server/renderer.js +34 -40
  192. package/build/web/server/renderer.js.map +1 -1
  193. package/build/web/server/server.js +14 -11
  194. package/build/web/server/server.js.map +1 -1
  195. package/build/web/server/utils/index.js +1 -1
  196. package/build/web/server/utils/index.js.map +1 -1
  197. package/build/web/shared/components/Button/index.js +1 -1
  198. package/build/web/shared/components/Button/index.js.map +1 -1
  199. package/build/web/shared/components/Checkbox/index.js +1 -1
  200. package/build/web/shared/components/Checkbox/index.js.map +1 -1
  201. package/build/web/shared/components/Input/index.js +1 -1
  202. package/build/web/shared/components/Input/index.js.map +1 -1
  203. package/build/web/shared/components/Modal/index.js +3 -3
  204. package/build/web/shared/components/Modal/index.js.map +1 -1
  205. package/build/web/shared/components/PageLayout/index.js +1 -1
  206. package/build/web/shared/components/PageLayout/index.js.map +1 -1
  207. package/build/web/shared/components/TextArea/index.js +1 -1
  208. package/build/web/shared/components/TextArea/index.js.map +1 -1
  209. package/build/web/shared/components/Throbber/index.js +1 -1
  210. package/build/web/shared/components/Throbber/index.js.map +1 -1
  211. package/build/web/shared/components/WithTooltip/index.js +1 -1
  212. package/build/web/shared/components/WithTooltip/index.js.map +1 -1
  213. package/build/web/shared/components/YouTubeVideo/index.js +1 -1
  214. package/build/web/shared/components/YouTubeVideo/index.js.map +1 -1
  215. package/build/web/shared/components/selectors/CustomDropdown/Options/index.js +3 -0
  216. package/build/web/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  217. package/build/web/shared/components/selectors/CustomDropdown/index.js +3 -1
  218. package/build/web/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  219. package/build/web/shared/components/selectors/NativeDropdown/index.js +4 -1
  220. package/build/web/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  221. package/build/web/shared/components/selectors/Switch/index.js +2 -1
  222. package/build/web/shared/components/selectors/Switch/index.js.map +1 -1
  223. package/build/web/shared/utils/config.js +38 -14
  224. package/build/web/shared/utils/config.js.map +1 -1
  225. package/build/web/shared/utils/index.js +2 -2
  226. package/build/web/shared/utils/index.js.map +1 -1
  227. package/build/web/shared/utils/jest/E2eSsrEnv.js +3 -2
  228. package/build/web/shared/utils/jest/E2eSsrEnv.js.map +1 -1
  229. package/build/web/shared/utils/splitComponent.js +27 -20
  230. package/build/web/shared/utils/splitComponent.js.map +1 -1
  231. package/build/web/shared/utils/webpack.js +13 -7
  232. package/build/web/shared/utils/webpack.js.map +1 -1
  233. package/config/babel/node-ssr.js +12 -6
  234. package/config/babel/webpack.js +6 -1
  235. package/config/jest/default.js +8 -2
  236. package/config/jest/setup.js +8 -1
  237. package/config/webpack/app-base.js +23 -15
  238. package/config/webpack/app-development.js +2 -3
  239. package/config/webpack/lib-base.js +1 -2
  240. package/package.json +35 -25
  241. package/types.d.ts +1 -6
  242. package/node-entry.js +0 -15
  243. package/src/client/getInj.ts +0 -51
  244. package/src/client/index.tsx +0 -43
  245. package/src/client/init.ts +0 -52
  246. package/src/index.ts +0 -79
  247. package/src/server/Cache.ts +0 -61
  248. package/src/server/index.ts +0 -249
  249. package/src/server/renderer.tsx +0 -653
  250. package/src/server/server.ts +0 -332
  251. package/src/server/utils/errors.ts +0 -122
  252. package/src/server/utils/index.ts +0 -3
  253. package/src/shared/components/Button/index.tsx +0 -130
  254. package/src/shared/components/Button/style.scss +0 -54
  255. package/src/shared/components/Checkbox/index.tsx +0 -53
  256. package/src/shared/components/Checkbox/theme.scss +0 -63
  257. package/src/shared/components/GenericLink/index.tsx +0 -141
  258. package/src/shared/components/GenericLink/style.scss +0 -3
  259. package/src/shared/components/Input/index.tsx +0 -96
  260. package/src/shared/components/Input/theme.scss +0 -52
  261. package/src/shared/components/Link.tsx +0 -25
  262. package/src/shared/components/Modal/base-theme.scss +0 -38
  263. package/src/shared/components/Modal/index.tsx +0 -177
  264. package/src/shared/components/Modal/styles.scss +0 -3
  265. package/src/shared/components/NavLink.tsx +0 -18
  266. package/src/shared/components/PageLayout/base-theme.scss +0 -30
  267. package/src/shared/components/PageLayout/index.tsx +0 -51
  268. package/src/shared/components/TextArea/index.tsx +0 -139
  269. package/src/shared/components/TextArea/style.scss +0 -68
  270. package/src/shared/components/Throbber/index.tsx +0 -28
  271. package/src/shared/components/Throbber/theme.scss +0 -26
  272. package/src/shared/components/WithTooltip/Tooltip.tsx +0 -274
  273. package/src/shared/components/WithTooltip/default-theme.scss +0 -36
  274. package/src/shared/components/WithTooltip/index.tsx +0 -186
  275. package/src/shared/components/YouTubeVideo/base.scss +0 -15
  276. package/src/shared/components/YouTubeVideo/index.tsx +0 -73
  277. package/src/shared/components/YouTubeVideo/throbber.scss +0 -11
  278. package/src/shared/components/index.ts +0 -20
  279. package/src/shared/components/selectors/CustomDropdown/Options/index.tsx +0 -124
  280. package/src/shared/components/selectors/CustomDropdown/Options/style.scss +0 -6
  281. package/src/shared/components/selectors/CustomDropdown/index.tsx +0 -146
  282. package/src/shared/components/selectors/CustomDropdown/theme.scss +0 -118
  283. package/src/shared/components/selectors/NativeDropdown/index.tsx +0 -90
  284. package/src/shared/components/selectors/NativeDropdown/theme.scss +0 -81
  285. package/src/shared/components/selectors/Switch/index.tsx +0 -74
  286. package/src/shared/components/selectors/Switch/theme.scss +0 -39
  287. package/src/shared/components/selectors/common.ts +0 -57
  288. package/src/shared/components/selectors/index.ts +0 -8
  289. package/src/shared/utils/config.ts +0 -28
  290. package/src/shared/utils/globalState.ts +0 -44
  291. package/src/shared/utils/index.ts +0 -45
  292. package/src/shared/utils/isomorphy/buildInfo.ts +0 -50
  293. package/src/shared/utils/isomorphy/environment-check.ts +0 -18
  294. package/src/shared/utils/isomorphy/index.ts +0 -36
  295. package/src/shared/utils/jest/E2eSsrEnv.ts +0 -305
  296. package/src/shared/utils/jest/global.ts +0 -17
  297. package/src/shared/utils/jest/index.ts +0 -215
  298. package/src/shared/utils/splitComponent.tsx +0 -275
  299. package/src/shared/utils/time.ts +0 -101
  300. package/src/shared/utils/webpack.ts +0 -74
  301. package/src/styles/_global/reset.css +0 -52
  302. package/src/styles/_mixins/fonts.scss +0 -40
  303. package/src/styles/_mixins/media.scss +0 -150
  304. package/src/styles/_mixins/typography.scss +0 -83
  305. package/src/styles/global.scss +0 -11
  306. package/src/styles/mixins.scss +0 -6
@@ -1,275 +0,0 @@
1
- /* global document */
2
-
3
- import {
4
- type ComponentType,
5
- type FunctionComponent,
6
- type ReactNode,
7
- type RefObject,
8
- Suspense,
9
- lazy,
10
- useInsertionEffect,
11
- } from 'react';
12
-
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 */
40
- }
41
-
42
- const refCounts: Record<string, number> = {};
43
-
44
- function getPublicPath() {
45
- return getBuildInfo().publicPath;
46
- }
47
-
48
- /**
49
- * Client-side only! Ensures the specified CSS stylesheet is loaded into
50
- * the document; loads if it is missing; and does simple reference counting
51
- * to facilitate future clean-up.
52
- * @param name
53
- * @param loadedSheets
54
- * @param refCount
55
- * @return
56
- */
57
- function bookStyleSheet(
58
- name: string,
59
- loadedSheets: Set<string>,
60
- refCount: boolean,
61
- ): Promise<void> | undefined {
62
- let res: Barrier<void> | undefined;
63
- const path = `${getPublicPath()}/${name}`;
64
- const fullPath = `${document.location.origin}${path}`;
65
-
66
- if (!loadedSheets.has(fullPath)) {
67
- let link = document.querySelector(`link[href="${path}"]`);
68
-
69
- if (!link) {
70
- link = document.createElement('link');
71
- link.setAttribute('rel', 'stylesheet');
72
- link.setAttribute('href', path);
73
- document.head.appendChild(link);
74
- }
75
-
76
- res = new Barrier<void>();
77
- link.addEventListener('load', () => {
78
- if (!res) throw Error('Internal error');
79
- void res.resolve();
80
- });
81
- link.addEventListener('error', () => {
82
- if (!res) throw Error('Internal error');
83
- void res.resolve();
84
- });
85
- }
86
-
87
- if (refCount) {
88
- const current = refCounts[path] ?? 0;
89
- refCounts[path] = 1 + current;
90
- }
91
-
92
- return res;
93
- }
94
-
95
- /**
96
- * Generates the set of URLs for currently loaded, linked stylesheets.
97
- * @return
98
- */
99
- function getLoadedStyleSheets(): Set<string> {
100
- const res = new Set<string>();
101
- const { styleSheets } = document;
102
- for (const { href } of styleSheets) {
103
- if (href) res.add(href);
104
- }
105
- return res;
106
- }
107
-
108
- function assertChunkName(
109
- chunkName: string,
110
- chunkGroups: ChunkGroupsT,
111
- ) {
112
- if (chunkGroups[chunkName]) return;
113
- throw Error(`Unknown chunk name "${chunkName}"`);
114
- }
115
-
116
- /**
117
- * Client-side only! Ensures all CSS stylesheets required for the specified
118
- * code chunk are loaded into the document; loads the missing ones; and does
119
- * simple reference counting to facilitate future clean-up.
120
- * @param chunkName Chunk name.
121
- * @param refCount
122
- * @return Resolves once all pending stylesheets, necessary for
123
- * the chunk, are either loaded, or failed to load.
124
- */
125
- export async function bookStyleSheets(
126
- chunkName: string,
127
- chunkGroups: ChunkGroupsT,
128
- refCount: boolean,
129
- ): Promise<void> {
130
- const promises = [];
131
- const assets = chunkGroups[chunkName];
132
- if (!assets) return Promise.resolve();
133
-
134
- const loadedSheets = getLoadedStyleSheets();
135
-
136
- for (const asset of assets) {
137
- if (asset.endsWith('.css')) {
138
- const promise = bookStyleSheet(asset, loadedSheets, refCount);
139
- if (promise) promises.push(promise);
140
- }
141
- }
142
-
143
- return promises.length
144
- ? Promise.allSettled(promises).then()
145
- : Promise.resolve();
146
- }
147
-
148
- /**
149
- * Client-side only! Frees from the document all CSS stylesheets that are
150
- * required by the specified chunk, and have reference counter equal to one
151
- * (for chunks with larger reference counter values, it just decrements
152
- * the reference counter).
153
- * @param {string} chunkName
154
- */
155
- export function freeStyleSheets(
156
- chunkName: string,
157
- chunkGroups: ChunkGroupsT,
158
- ): void {
159
- const assets = chunkGroups[chunkName];
160
- if (!assets) return;
161
-
162
- for (const asset of assets) {
163
- if (asset.endsWith('.css')) {
164
- const path = `${getPublicPath()}/${asset}`;
165
-
166
- const pathRefCount = refCounts[path];
167
- if (pathRefCount) {
168
- if (pathRefCount <= 1) {
169
- document.head.querySelector(`link[href="${path}"]`)!.remove();
170
- delete refCounts[path];
171
- } else refCounts[path] = pathRefCount - 1;
172
- }
173
- }
174
- }
175
- }
176
-
177
- // Holds the set of chunk names already used for splitComponent() calls.
178
- const usedChunkNames = new Set();
179
-
180
- type ComponentOrModule<PropsT> = ComponentType<PropsT> | {
181
- default: ComponentType<PropsT>;
182
- };
183
-
184
- /**
185
- * Given an async component retrieval function `getComponent()` it creates
186
- * a special "code split" component, which uses <Suspense> to asynchronously
187
- * load on demand the code required by `getComponent()`.
188
- * @param options
189
- * @param options.chunkName
190
- * @param {function} options.getComponent
191
- * @param {React.Element} [options.placeholder]
192
- * @return {React.ElementType}
193
- */
194
- export default function splitComponent<
195
- ComponentPropsT extends { children?: ReactNode; ref?: RefObject<unknown> },
196
- >({
197
- chunkName,
198
- 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
-
208
- // The correct usage of splitComponent() assumes a single call per chunk.
209
- if (usedChunkNames.has(chunkName)) {
210
- throw Error(`Repeated splitComponent() call for the chunk "${chunkName}"`);
211
- } else usedChunkNames.add(chunkName);
212
-
213
- const LazyComponent = lazy(async () => {
214
- const resolved = await getComponent();
215
- const Component = 'default' in resolved ? resolved.default : resolved;
216
-
217
- // This pre-loads necessary stylesheets prior to the first mount of
218
- // the component (the lazy load function is executed by React one at
219
- // the frist mount).
220
- if (IS_CLIENT_SIDE) {
221
- await bookStyleSheets(chunkName, clientChunkGroups, false);
222
- }
223
-
224
- const Wrapper: FunctionComponent<ComponentPropsT> = ({
225
- children,
226
- ref,
227
- ...rest
228
- }) => {
229
- // On the server side we'll assert the chunk name here,
230
- // and also push it to the SSR chunks array.
231
- if (IS_SERVER_SIDE) {
232
- const { chunkGroups, chunks } = getSsrContext()!;
233
- assertChunkName(chunkName, chunkGroups);
234
- if (!chunks.includes(chunkName)) chunks.push(chunkName);
235
- }
236
-
237
- // This takes care about stylesheets management every time an instance of
238
- // this component is mounted / unmounted.
239
- useInsertionEffect(() => {
240
- void bookStyleSheets(chunkName, clientChunkGroups, true);
241
- return () => {
242
- freeStyleSheets(chunkName, clientChunkGroups);
243
- };
244
- }, []);
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
- );
255
- };
256
-
257
- return { default: Wrapper };
258
- });
259
-
260
- const CodeSplit: React.FunctionComponent<ComponentPropsT> = ({
261
- children,
262
- ...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
-
274
- return CodeSplit;
275
- }
@@ -1,101 +0,0 @@
1
- import { serialize } from 'cookie';
2
- import { useEffect } from 'react';
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';
17
-
18
- /**
19
- * This react hook wraps Date.now() function in a SSR friendly way,
20
- * ensuring that all calls to useCurrent() within the same render return
21
- * exactly the same time (which is retrieved from Date.now() first, and
22
- * then stored in the global state to be reused in all other calls), which
23
- * is also passed and used in the first client side render, and then updated
24
- * with a finite precision to avoid infinite re-rendering loops.
25
- */
26
- // TODO: Should we request the state type as generic parameter, to be able
27
- // to verify the give globalStatePath is correct?
28
- export function useCurrent({
29
- autorefresh = false,
30
- globalStatePath = 'currentTime',
31
- precision = 5 * SEC_MS,
32
- } = {}): number {
33
- const [now, setter] = useGlobalState<ForceT, number>(
34
- globalStatePath,
35
- Date.now,
36
- );
37
- useEffect(() => {
38
- let timerId: NodeJS.Timeout | undefined;
39
- const update = (): void => {
40
- setter((old) => {
41
- const neu = Date.now();
42
- return Math.abs(neu - old) > precision ? neu : old;
43
- });
44
- if (autorefresh) timerId = setTimeout(update, precision);
45
- };
46
- update();
47
- return (): void => {
48
- if (timerId) clearTimeout(timerId);
49
- };
50
- }, [autorefresh, precision, setter]);
51
- return now;
52
- }
53
-
54
- /**
55
- * Wraps the standard Date.getTimezoneOffset() method in a SSR-friendly way.
56
- * This hook retrieves the offset value at the client side and uses a cookie
57
- * to pass it to the server in subsequent requests from that user. At the server
58
- * side the value from cookie is used in renders and passed back to the client
59
- * via the global state. Prior to the value being known (in the very first
60
- * request from the user, when the cookie is still missing), zero value is used
61
- * as the default value.
62
- */
63
- // TODO: Should we request the state type as generic parameter, to be able
64
- // to verify the give globalStatePath is correct?
65
- export function useTimezoneOffset({
66
- cookieName = 'timezoneOffset',
67
- globalStatePath = 'timezoneOffset',
68
- } = {}): number {
69
- 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
- );
78
- useEffect(() => {
79
- const date = new Date();
80
- const value = date.getTimezoneOffset();
81
- setOffset(value);
82
- if (cookieName) {
83
- document.cookie = serialize(cookieName, value.toString(), { path: '/' });
84
- }
85
- }, [cookieName, setOffset]);
86
- return offset;
87
- }
88
-
89
- const time = {
90
- DAY_MS,
91
- HOUR_MS,
92
- MIN_MS,
93
- SEC_MS,
94
- YEAR_MS,
95
- now: Date.now,
96
- timer,
97
- useCurrent,
98
- useTimezoneOffset,
99
- };
100
-
101
- export default Object.assign(dayjs, time);
@@ -1,74 +0,0 @@
1
- import type PathNS from 'node:path';
2
-
3
- import { IS_CLIENT_SIDE } from './isomorphy';
4
-
5
- type RequireWeakOptionsT = {
6
- basePath?: string;
7
- };
8
-
9
- type RequireWeakResT<T> = T extends { default: infer D }
10
- ? (D extends null | undefined ? T : D & Omit<T, 'default'>)
11
- : T;
12
-
13
- /**
14
- * Requires the specified module without including it into the bundle during
15
- * Webpack build.
16
- * @param modulePath
17
- * @param [basePath]
18
- * @return Required module.
19
- */
20
- export function requireWeak<T extends object>(
21
- modulePath: string,
22
-
23
- // TODO: For now `basePath` can be provided directly as a string here,
24
- // for backward compatibility. Deprecate it in future, if any other
25
- // breaking changes are done for requireWeak().
26
- basePathOrOptions?: string | RequireWeakOptionsT,
27
- ): RequireWeakResT<T> | null {
28
- if (IS_CLIENT_SIDE) return null;
29
-
30
- let basePath: string | undefined;
31
- let ops: RequireWeakOptionsT;
32
- if (typeof basePathOrOptions === 'string') {
33
- basePath = basePathOrOptions;
34
- } else {
35
- ops = basePathOrOptions ?? {};
36
- ({ basePath } = ops);
37
- }
38
-
39
- // eslint-disable-next-line no-eval
40
- const req = eval('require') as (path: string) => unknown;
41
-
42
- // eslint-disable-next-line @typescript-eslint/unbound-method
43
- const { resolve } = req('path') as typeof PathNS;
44
-
45
- const path = basePath ? resolve(basePath, modulePath) : modulePath;
46
- const module = req(path) as T;
47
-
48
- if (!('default' in module) || !module.default) return module as RequireWeakResT<T>;
49
-
50
- const { default: def, ...named } = module;
51
-
52
- const res = def as RequireWeakResT<T>;
53
-
54
- Object.entries(named).forEach(([name, value]) => {
55
- const assigned = res[name as keyof RequireWeakResT<T>];
56
- if (assigned) (res[name as keyof RequireWeakResT<T>] as unknown) = value;
57
- else if (assigned !== value) {
58
- throw Error('Conflict between default and named exports');
59
- }
60
- });
61
- return res;
62
- }
63
-
64
- /**
65
- * Resolves specified module path with help of Babel's module resolver.
66
- * Yes, the function itself just returns its argument to the caller, but Babel
67
- * is configured to resolve the first argument of resolveWeak(..) function, thus
68
- * the result will be the resolved path.
69
- * @param {string} modulePath
70
- * @return {string} Absolute or relative path to the module.
71
- */
72
- export function resolveWeak(modulePath: string): string {
73
- return modulePath;
74
- }
@@ -1,52 +0,0 @@
1
- /* Eric Meyer's "Reset CSS" 2.0 */
2
-
3
- /* http://meyerweb.com/eric/tools/css/reset/
4
- v2.0 | 20110126
5
- License: none (public domain)
6
- */
7
-
8
- /* Having all selectors at individual lines is unreadable in the case of this
9
- * style reset sheet. */
10
- /* stylelint-disable selector-list-comma-newline-after */
11
- a, abbr, acronym, address, applet, article, aside, audio, b, big, blockquote,
12
- body, canvas, caption, center, cite, code, dd, del, details, dfn, div, dl, dt,
13
- em, embed, fieldset, figcaption, figure, footer, form, h1, h2, h3, h4, h5, h6,
14
- header, hgroup, html, i, iframe, img, ins, kbd, label, legend, li, mark, menu,
15
- nav, object, ol, output, p, pre, q, ruby, s, samp, section, small, span,
16
- strike, strong,sub, summary, sup, table, tbody, td, tfoot, th, thead, time, tr,
17
- tt, u, ul, var, video {
18
- margin: 0;
19
- padding: 0;
20
- border: 0;
21
- font: inherit;
22
- font-size: 100%;
23
- vertical-align: baseline;
24
- }
25
-
26
- /* HTML5 display-role reset for older browsers */
27
- article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav,
28
- section {
29
- display: block;
30
- }
31
-
32
- body {
33
- line-height: 1;
34
- }
35
-
36
- ol, ul {
37
- list-style: none;
38
- }
39
-
40
- blockquote, q {
41
- quotes: none;
42
- }
43
-
44
- blockquote::before, blockquote::after, q::before, q::after {
45
- content: "";
46
- content: none;
47
- }
48
-
49
- table {
50
- border-collapse: collapse;
51
- border-spacing: 0;
52
- }
@@ -1,40 +0,0 @@
1
- /* Auxiliary mixins for fonts inclusion. */
2
-
3
- /**
4
- * Includes a font, provided as a set of alternative files in EOT, WOFF, TTF,
5
- * SVG formats into the app.
6
- * $font-name {String}
7
- * $font-weight {Number}
8
- * $font-style {String}
9
- * $font-url {String} Path to the font file, without the filename itself.
10
- * $font-file {String} Font filename, without extension (should be the same for
11
- * each version of the font in different formats.
12
- */
13
- @mixin font-family($font-name, $font-weight, $font-style, $font-url, $font-file) {
14
- @font-face {
15
- font-family: "#{$font-name}";
16
- font-display: block;
17
- font-weight: $font-weight;
18
- font-style: $font-style;
19
- src: url("#{$font-url}#{$font-file}.eot");
20
- src: url("#{$font-url}#{$font-file}.eot?#iefix") format("embedded-opentype"), url("#{$font-url}#{$font-file}.woff") format("woff"), url("#{$font-url}#{$font-file}.ttf") format("truetype");
21
- }
22
- }
23
-
24
- /**
25
- * Includes a font, provided in the TTF format only.
26
- * $font-name {String}
27
- * $font-weight {Number}
28
- * $font-style {String}
29
- * $font-url {String}
30
- */
31
- @mixin font-family-ttf(
32
- $font-name, $font-weight, $font-style, $font-url) {
33
- @font-face {
34
- font-family: $font-name;
35
- font-display: block;
36
- font-style: $font-style;
37
- font-weight: $font-weight;
38
- src: url("#{$font-url}.ttf") format("truetype");
39
- }
40
- }
@@ -1,150 +0,0 @@
1
- /**
2
- * Mixins for different layout sizes: xs, sm, md, lg.
3
- * Breaking points are defined in _variables.scss
4
- * The range mixins A-to-B all means "for the sizes from A to B, both
5
- * inclusive", in particular it means that mixin A-to-lg is equivalent to
6
- * all sizes from A (inclusive) and larger.
7
- *
8
- * NOTE: For convenience, these mixins are sorted not alphabetically, but,
9
- * first, by increase of the first size; second, by increase of the second size.
10
- */
11
-
12
- /* Break points. */
13
-
14
- $screen-xs: 320px !default;
15
- $screen-sm: 495px !default;
16
- $screen-mm: 768px !default;
17
- $screen-md: 1024px !default;
18
- $screen-lg: 1280px !default;
19
-
20
- /* XS */
21
-
22
- @mixin xs {
23
- @media (max-width: #{$screen-xs}) {
24
- @content;
25
- }
26
- }
27
-
28
- @mixin xs-to-sm {
29
- @media (max-width: #{$screen-sm}) {
30
- @content;
31
- }
32
- }
33
-
34
- @mixin xs-to-mm {
35
- @media (max-width: #{$screen-mm}) {
36
- @content;
37
- }
38
- }
39
-
40
- @mixin xs-to-md {
41
- @media (max-width: #{$screen-md}) {
42
- @content;
43
- }
44
- }
45
-
46
- @mixin xs-to-lg {
47
- @media (max-width: #{$screen-lg}) {
48
- @content;
49
- }
50
- }
51
-
52
- /* SM */
53
-
54
- @mixin sm {
55
- @media (min-width: #{$screen-xs + 1px}) and (max-width: #{$screen-sm}) {
56
- @content;
57
- }
58
- }
59
-
60
- @mixin sm-to-mm {
61
- @media (min-width: #{$screen-xs + 1px}) and (max-width: #{$screen-mm}) {
62
- @content;
63
- }
64
- }
65
-
66
- @mixin sm-to-md {
67
- @media (min-width: #{$screen-xs + 1px}) and (max-width: #{$screen-md}) {
68
- @content;
69
- }
70
- }
71
-
72
- @mixin sm-to-lg {
73
- @media (min-width: #{$screen-xs + 1px}) and (max-width: #{$screen-lg}) {
74
- @content;
75
- }
76
- }
77
-
78
- @mixin sm-to-xl {
79
- @media (min-width: #{$screen-xs + 1px}) {
80
- @content;
81
- }
82
- }
83
-
84
- /* MM */
85
-
86
- @mixin mm {
87
- @media (min-width: #{$screen-sm + 1px}) and (max-width: #{$screen-mm}) {
88
- @content;
89
- }
90
- }
91
-
92
- @mixin mm-to-md {
93
- @media (min-width: #{$screen-sm + 1px}) and (max-width: #{$screen-md}) {
94
- @content;
95
- }
96
- }
97
-
98
- @mixin mm-to-lg {
99
- @media (min-width: #{$screen-sm + 1px}) and (max-width: #{$screen-lg}) {
100
- @content;
101
- }
102
- }
103
-
104
- @mixin mm-to-xl {
105
- @media (min-width: #{$screen-sm + 1px}) {
106
- @content;
107
- }
108
- }
109
-
110
- /* MD */
111
-
112
- @mixin md {
113
- @media (min-width: #{$screen-mm + 1px}) and (max-width: #{$screen-md}) {
114
- @content;
115
- }
116
- }
117
-
118
- @mixin md-to-lg {
119
- @media (min-width: #{$screen-mm + 1px}) and (max-width: #{$screen-lg}) {
120
- @content;
121
- }
122
- }
123
-
124
- @mixin md-to-xl {
125
- @media (min-width: #{$screen-mm + 1px}) {
126
- @content;
127
- }
128
- }
129
-
130
- /* LG */
131
-
132
- @mixin lg {
133
- @media (min-width: #{$screen-md + 1px}) and (max-width: #{$screen-lg}) {
134
- @content;
135
- }
136
- }
137
-
138
- @mixin lg-to-xl {
139
- @media (min-width: #{$screen-md + 1px}) {
140
- @content;
141
- }
142
- }
143
-
144
- /* XL */
145
-
146
- @mixin xl {
147
- @media (min-width: #{$screen-lg + 1px}) {
148
- @content;
149
- }
150
- }