@redneckz/wildless-cms-uni-blocks 0.14.595 → 0.14.596

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 (335) hide show
  1. package/bundle/EventBus/EventBus.d.ts +17 -4
  2. package/bundle/EventBus/defaultEventBus.d.ts +2 -13
  3. package/bundle/EventBus/useSubject.d.ts +2 -0
  4. package/bundle/EventBus/useSubjectState.d.ts +2 -0
  5. package/bundle/bundle.umd.js +131 -89
  6. package/bundle/bundle.umd.min.js +1 -1
  7. package/bundle/components/CarouselTariffsCard/CardCellsSection.d.ts +9 -0
  8. package/bundle/components/CarouselTariffsCard/carouselTariffsCardEventBus.d.ts +9 -0
  9. package/bundle/hooks/useLocation.d.ts +2 -1
  10. package/bundle/hooks/useReducer.d.ts +4 -0
  11. package/bundle/ui-kit/Foldable/Foldable.d.ts +11 -1
  12. package/bundle/ui-kit/LocationDialog/SelectedLocation.d.ts +5 -0
  13. package/dist/EventBus/EventBus.d.ts +17 -4
  14. package/dist/EventBus/EventBus.js +29 -10
  15. package/dist/EventBus/EventBus.js.map +1 -1
  16. package/dist/EventBus/defaultEventBus.d.ts +2 -13
  17. package/dist/EventBus/defaultEventBus.js.map +1 -1
  18. package/dist/EventBus/useSubject.d.ts +2 -0
  19. package/dist/EventBus/useSubject.js +17 -0
  20. package/dist/EventBus/useSubject.js.map +1 -0
  21. package/dist/EventBus/useSubjectState.d.ts +2 -0
  22. package/dist/EventBus/useSubjectState.js +10 -0
  23. package/dist/EventBus/useSubjectState.js.map +1 -0
  24. package/dist/components/CarouselTariffsCard/CardCellsSection.d.ts +9 -0
  25. package/dist/components/CarouselTariffsCard/CardCellsSection.js +18 -0
  26. package/dist/components/CarouselTariffsCard/CardCellsSection.js.map +1 -0
  27. package/dist/components/CarouselTariffsCard/CarouselTariffsCard.js +11 -25
  28. package/dist/components/CarouselTariffsCard/CarouselTariffsCard.js.map +1 -1
  29. package/dist/components/CarouselTariffsCard/carouselTariffsCardEventBus.d.ts +9 -0
  30. package/dist/components/CarouselTariffsCard/carouselTariffsCardEventBus.js +5 -0
  31. package/dist/components/CarouselTariffsCard/carouselTariffsCardEventBus.js.map +1 -0
  32. package/dist/components/ExchangeRateTile/ExchangeRateTile.js +1 -1
  33. package/dist/components/ExchangeRateTile/ExchangeRateTile.js.map +1 -1
  34. package/dist/components/Header/HeaderSecondaryMenu.js +1 -1
  35. package/dist/components/Header/HeaderSecondaryMenu.js.map +1 -1
  36. package/dist/components/OfficesAtmsMap/AtmsMap.js +1 -1
  37. package/dist/components/OfficesAtmsMap/AtmsMap.js.map +1 -1
  38. package/dist/components/OfficesAtmsMap/OfficesMap.js +1 -1
  39. package/dist/components/OfficesAtmsMap/OfficesMap.js.map +1 -1
  40. package/dist/components/StickyBottomMenu/BurgerMenuDialog.js +1 -1
  41. package/dist/components/StickyBottomMenu/BurgerMenuDialog.js.map +1 -1
  42. package/dist/hooks/useLocation.d.ts +2 -1
  43. package/dist/hooks/useLocation.js +27 -33
  44. package/dist/hooks/useLocation.js.map +1 -1
  45. package/dist/hooks/useReducer.d.ts +4 -0
  46. package/dist/hooks/useReducer.js +12 -0
  47. package/dist/hooks/useReducer.js.map +1 -0
  48. package/dist/hooks/useRegions.js +3 -1
  49. package/dist/hooks/useRegions.js.map +1 -1
  50. package/dist/ui-kit/DialogManager/useDialogManager.js +3 -3
  51. package/dist/ui-kit/DialogManager/useDialogManager.js.map +1 -1
  52. package/dist/ui-kit/DialogManager/useDialogsList.js +1 -1
  53. package/dist/ui-kit/DialogManager/useDialogsList.js.map +1 -1
  54. package/dist/ui-kit/Foldable/Foldable.d.ts +11 -1
  55. package/dist/ui-kit/Foldable/Foldable.js +10 -2
  56. package/dist/ui-kit/Foldable/Foldable.js.map +1 -1
  57. package/dist/ui-kit/FormField/constants.js +1 -0
  58. package/dist/ui-kit/FormField/constants.js.map +1 -1
  59. package/dist/ui-kit/FormField/getValidation.js +1 -0
  60. package/dist/ui-kit/FormField/getValidation.js.map +1 -1
  61. package/dist/ui-kit/LocationDialog/LocationDialog.js +9 -12
  62. package/dist/ui-kit/LocationDialog/LocationDialog.js.map +1 -1
  63. package/dist/ui-kit/LocationDialog/SelectedLocation.d.ts +5 -0
  64. package/dist/ui-kit/LocationDialog/SelectedLocation.js +15 -0
  65. package/dist/ui-kit/LocationDialog/SelectedLocation.js.map +1 -0
  66. package/dist/ui-kit/PopupManager/PopupManager.js +1 -1
  67. package/dist/ui-kit/PopupManager/PopupManager.js.map +1 -1
  68. package/dist/ui-kit/PopupManager/usePopupManager.js +3 -3
  69. package/dist/ui-kit/PopupManager/usePopupManager.js.map +1 -1
  70. package/lib/EventBus/EventBus.d.ts +17 -4
  71. package/lib/EventBus/EventBus.js +29 -10
  72. package/lib/EventBus/EventBus.js.map +1 -1
  73. package/lib/EventBus/defaultEventBus.d.ts +2 -13
  74. package/lib/EventBus/defaultEventBus.js.map +1 -1
  75. package/lib/EventBus/useSubject.d.ts +2 -0
  76. package/lib/EventBus/useSubject.js +14 -0
  77. package/lib/EventBus/useSubject.js.map +1 -0
  78. package/lib/EventBus/useSubjectState.d.ts +2 -0
  79. package/lib/EventBus/useSubjectState.js +7 -0
  80. package/lib/EventBus/useSubjectState.js.map +1 -0
  81. package/lib/common.css +1 -1
  82. package/lib/components/CarouselTariffsCard/CardCellsSection.d.ts +9 -0
  83. package/lib/components/CarouselTariffsCard/CardCellsSection.js +16 -0
  84. package/lib/components/CarouselTariffsCard/CardCellsSection.js.map +1 -0
  85. package/lib/components/CarouselTariffsCard/CarouselTariffsCard.js +12 -26
  86. package/lib/components/CarouselTariffsCard/CarouselTariffsCard.js.map +1 -1
  87. package/lib/components/CarouselTariffsCard/carouselTariffsCardEventBus.d.ts +9 -0
  88. package/lib/components/CarouselTariffsCard/carouselTariffsCardEventBus.js +3 -0
  89. package/lib/components/CarouselTariffsCard/carouselTariffsCardEventBus.js.map +1 -0
  90. package/lib/components/ExchangeRateTile/ExchangeRateTile.js +2 -2
  91. package/lib/components/ExchangeRateTile/ExchangeRateTile.js.map +1 -1
  92. package/lib/components/Header/HeaderSecondaryMenu.js +2 -2
  93. package/lib/components/Header/HeaderSecondaryMenu.js.map +1 -1
  94. package/lib/components/OfficesAtmsMap/AtmsMap.js +2 -2
  95. package/lib/components/OfficesAtmsMap/AtmsMap.js.map +1 -1
  96. package/lib/components/OfficesAtmsMap/OfficesMap.js +2 -2
  97. package/lib/components/OfficesAtmsMap/OfficesMap.js.map +1 -1
  98. package/lib/components/StickyBottomMenu/BurgerMenuDialog.js +2 -2
  99. package/lib/components/StickyBottomMenu/BurgerMenuDialog.js.map +1 -1
  100. package/lib/hooks/useLocation.d.ts +2 -1
  101. package/lib/hooks/useLocation.js +26 -33
  102. package/lib/hooks/useLocation.js.map +1 -1
  103. package/lib/hooks/useReducer.d.ts +4 -0
  104. package/lib/hooks/useReducer.js +9 -0
  105. package/lib/hooks/useReducer.js.map +1 -0
  106. package/lib/hooks/useRegions.js +3 -1
  107. package/lib/hooks/useRegions.js.map +1 -1
  108. package/lib/ui-kit/DialogManager/useDialogManager.js +3 -3
  109. package/lib/ui-kit/DialogManager/useDialogManager.js.map +1 -1
  110. package/lib/ui-kit/DialogManager/useDialogsList.js +1 -1
  111. package/lib/ui-kit/DialogManager/useDialogsList.js.map +1 -1
  112. package/lib/ui-kit/Foldable/Foldable.d.ts +11 -1
  113. package/lib/ui-kit/Foldable/Foldable.js +10 -2
  114. package/lib/ui-kit/Foldable/Foldable.js.map +1 -1
  115. package/lib/ui-kit/FormField/constants.js +1 -0
  116. package/lib/ui-kit/FormField/constants.js.map +1 -1
  117. package/lib/ui-kit/FormField/getValidation.js +1 -0
  118. package/lib/ui-kit/FormField/getValidation.js.map +1 -1
  119. package/lib/ui-kit/LocationDialog/LocationDialog.js +10 -13
  120. package/lib/ui-kit/LocationDialog/LocationDialog.js.map +1 -1
  121. package/lib/ui-kit/LocationDialog/SelectedLocation.d.ts +5 -0
  122. package/lib/ui-kit/LocationDialog/SelectedLocation.js +13 -0
  123. package/lib/ui-kit/LocationDialog/SelectedLocation.js.map +1 -0
  124. package/lib/ui-kit/PopupManager/PopupManager.js +1 -1
  125. package/lib/ui-kit/PopupManager/PopupManager.js.map +1 -1
  126. package/lib/ui-kit/PopupManager/usePopupManager.js +3 -3
  127. package/lib/ui-kit/PopupManager/usePopupManager.js.map +1 -1
  128. package/mobile/bundle/EventBus/EventBus.d.ts +17 -4
  129. package/mobile/bundle/EventBus/defaultEventBus.d.ts +2 -13
  130. package/mobile/bundle/EventBus/useSubject.d.ts +2 -0
  131. package/mobile/bundle/EventBus/useSubjectState.d.ts +2 -0
  132. package/mobile/bundle/bundle.umd.js +131 -89
  133. package/mobile/bundle/bundle.umd.min.js +1 -1
  134. package/mobile/bundle/components/CarouselTariffsCard/CardCellsSection.d.ts +9 -0
  135. package/mobile/bundle/components/CarouselTariffsCard/carouselTariffsCardEventBus.d.ts +9 -0
  136. package/mobile/bundle/hooks/useLocation.d.ts +2 -1
  137. package/mobile/bundle/hooks/useReducer.d.ts +4 -0
  138. package/mobile/bundle/ui-kit/Foldable/Foldable.d.ts +11 -1
  139. package/mobile/bundle/ui-kit/LocationDialog/SelectedLocation.d.ts +5 -0
  140. package/mobile/dist/EventBus/EventBus.d.ts +17 -4
  141. package/mobile/dist/EventBus/EventBus.js +29 -10
  142. package/mobile/dist/EventBus/EventBus.js.map +1 -1
  143. package/mobile/dist/EventBus/defaultEventBus.d.ts +2 -13
  144. package/mobile/dist/EventBus/defaultEventBus.js.map +1 -1
  145. package/mobile/dist/EventBus/useSubject.d.ts +2 -0
  146. package/mobile/dist/EventBus/useSubject.js +17 -0
  147. package/mobile/dist/EventBus/useSubject.js.map +1 -0
  148. package/mobile/dist/EventBus/useSubjectState.d.ts +2 -0
  149. package/mobile/dist/EventBus/useSubjectState.js +10 -0
  150. package/mobile/dist/EventBus/useSubjectState.js.map +1 -0
  151. package/mobile/dist/components/CarouselTariffsCard/CardCellsSection.d.ts +9 -0
  152. package/mobile/dist/components/CarouselTariffsCard/CardCellsSection.js +18 -0
  153. package/mobile/dist/components/CarouselTariffsCard/CardCellsSection.js.map +1 -0
  154. package/mobile/dist/components/CarouselTariffsCard/CarouselTariffsCard.js +11 -25
  155. package/mobile/dist/components/CarouselTariffsCard/CarouselTariffsCard.js.map +1 -1
  156. package/mobile/dist/components/CarouselTariffsCard/carouselTariffsCardEventBus.d.ts +9 -0
  157. package/mobile/dist/components/CarouselTariffsCard/carouselTariffsCardEventBus.js +5 -0
  158. package/mobile/dist/components/CarouselTariffsCard/carouselTariffsCardEventBus.js.map +1 -0
  159. package/mobile/dist/components/ExchangeRateTile/ExchangeRateTile.js +1 -1
  160. package/mobile/dist/components/ExchangeRateTile/ExchangeRateTile.js.map +1 -1
  161. package/mobile/dist/components/Header/HeaderSecondaryMenu.js +1 -1
  162. package/mobile/dist/components/Header/HeaderSecondaryMenu.js.map +1 -1
  163. package/mobile/dist/components/OfficesAtmsMap/AtmsMap.js +1 -1
  164. package/mobile/dist/components/OfficesAtmsMap/AtmsMap.js.map +1 -1
  165. package/mobile/dist/components/OfficesAtmsMap/OfficesMap.js +1 -1
  166. package/mobile/dist/components/OfficesAtmsMap/OfficesMap.js.map +1 -1
  167. package/mobile/dist/components/StickyBottomMenu/BurgerMenuDialog.js +1 -1
  168. package/mobile/dist/components/StickyBottomMenu/BurgerMenuDialog.js.map +1 -1
  169. package/mobile/dist/hooks/useLocation.d.ts +2 -1
  170. package/mobile/dist/hooks/useLocation.js +27 -33
  171. package/mobile/dist/hooks/useLocation.js.map +1 -1
  172. package/mobile/dist/hooks/useReducer.d.ts +4 -0
  173. package/mobile/dist/hooks/useReducer.js +12 -0
  174. package/mobile/dist/hooks/useReducer.js.map +1 -0
  175. package/mobile/dist/hooks/useRegions.js +3 -1
  176. package/mobile/dist/hooks/useRegions.js.map +1 -1
  177. package/mobile/dist/ui-kit/DialogManager/useDialogManager.js +3 -3
  178. package/mobile/dist/ui-kit/DialogManager/useDialogManager.js.map +1 -1
  179. package/mobile/dist/ui-kit/DialogManager/useDialogsList.js +1 -1
  180. package/mobile/dist/ui-kit/DialogManager/useDialogsList.js.map +1 -1
  181. package/mobile/dist/ui-kit/Foldable/Foldable.d.ts +11 -1
  182. package/mobile/dist/ui-kit/Foldable/Foldable.js +10 -2
  183. package/mobile/dist/ui-kit/Foldable/Foldable.js.map +1 -1
  184. package/mobile/dist/ui-kit/FormField/constants.js +1 -0
  185. package/mobile/dist/ui-kit/FormField/constants.js.map +1 -1
  186. package/mobile/dist/ui-kit/FormField/getValidation.js +1 -0
  187. package/mobile/dist/ui-kit/FormField/getValidation.js.map +1 -1
  188. package/mobile/dist/ui-kit/LocationDialog/LocationDialog.js +9 -12
  189. package/mobile/dist/ui-kit/LocationDialog/LocationDialog.js.map +1 -1
  190. package/mobile/dist/ui-kit/LocationDialog/SelectedLocation.d.ts +5 -0
  191. package/mobile/dist/ui-kit/LocationDialog/SelectedLocation.js +15 -0
  192. package/mobile/dist/ui-kit/LocationDialog/SelectedLocation.js.map +1 -0
  193. package/mobile/dist/ui-kit/PopupManager/PopupManager.js +1 -1
  194. package/mobile/dist/ui-kit/PopupManager/PopupManager.js.map +1 -1
  195. package/mobile/dist/ui-kit/PopupManager/usePopupManager.js +3 -3
  196. package/mobile/dist/ui-kit/PopupManager/usePopupManager.js.map +1 -1
  197. package/mobile/lib/EventBus/EventBus.d.ts +17 -4
  198. package/mobile/lib/EventBus/EventBus.js +29 -10
  199. package/mobile/lib/EventBus/EventBus.js.map +1 -1
  200. package/mobile/lib/EventBus/defaultEventBus.d.ts +2 -13
  201. package/mobile/lib/EventBus/defaultEventBus.js.map +1 -1
  202. package/mobile/lib/EventBus/useSubject.d.ts +2 -0
  203. package/mobile/lib/EventBus/useSubject.js +14 -0
  204. package/mobile/lib/EventBus/useSubject.js.map +1 -0
  205. package/mobile/lib/EventBus/useSubjectState.d.ts +2 -0
  206. package/mobile/lib/EventBus/useSubjectState.js +7 -0
  207. package/mobile/lib/EventBus/useSubjectState.js.map +1 -0
  208. package/mobile/lib/common.css +1 -1
  209. package/mobile/lib/components/CarouselTariffsCard/CardCellsSection.d.ts +9 -0
  210. package/mobile/lib/components/CarouselTariffsCard/CardCellsSection.js +16 -0
  211. package/mobile/lib/components/CarouselTariffsCard/CardCellsSection.js.map +1 -0
  212. package/mobile/lib/components/CarouselTariffsCard/CarouselTariffsCard.js +12 -26
  213. package/mobile/lib/components/CarouselTariffsCard/CarouselTariffsCard.js.map +1 -1
  214. package/mobile/lib/components/CarouselTariffsCard/carouselTariffsCardEventBus.d.ts +9 -0
  215. package/mobile/lib/components/CarouselTariffsCard/carouselTariffsCardEventBus.js +3 -0
  216. package/mobile/lib/components/CarouselTariffsCard/carouselTariffsCardEventBus.js.map +1 -0
  217. package/mobile/lib/components/ExchangeRateTile/ExchangeRateTile.js +2 -2
  218. package/mobile/lib/components/ExchangeRateTile/ExchangeRateTile.js.map +1 -1
  219. package/mobile/lib/components/Header/HeaderSecondaryMenu.js +2 -2
  220. package/mobile/lib/components/Header/HeaderSecondaryMenu.js.map +1 -1
  221. package/mobile/lib/components/OfficesAtmsMap/AtmsMap.js +2 -2
  222. package/mobile/lib/components/OfficesAtmsMap/AtmsMap.js.map +1 -1
  223. package/mobile/lib/components/OfficesAtmsMap/OfficesMap.js +2 -2
  224. package/mobile/lib/components/OfficesAtmsMap/OfficesMap.js.map +1 -1
  225. package/mobile/lib/components/StickyBottomMenu/BurgerMenuDialog.js +2 -2
  226. package/mobile/lib/components/StickyBottomMenu/BurgerMenuDialog.js.map +1 -1
  227. package/mobile/lib/hooks/useLocation.d.ts +2 -1
  228. package/mobile/lib/hooks/useLocation.js +26 -33
  229. package/mobile/lib/hooks/useLocation.js.map +1 -1
  230. package/mobile/lib/hooks/useReducer.d.ts +4 -0
  231. package/mobile/lib/hooks/useReducer.js +9 -0
  232. package/mobile/lib/hooks/useReducer.js.map +1 -0
  233. package/mobile/lib/hooks/useRegions.js +3 -1
  234. package/mobile/lib/hooks/useRegions.js.map +1 -1
  235. package/mobile/lib/ui-kit/DialogManager/useDialogManager.js +3 -3
  236. package/mobile/lib/ui-kit/DialogManager/useDialogManager.js.map +1 -1
  237. package/mobile/lib/ui-kit/DialogManager/useDialogsList.js +1 -1
  238. package/mobile/lib/ui-kit/DialogManager/useDialogsList.js.map +1 -1
  239. package/mobile/lib/ui-kit/Foldable/Foldable.d.ts +11 -1
  240. package/mobile/lib/ui-kit/Foldable/Foldable.js +10 -2
  241. package/mobile/lib/ui-kit/Foldable/Foldable.js.map +1 -1
  242. package/mobile/lib/ui-kit/FormField/constants.js +1 -0
  243. package/mobile/lib/ui-kit/FormField/constants.js.map +1 -1
  244. package/mobile/lib/ui-kit/FormField/getValidation.js +1 -0
  245. package/mobile/lib/ui-kit/FormField/getValidation.js.map +1 -1
  246. package/mobile/lib/ui-kit/LocationDialog/LocationDialog.js +10 -13
  247. package/mobile/lib/ui-kit/LocationDialog/LocationDialog.js.map +1 -1
  248. package/mobile/lib/ui-kit/LocationDialog/SelectedLocation.d.ts +5 -0
  249. package/mobile/lib/ui-kit/LocationDialog/SelectedLocation.js +13 -0
  250. package/mobile/lib/ui-kit/LocationDialog/SelectedLocation.js.map +1 -0
  251. package/mobile/lib/ui-kit/PopupManager/PopupManager.js +1 -1
  252. package/mobile/lib/ui-kit/PopupManager/PopupManager.js.map +1 -1
  253. package/mobile/lib/ui-kit/PopupManager/usePopupManager.js +3 -3
  254. package/mobile/lib/ui-kit/PopupManager/usePopupManager.js.map +1 -1
  255. package/mobile/src/EventBus/EventBus.ts +51 -15
  256. package/mobile/src/EventBus/defaultEventBus.ts +2 -14
  257. package/mobile/src/EventBus/useSubject.ts +19 -0
  258. package/mobile/src/EventBus/useSubjectState.ts +13 -0
  259. package/mobile/src/components/CarouselTariffsCard/CardCellsSection.tsx +54 -0
  260. package/mobile/src/components/CarouselTariffsCard/CarouselTariffsCard.tsx +23 -66
  261. package/mobile/src/components/CarouselTariffsCard/carouselTariffsCardEventBus.ts +11 -0
  262. package/mobile/src/components/ExchangeRateTile/ExchangeRateTile.tsx +2 -2
  263. package/mobile/src/components/Header/HeaderSecondaryMenu.tsx +2 -2
  264. package/mobile/src/components/OfficesAtmsMap/AtmsMap.tsx +2 -3
  265. package/mobile/src/components/OfficesAtmsMap/OfficesMap.tsx +2 -2
  266. package/mobile/src/components/StickyBottomMenu/BurgerMenuDialog.tsx +2 -2
  267. package/mobile/src/hooks/useLocation.ts +30 -44
  268. package/mobile/src/hooks/useReducer.ts +21 -0
  269. package/mobile/src/hooks/useRegions.ts +4 -1
  270. package/mobile/src/ui-kit/DialogManager/useDialogManager.ts +3 -3
  271. package/mobile/src/ui-kit/DialogManager/useDialogsList.ts +1 -1
  272. package/mobile/src/ui-kit/Foldable/Foldable.tsx +21 -5
  273. package/mobile/src/ui-kit/FormField/constants.tsx +1 -0
  274. package/mobile/src/ui-kit/FormField/getValidation.tsx +1 -0
  275. package/mobile/src/ui-kit/LocationDialog/LocationDialog.tsx +13 -25
  276. package/mobile/src/ui-kit/LocationDialog/SelectedLocation.tsx +27 -0
  277. package/mobile/src/ui-kit/PopupManager/PopupManager.tsx +1 -1
  278. package/mobile/src/ui-kit/PopupManager/usePopupManager.tsx +3 -3
  279. package/package.json +1 -1
  280. package/src/EventBus/EventBus.ts +51 -15
  281. package/src/EventBus/defaultEventBus.ts +2 -14
  282. package/src/EventBus/useSubject.ts +19 -0
  283. package/src/EventBus/useSubjectState.ts +13 -0
  284. package/src/components/CarouselTariffsCard/CardCellsSection.tsx +54 -0
  285. package/src/components/CarouselTariffsCard/CarouselTariffsCard.tsx +23 -66
  286. package/src/components/CarouselTariffsCard/carouselTariffsCardEventBus.ts +11 -0
  287. package/src/components/ExchangeRateTile/ExchangeRateTile.tsx +2 -2
  288. package/src/components/Header/HeaderSecondaryMenu.tsx +2 -2
  289. package/src/components/OfficesAtmsMap/AtmsMap.tsx +2 -3
  290. package/src/components/OfficesAtmsMap/OfficesMap.tsx +2 -2
  291. package/src/components/StickyBottomMenu/BurgerMenuDialog.tsx +2 -2
  292. package/src/hooks/useLocation.ts +30 -44
  293. package/src/hooks/useReducer.ts +21 -0
  294. package/src/hooks/useRegions.ts +4 -1
  295. package/src/ui-kit/DialogManager/useDialogManager.ts +3 -3
  296. package/src/ui-kit/DialogManager/useDialogsList.ts +1 -1
  297. package/src/ui-kit/Foldable/Foldable.tsx +21 -5
  298. package/src/ui-kit/FormField/constants.tsx +1 -0
  299. package/src/ui-kit/FormField/getValidation.tsx +1 -0
  300. package/src/ui-kit/LocationDialog/LocationDialog.tsx +13 -25
  301. package/src/ui-kit/LocationDialog/SelectedLocation.tsx +27 -0
  302. package/src/ui-kit/PopupManager/PopupManager.tsx +1 -1
  303. package/src/ui-kit/PopupManager/usePopupManager.tsx +3 -3
  304. package/bundle/EventBus/useLatestEvent.d.ts +0 -2
  305. package/bundle/components/CarouselTariffsCard/CarouselTariffsCardAction.d.ts +0 -6
  306. package/dist/EventBus/useLatestEvent.d.ts +0 -2
  307. package/dist/EventBus/useLatestEvent.js +0 -11
  308. package/dist/EventBus/useLatestEvent.js.map +0 -1
  309. package/dist/components/CarouselTariffsCard/CarouselTariffsCardAction.d.ts +0 -6
  310. package/dist/components/CarouselTariffsCard/CarouselTariffsCardAction.js +0 -2
  311. package/dist/components/CarouselTariffsCard/CarouselTariffsCardAction.js.map +0 -1
  312. package/lib/EventBus/useLatestEvent.d.ts +0 -2
  313. package/lib/EventBus/useLatestEvent.js +0 -8
  314. package/lib/EventBus/useLatestEvent.js.map +0 -1
  315. package/lib/components/CarouselTariffsCard/CarouselTariffsCardAction.d.ts +0 -6
  316. package/lib/components/CarouselTariffsCard/CarouselTariffsCardAction.js +0 -2
  317. package/lib/components/CarouselTariffsCard/CarouselTariffsCardAction.js.map +0 -1
  318. package/mobile/bundle/EventBus/useLatestEvent.d.ts +0 -2
  319. package/mobile/bundle/components/CarouselTariffsCard/CarouselTariffsCardAction.d.ts +0 -6
  320. package/mobile/dist/EventBus/useLatestEvent.d.ts +0 -2
  321. package/mobile/dist/EventBus/useLatestEvent.js +0 -11
  322. package/mobile/dist/EventBus/useLatestEvent.js.map +0 -1
  323. package/mobile/dist/components/CarouselTariffsCard/CarouselTariffsCardAction.d.ts +0 -6
  324. package/mobile/dist/components/CarouselTariffsCard/CarouselTariffsCardAction.js +0 -2
  325. package/mobile/dist/components/CarouselTariffsCard/CarouselTariffsCardAction.js.map +0 -1
  326. package/mobile/lib/EventBus/useLatestEvent.d.ts +0 -2
  327. package/mobile/lib/EventBus/useLatestEvent.js +0 -8
  328. package/mobile/lib/EventBus/useLatestEvent.js.map +0 -1
  329. package/mobile/lib/components/CarouselTariffsCard/CarouselTariffsCardAction.d.ts +0 -6
  330. package/mobile/lib/components/CarouselTariffsCard/CarouselTariffsCardAction.js +0 -2
  331. package/mobile/lib/components/CarouselTariffsCard/CarouselTariffsCardAction.js.map +0 -1
  332. package/mobile/src/EventBus/useLatestEvent.ts +0 -16
  333. package/mobile/src/components/CarouselTariffsCard/CarouselTariffsCardAction.ts +0 -6
  334. package/src/EventBus/useLatestEvent.ts +0 -16
  335. package/src/components/CarouselTariffsCard/CarouselTariffsCardAction.ts +0 -6
@@ -1,36 +1,72 @@
1
- export class EventBus<EM extends Record<string, any>> {
2
- private subscribers: Partial<Record<keyof EM, Array<(ev: EM[keyof EM]) => void>>> = {};
1
+ export type Subscriber<Event> = (ev: Event) => void;
2
+
3
+ type Cleanup = () => void;
4
+
5
+ export interface EventBusObservable<EM extends Record<string, any>> {
6
+ subscribe<K extends keyof EM>(type: K, listener: Subscriber<EM[K]>): Cleanup;
7
+ }
8
+
9
+ export interface EventBusEmitter<EM extends Record<string, any>> {
10
+ fire<K extends keyof EM>(type: K, event: EM[K]): void;
11
+ subject<K extends keyof EM>(type: K, event: EM[K]): Cleanup;
12
+ }
13
+
14
+ export class EventBus<EM extends Record<string, any>>
15
+ implements EventBusObservable<EM>, EventBusEmitter<EM>
16
+ {
17
+ private subscribersMap: Partial<Record<keyof EM, Subscriber<EM[keyof EM]>[]>> = {};
3
18
  private subjectsStateMap: Partial<EM> = {};
4
19
 
5
- subscribe<K extends keyof EM>(type: K, listener: (event: EM[K]) => void) {
6
- this.subscribers[type] = (this.subscribers[type] || []).concat(
7
- listener as (ev: EM[keyof EM]) => void,
8
- );
20
+ readonly emitter: EventBusEmitter<EM> = this;
21
+ readonly observable: EventBusObservable<EM> = this;
9
22
 
10
- const latestEvent = this.subjectsStateMap[type];
11
- if (latestEvent) {
12
- listener(latestEvent as EM[K]);
13
- }
23
+ subscribe<K extends keyof EM>(type: K, listener: Subscriber<EM[K]>): Cleanup {
24
+ this.subscribersMap[type] ||= [];
25
+ this.subscribersMap[type]?.push(listener as Subscriber<EM[keyof EM]>);
26
+
27
+ this.fireSubscribers([listener], this.subjectsStateMap[type]);
14
28
 
15
29
  return () => {
16
30
  this.unsubscribe(type, listener);
17
31
  };
18
32
  }
19
33
 
20
- private unsubscribe<K extends keyof EM>(type: K, listener: (event: EM[K]) => void) {
21
- this.subscribers[type] = this.subscribers[type]?.filter((s) => s !== listener);
34
+ private unsubscribe<K extends keyof EM>(type: K, listener: Subscriber<EM[K]>) {
35
+ const index = this.subscribersMap[type]?.indexOf(listener as Subscriber<EM[keyof EM]>);
36
+ if (index && index !== -1) {
37
+ this.subscribersMap[type]?.splice(index, 1);
38
+ }
22
39
  }
23
40
 
24
41
  fire<K extends keyof EM>(type: K, event: EM[K]) {
25
42
  const isSubjectDeclared = type in this.subjectsStateMap;
26
43
  if (isSubjectDeclared) {
44
+ this.subject(type, event);
45
+ } else {
46
+ this.fireSubscribers(this.subscribersMap[type], event);
47
+ }
48
+ }
49
+
50
+ subject<K extends keyof EM>(type: K, event: EM[K]): Cleanup {
51
+ if (this.subjectsStateMap[type] !== event) {
27
52
  this.subjectsStateMap[type] = event;
53
+ this.fireSubscribers(this.subscribersMap[type], event);
28
54
  }
29
55
 
30
- this.subscribers[type]?.forEach((s) => s(event));
56
+ return () => {
57
+ delete this.subjectsStateMap[type];
58
+ };
31
59
  }
32
60
 
33
- subject<K extends keyof EM>(type: K, event: EM[K]) {
34
- this.subjectsStateMap[type] = event;
61
+ private fireSubscribers<K extends keyof EM>(
62
+ subscribers: Subscriber<EM[K]>[] | undefined,
63
+ event: EM[K] | undefined,
64
+ ) {
65
+ if (!subscribers || !event) {
66
+ return;
67
+ }
68
+ for (const _ of subscribers) {
69
+ _(event);
70
+ }
35
71
  }
36
72
  }
@@ -1,22 +1,10 @@
1
- import { type CarouselTariffsCardAction } from '../components/CarouselTariffsCard/CarouselTariffsCardAction';
2
- import { type Tab } from '../components/TabsLayout/TabsLayoutContent';
3
1
  import { type Region } from '../hooks/useRegions';
4
2
  import { type DialogAction } from '../ui-kit/DialogManager/DialogAction';
5
3
  import { type PopupAction } from '../ui-kit/PopupManager/PopupAction';
6
4
  import { EventBus } from './EventBus';
7
5
 
8
- interface TabActivationEvent {
9
- type?: Tab['type'];
10
- groupName?: string;
11
- label?: string;
12
- }
13
-
14
- interface GlobalEventMap {
6
+ export const defaultEventBus = new EventBus<{
15
7
  location: Region;
16
8
  dialog: DialogAction;
17
9
  popup: PopupAction;
18
- tab: TabActivationEvent;
19
- fold: CarouselTariffsCardAction;
20
- }
21
-
22
- export const defaultEventBus = new EventBus<GlobalEventMap>();
10
+ }>();
@@ -0,0 +1,19 @@
1
+ import { useCallback, useEffect } from '@redneckz/uni-jsx/lib/hooks';
2
+ import type { EventBusEmitter } from './EventBus';
3
+
4
+ export function useSubject<EM extends Record<string, any>, K extends keyof EM>(
5
+ eventBus: EventBusEmitter<EM>,
6
+ type: K,
7
+ initialState: EM[K] | (() => EM[K] | Promise<EM[K]>),
8
+ ): (_: EM[K]) => void {
9
+ useEffect(() => {
10
+ const state = initialState instanceof Function ? initialState() : initialState;
11
+ if (state instanceof Promise) {
12
+ state.then((_) => eventBus.subject(type, _), console.warn);
13
+ } else {
14
+ eventBus.subject(type, state);
15
+ }
16
+ }, [eventBus, type]);
17
+
18
+ return useCallback((_: EM[K]) => eventBus.fire(type, _), [eventBus, type]);
19
+ }
@@ -0,0 +1,13 @@
1
+ import { useEffect, useState } from '@redneckz/uni-jsx/lib/hooks';
2
+ import { type EventBusObservable } from './EventBus';
3
+
4
+ export const useSubjectState = <EM extends Record<string, any>, K extends keyof EM>(
5
+ eventBus: EventBusObservable<EM>,
6
+ type: K,
7
+ initialState: EM[K],
8
+ ): EM[K] => {
9
+ const [state, setState] = useState(initialState);
10
+ useEffect(() => eventBus.subscribe(type, setState), [eventBus, type]);
11
+
12
+ return state;
13
+ };
@@ -0,0 +1,54 @@
1
+ import { JSX } from '@redneckz/uni-jsx';
2
+ import type { AspectsProps } from '../../model/AspectsProps';
3
+ import { FoldableWrapper } from '../../ui-kit/Foldable/Foldable';
4
+ import { FoldableSection } from '../../ui-kit/Foldable/FoldableSection';
5
+ import { Icon } from '../../ui-kit/Icon/Icon';
6
+ import { getAspectsAttributes } from '../../utils/dataAttributes';
7
+ import type { TariffsCardCellProps } from './CarouselTariffsCardContent';
8
+ import { renderCardInfo } from './renderCardInfo';
9
+
10
+ export interface CardCellsSectionProps extends AspectsProps {
11
+ cardCells?: TariffsCardCellProps[];
12
+ visibleCellsCount?: number;
13
+ isUnfolded?: boolean;
14
+ onToggle?: () => void;
15
+ }
16
+
17
+ export const CardCellsSection = JSX<CardCellsSectionProps>((props) => {
18
+ const { cardCells = [], visibleCellsCount = 1, isUnfolded } = props;
19
+
20
+ const [visibleCells, hiddenCells] =
21
+ visibleCellsCount > 0 && cardCells.length >= visibleCellsCount
22
+ ? [cardCells.slice(0, visibleCellsCount), cardCells.slice(visibleCellsCount)]
23
+ : [cardCells, []];
24
+
25
+ return hiddenCells.length ? (
26
+ <FoldableWrapper>
27
+ <div>
28
+ {visibleCells.map(renderCardInfo)}
29
+ <FoldableSection isUnfolded={isUnfolded}>{hiddenCells.map(renderCardInfo)}</FoldableSection>
30
+ </div>
31
+ <FoldButton {...props} />
32
+ </FoldableWrapper>
33
+ ) : (
34
+ <div>{visibleCells.map(renderCardInfo)}</div>
35
+ );
36
+ });
37
+
38
+ const FoldButton = JSX<CardCellsSectionProps>(({ isUnfolded, data, onToggle }) => (
39
+ <button
40
+ type="button"
41
+ className="w-full cursor-pointer text-primary-main pt-lg flex justify-between items-center"
42
+ // eslint-disable-next-line react/jsx-props-no-spreading
43
+ {...(isUnfolded ? getAspectsAttributes(data) : {})}
44
+ onClick={onToggle}
45
+ >
46
+ <div>{isUnfolded ? 'Скрыть' : 'Подробнее о тарифе'}</div>
47
+ <Icon
48
+ className="text-primary-text"
49
+ name={isUnfolded ? 'ArrowUpIcon' : 'ArrowDownIcon'}
50
+ width="16"
51
+ height="16"
52
+ />
53
+ </button>
54
+ ));
@@ -1,28 +1,22 @@
1
1
  import { JSX } from '@redneckz/uni-jsx';
2
- import { useEffect, useState } from '@redneckz/uni-jsx/lib/hooks';
3
- import { defaultEventBus } from '../../EventBus/defaultEventBus';
4
- import { type AspectsDef } from '../../model/AspectsProps';
5
- import { type Slot } from '../../model/ContentPageDef';
6
- import { type VNode } from '../../model/VNode';
2
+ import { useCallback } from '@redneckz/uni-jsx/lib/hooks';
3
+ import { useSubjectState } from '../../EventBus/useSubjectState';
7
4
  import { BlockWrapper } from '../../ui-kit/BlockWrapper';
8
- import { Foldable } from '../../ui-kit/Foldable/Foldable';
9
- import { FoldableSection } from '../../ui-kit/Foldable/FoldableSection';
10
5
  import { Heading } from '../../ui-kit/Heading/Heading';
11
- import { Icon } from '../../ui-kit/Icon/Icon';
12
6
  import { Img } from '../../ui-kit/Img/Img';
13
7
  import { LinkButton } from '../../ui-kit/LinkButton/LinkButton';
14
8
  import { type UniBlockProps } from '../../UniBlock/UniBlockProps';
15
- import { getAspectsAttributes } from '../../utils/dataAttributes';
16
9
  import { isIcon } from '../../utils/isIcon';
17
10
  import { style } from '../../utils/style';
11
+ import { CardCellsSection } from './CardCellsSection';
18
12
  import { type CarouselTariffsCardContent } from './CarouselTariffsCardContent';
19
- import { renderCardInfo } from './renderCardInfo';
13
+ import { carouselTariffsCardEventBus } from './carouselTariffsCardEventBus';
20
14
 
21
15
  export interface CarouselTariffsCardProps extends CarouselTariffsCardContent, UniBlockProps {}
22
16
 
23
17
  export const CarouselTariffsCard = JSX<CarouselTariffsCardProps>(
24
18
  ({
25
- className = '',
19
+ className,
26
20
  title,
27
21
  align = 'text-center',
28
22
  icon,
@@ -33,22 +27,20 @@ export const CarouselTariffsCard = JSX<CarouselTariffsCardProps>(
33
27
  data,
34
28
  ...rest
35
29
  }) => {
36
- const cellsNode = cardCells.map(renderCardInfo);
37
-
38
- const [visibleCells, hiddenCells] =
39
- visibleCellsCount > 0
40
- ? [cellsNode.slice(0, visibleCellsCount), cellsNode.slice(visibleCellsCount)]
41
- : [cellsNode, []];
42
- const [isVisible, setIsVisible] = useState(false);
30
+ const { isUnfolded, parent: firedParent } = useSubjectState(
31
+ carouselTariffsCardEventBus.observable,
32
+ 'fold',
33
+ {},
34
+ );
35
+ const isVisible = isUnfolded && firedParent === options?.parent;
43
36
 
44
- useEffect(
37
+ const toggle = useCallback(
45
38
  () =>
46
- defaultEventBus.subscribe('fold', (event) => {
47
- if (options?.parent !== undefined && event.parent === options?.parent) {
48
- setIsVisible(event.isUnfolded);
49
- }
39
+ carouselTariffsCardEventBus.emitter.fire('fold', {
40
+ isUnfolded: !isVisible,
41
+ parent: options?.parent,
50
42
  }),
51
- [options?.parent],
43
+ [isVisible, options?.parent],
52
44
  );
53
45
 
54
46
  return (
@@ -62,49 +54,14 @@ export const CarouselTariffsCard = JSX<CarouselTariffsCardProps>(
62
54
  <Heading className={style('pt-xs', align)} headingType="h5" title={title} />
63
55
  ) : null}
64
56
  {button?.text ? <LinkButton className="w-full mt-m mb-lg" {...button} /> : null}
65
- {hiddenCells.length ? (
66
- <Foldable
67
- renderFoldableSection={() => (
68
- <div>
69
- {visibleCells}
70
- <FoldableSection isUnfolded={isVisible}>{hiddenCells}</FoldableSection>
71
- </div>
72
- )}
73
- renderFoldButton={
74
- cardCells.length >= visibleCellsCount
75
- ? renderFoldButton(options?.parent, data, isVisible)
76
- : null
77
- }
78
- />
79
- ) : (
80
- <div>{visibleCells}</div>
81
- )}
57
+ <CardCellsSection
58
+ cardCells={cardCells}
59
+ visibleCellsCount={visibleCellsCount}
60
+ isUnfolded={isVisible}
61
+ data={data}
62
+ onToggle={toggle}
63
+ />
82
64
  </BlockWrapper>
83
65
  );
84
66
  },
85
67
  );
86
-
87
- const renderFoldButton =
88
- (parent?: Slot, data?: AspectsDef[], isUnfolded = false) =>
89
- (): VNode =>
90
- (
91
- <button
92
- className="w-full cursor-pointer text-primary-main pt-lg flex justify-between items-center"
93
- onClick={() => {
94
- if (parent !== undefined) {
95
- defaultEventBus.fire('fold', { type: 'fold', isUnfolded: !isUnfolded, parent });
96
- }
97
- }}
98
- type="button"
99
- // eslint-disable-next-line react/jsx-props-no-spreading
100
- {...(isUnfolded ? getAspectsAttributes(data) : {})}
101
- >
102
- <div>{isUnfolded ? 'Скрыть' : 'Подробнее о тарифе'}</div>
103
- <Icon
104
- className="text-primary-text"
105
- name={isUnfolded ? 'ArrowUpIcon' : 'ArrowDownIcon'}
106
- width="16"
107
- height="16"
108
- />
109
- </button>
110
- );
@@ -0,0 +1,11 @@
1
+ import { EventBus } from '../../EventBus/EventBus';
2
+ import { type Slot } from '../../model/ContentPageDef';
3
+
4
+ export type CarouselTariffsCardFoldAction = {
5
+ isUnfolded?: boolean;
6
+ parent?: Slot;
7
+ };
8
+
9
+ export const carouselTariffsCardEventBus = new EventBus<{
10
+ fold: CarouselTariffsCardFoldAction;
11
+ }>();
@@ -1,5 +1,5 @@
1
1
  import { JSX } from '@redneckz/uni-jsx';
2
- import { useLocation } from '../../hooks/useLocation';
2
+ import { useLocationState } from '../../hooks/useLocation';
3
3
  import { BaseTile } from '../../ui-kit/BaseTile/BaseTile';
4
4
  import { BlockWrapper } from '../../ui-kit/BlockWrapper';
5
5
  import { Heading } from '../../ui-kit/Heading/Heading';
@@ -19,7 +19,7 @@ export interface ExchangeRateTileProps extends ExchangeRateTileContent, UniBlock
19
19
 
20
20
  export const ExchangeRateTile = JSX<ExchangeRateTileProps>(
21
21
  ({ className = '', title = 'Курсы обмена валют', button, ...rest }) => {
22
- const [currentLocation] = useLocation();
22
+ const currentLocation = useLocationState();
23
23
  const exchangeRates = useFetchExchangeRateData(currentLocation);
24
24
 
25
25
  const currencyRates = getCurrencyRates(exchangeRates?.exchangeRate?.currencies);
@@ -4,7 +4,7 @@ import { type SearchHeaderProps } from '../../data/CommonData';
4
4
  import { type HeaderData } from '../../data/HeaderData';
5
5
  import { type NavigationData } from '../../data/NavigationData';
6
6
  import { getAspectsWithInclude } from '../../hooks/useAspects/aspects/getAspectsWithInclude';
7
- import { useLocation } from '../../hooks/useLocation';
7
+ import { useLocationState } from '../../hooks/useLocation';
8
8
  import { type BlockVersion } from '../../model/BlockVersion';
9
9
  import { type IconVersion } from '../../model/IconVersion';
10
10
  import { useLocationDialog } from '../../ui-kit/LocationDialog/useLocationDialog';
@@ -22,7 +22,7 @@ export const HeaderSecondaryMenu = JSX<HeaderSecondaryMenuProps>(
22
22
  ({ className, version, ...rest }) => {
23
23
  const iconVersion: IconVersion = version === 'transparent' ? 'white' : 'black';
24
24
 
25
- const [currentLocation] = useLocation(rest?.branches?.default);
25
+ const currentLocation = useLocationState(rest?.branches?.default);
26
26
 
27
27
  const searchDialog = useSearchDialog(rest);
28
28
  const locationDialog = useLocationDialog(rest);
@@ -1,5 +1,5 @@
1
1
  import { JSX } from '@redneckz/uni-jsx';
2
- import { useLocation } from '../../hooks/useLocation';
2
+ import { useLocationState } from '../../hooks/useLocation';
3
3
  import { type AtmsDef } from './OfficesAtmsMapContent';
4
4
  import { OfficesAtmsMapLayout } from './OfficesAtmsMapLayout';
5
5
  import { type Atm } from './OfficesAtmsMapProps';
@@ -30,8 +30,7 @@ export interface AtmsMapProps {
30
30
  }
31
31
 
32
32
  export const AtmsMap = JSX<AtmsMapProps>(({ descriptionData, className }) => {
33
- const [currentLocation] = useLocation();
34
-
33
+ const currentLocation = useLocationState();
35
34
  const regionCode = currentLocation?.code ?? '000';
36
35
 
37
36
  const { data: officesData, isLoad } = useAtms(regionCode);
@@ -1,5 +1,5 @@
1
1
  import { JSX } from '@redneckz/uni-jsx';
2
- import { useLocation } from '../../hooks/useLocation';
2
+ import { useLocationState } from '../../hooks/useLocation';
3
3
  import { OfficesAtmsMapLayout } from './OfficesAtmsMapLayout';
4
4
  import { getOfficePoint, renderOfficeCard } from './renderOfficeCard';
5
5
  import { getRemoteWorkplacePoint, renderRemoteWorkplaceCard } from './renderRemoteWorkplaceCard';
@@ -10,7 +10,7 @@ export interface OfficesMapProps {
10
10
  }
11
11
 
12
12
  export const OfficesMap = JSX<OfficesMapProps>(({ className }) => {
13
- const [currentLocation] = useLocation();
13
+ const currentLocation = useLocationState();
14
14
  const regionCode = currentLocation?.code ?? '000';
15
15
  const { data, isLoad } = useOffices(regionCode);
16
16
 
@@ -4,7 +4,7 @@ import { type HeaderData } from '../../data/HeaderData';
4
4
  import { type JSONRefObject } from '../../data/JSONRefObject';
5
5
  import { type StickyMenuItem } from '../../data/StickyMobileData';
6
6
  import { env } from '../../Env';
7
- import { useLocation } from '../../hooks/useLocation';
7
+ import { useLocationState } from '../../hooks/useLocation';
8
8
  import { Heading } from '../../ui-kit/Heading/Heading';
9
9
  import { useLocationDialog } from '../../ui-kit/LocationDialog/useLocationDialog';
10
10
  import { getBasePath } from '../../utils/getBasePath';
@@ -22,7 +22,7 @@ export interface BurgerMenuDialogProps {
22
22
  export const BurgerMenuDialog = JSX<BurgerMenuDialogProps>(
23
23
  ({ menuRef, menuItem, locationDialogProps, closeAll }) => {
24
24
  const locationDialog = useLocationDialog(locationDialogProps || {});
25
- const [{ name: location }] = useLocation();
25
+ const { name: location } = useLocationState();
26
26
  const menuDimensions = menuRef?.current?.getBoundingClientRect();
27
27
  const basePath = getBasePath(env.SITE_URL);
28
28
 
@@ -1,54 +1,40 @@
1
- import { useCallback, useEffect } from '@redneckz/uni-jsx/lib/hooks';
2
- import { useAsyncData } from '@redneckz/uni-jsx/lib/hooks/useAsyncData';
1
+ import { useEffect } from '@redneckz/uni-jsx/lib/hooks';
3
2
  import { defaultEventBus } from '../EventBus/defaultEventBus';
4
- import { useLatestEvent } from '../EventBus/useLatestEvent';
5
- import { fetchJSONUnsafe, type FetchJSONUnsafeType } from '../utils/fetchJSON';
3
+ import { useSubject } from '../EventBus/useSubject';
4
+ import { useSubjectState } from '../EventBus/useSubjectState';
5
+ import { fetchJSON } from '../utils/fetchJSON';
6
6
  import { type Region } from './useRegions';
7
7
 
8
8
  const REGION_URL = '/api/v1/region';
9
9
  const LOCATION_STORAGE_KEY = 'location';
10
10
 
11
- export function useLocation(defaultLocation = 'Москва'): [Region, (_: Region) => void] {
12
- const [currentLocation, fireCurrentLocation] = useLatestEvent(
13
- defaultEventBus,
14
- 'location',
15
- restoreLocation() ?? { name: defaultLocation },
16
- );
17
-
18
- const selectCurrentLocation = useCallback((_: Region) => {
19
- storeLocation(_);
20
- fireCurrentLocation(_);
21
- }, []);
22
-
23
- const { data } = useAsyncData(
24
- hasStoredLocation() ? null : REGION_URL,
25
- fetchJSONUnsafe as FetchJSONUnsafeType<Region>,
26
- );
27
- useEffect(() => {
28
- if (data && !hasStoredLocation()) {
29
- fireCurrentLocation(data);
11
+ export function useLocation(defaultLocation = 'Москва'): (_: Region) => void {
12
+ useEffect(() => defaultEventBus.subscribe('location', storeLocation), []);
13
+
14
+ return useSubject(defaultEventBus.emitter, 'location', restoreLocation(defaultLocation));
15
+ }
16
+
17
+ export function useLocationState(defaultLocation = 'Москва'): Region {
18
+ return useSubjectState(defaultEventBus.observable, 'location', { name: defaultLocation });
19
+ }
20
+
21
+ function restoreLocation(defaultLocation: string) {
22
+ return async (): Promise<Region> => {
23
+ if (!globalThis.localStorage?.hasItem(LOCATION_STORAGE_KEY)) {
24
+ storeLocation(await fetchJSON<Region>(REGION_URL));
25
+ }
26
+
27
+ const storedLocation = globalThis.localStorage?.getItem(LOCATION_STORAGE_KEY);
28
+ try {
29
+ return storedLocation && JSON.parse(storedLocation);
30
+ } catch (ex) {
31
+ // Do nothing
30
32
  }
31
- }, [data]);
32
33
 
33
- return [currentLocation ?? { name: defaultLocation }, selectCurrentLocation];
34
+ return { name: defaultLocation };
35
+ };
34
36
  }
35
37
 
36
- const hasStoredLocation = () => Boolean(globalThis.localStorage?.getItem(LOCATION_STORAGE_KEY));
37
-
38
- const restoreLocation = (): Region | null => {
39
- try {
40
- const data = globalThis.localStorage?.getItem(LOCATION_STORAGE_KEY);
41
-
42
- return data && JSON.parse(data);
43
- } catch (ex) {
44
- return null;
45
- }
46
- };
47
-
48
- const storeLocation = (_: Region) => {
49
- try {
50
- globalThis.localStorage?.setItem(LOCATION_STORAGE_KEY, JSON.stringify(_));
51
- } catch (ex) {
52
- // Do nothing
53
- }
54
- };
38
+ function storeLocation(_: Region | null | undefined) {
39
+ _ && globalThis.localStorage?.setItem(LOCATION_STORAGE_KEY, JSON.stringify(_));
40
+ }
@@ -0,0 +1,21 @@
1
+ import { useCallback, useState } from '@redneckz/uni-jsx/lib/hooks';
2
+
3
+ export type NotUndefined = object | null;
4
+ export type Reducer<S, A extends NotUndefined> = (state: S, action: A) => S;
5
+ export type Dispatch<A extends NotUndefined> = (action: A) => void;
6
+
7
+ export function useReducer<S, A extends NotUndefined>(
8
+ reducer: Reducer<S, A>,
9
+ initialArg: S,
10
+ ): [state: S, dispatch: Dispatch<A>] {
11
+ const [state, setState] = useState(initialArg);
12
+
13
+ const dispatch = useCallback(
14
+ (action: A) => {
15
+ setState((_) => reducer(_, action));
16
+ },
17
+ [reducer],
18
+ );
19
+
20
+ return [state, dispatch];
21
+ }
@@ -11,8 +11,11 @@ export interface Region {
11
11
  localities?: string[];
12
12
  }
13
13
 
14
+ const EMPTY_REGIONS: Region[] = [];
15
+
16
+ // TODO Почему url можно менять? Разве смысл не в инкапсуляции api url. Тоже под рефакторинг попадает
14
17
  export function useRegions(url: string = REGIONS_URL): Region[] {
15
18
  const { data } = useAsyncData(url, fetchJSONUnsafe as FetchJSONUnsafeType<Region[]>);
16
19
 
17
- return Array.isArray(data) ? data : [];
20
+ return Array.isArray(data) ? data : EMPTY_REGIONS;
18
21
  }
@@ -8,7 +8,7 @@ export interface DialogOptions {
8
8
 
9
9
  export const useDialogManager = () => ({
10
10
  open: (dialog: VNode, options: DialogOptions = {}) =>
11
- defaultEventBus.fire('dialog', { type: 'open', dialog, ...options }),
12
- close: () => defaultEventBus.fire('dialog', { type: 'close' }),
13
- closeAll: () => defaultEventBus.fire('dialog', { type: 'close', all: true }),
11
+ defaultEventBus.emitter.fire('dialog', { type: 'open', dialog, ...options }),
12
+ close: () => defaultEventBus.emitter.fire('dialog', { type: 'close' }),
13
+ closeAll: () => defaultEventBus.emitter.fire('dialog', { type: 'close', all: true }),
14
14
  });
@@ -27,7 +27,7 @@ export const useDialogsList = ({
27
27
 
28
28
  useEffect(
29
29
  () =>
30
- defaultEventBus.subscribe('dialog', (action) => {
30
+ defaultEventBus.observable.subscribe('dialog', (action) => {
31
31
  switch (action.type) {
32
32
  case 'open':
33
33
  push(action);
@@ -3,14 +3,30 @@ import { useCallback, useState } from '@redneckz/uni-jsx/lib/hooks';
3
3
  import { type VNode } from '../../model/VNode';
4
4
  import { type FoldablePartProps } from './FoldablePartProps';
5
5
 
6
- export interface FoldableProps {
6
+ export interface FoldableWrapperProps {
7
7
  className?: string;
8
+ }
9
+
10
+ export interface FoldableProps extends FoldableWrapperProps {
8
11
  unfoldedByDefault?: boolean;
9
12
  isFoldButtonOnTop?: boolean;
10
13
  renderFoldableSection: (props: FoldablePartProps) => VNode;
11
14
  renderFoldButton?: ((props: FoldablePartProps) => VNode) | null;
12
15
  }
13
16
 
17
+ export const FoldableWrapper = JSX<FoldableWrapperProps>(({ className, children }) => (
18
+ <div className={className} role="group">
19
+ {children}
20
+ </div>
21
+ ));
22
+
23
+ /**
24
+ * Какой то бесполезный компонент. Его можно заменить на useBool
25
+ * Лучше оставить только обёрточный div с необходимой атрибутикой
26
+ * и сделать пассивный компонент
27
+ *
28
+ * @deprecated
29
+ */
14
30
  export const Foldable = JSX<FoldableProps>(
15
31
  ({
16
32
  className = '',
@@ -29,15 +45,15 @@ export const Foldable = JSX<FoldableProps>(
29
45
  const buttonNode = renderFoldButton ? renderFoldButton({ isUnfolded, onToggle }) : null;
30
46
 
31
47
  return isFoldButtonOnTop ? (
32
- <div className={className} role="group">
48
+ <FoldableWrapper className={className}>
33
49
  {buttonNode}
34
50
  {sectionNode}
35
- </div>
51
+ </FoldableWrapper>
36
52
  ) : (
37
- <div className={className} role="group">
53
+ <FoldableWrapper className={className}>
38
54
  {sectionNode}
39
55
  {buttonNode}
40
- </div>
56
+ </FoldableWrapper>
41
57
  );
42
58
  },
43
59
  );
@@ -26,4 +26,5 @@ export const FEEDBACK_METHOD: Option[] = [
26
26
  { key: 'email', text: 'Электронное сообщение' },
27
27
  ];
28
28
 
29
+ // TODO Тоже надо рефакторить - файлик constants
29
30
  export const OUT_SERVICE_URL = '/api/v1/outservice/outserviceregions';
@@ -2,5 +2,6 @@ import { type FieldProps } from '../../hooks/useForm';
2
2
  import { type Validator } from '../../validation/validator';
3
3
  import { withValidator } from '../../validation/withValidator';
4
4
 
5
+ // TODO Зачем это?
5
6
  export const getValidation = (field: FieldProps<any>, validator: Validator, required = false) =>
6
7
  required ? withValidator(field, validator) : field;