@redneckz/wildless-cms-uni-blocks 0.14.675 → 0.14.676

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 (175) hide show
  1. package/bundle/EventBus/EventBus.d.ts +1 -8
  2. package/bundle/EventBus/defaultEventBus.d.ts +0 -9
  3. package/bundle/bundle.umd.js +398 -132
  4. package/bundle/bundle.umd.min.js +1 -1
  5. package/bundle/hooks/useLocation.d.ts +4 -1
  6. package/bundle/ui-kit/LocationDialog/SelectedLocation.d.ts +5 -0
  7. package/dist/EventBus/EventBus.d.ts +1 -8
  8. package/dist/EventBus/EventBus.js +2 -28
  9. package/dist/EventBus/EventBus.js.map +1 -1
  10. package/dist/EventBus/defaultEventBus.d.ts +0 -9
  11. package/dist/EventBus/defaultEventBus.js.map +1 -1
  12. package/dist/components/CarouselTariffsCard/CarouselTariffsCard.js +1 -1
  13. package/dist/components/CarouselTariffsCard/CarouselTariffsCard.js.map +1 -1
  14. package/dist/components/ContentPage/ContentPage.js +2 -0
  15. package/dist/components/ContentPage/ContentPage.js.map +1 -1
  16. package/dist/components/ExchangeRateTile/ExchangeRateTile.js +1 -1
  17. package/dist/components/ExchangeRateTile/ExchangeRateTile.js.map +1 -1
  18. package/dist/components/Header/HeaderSecondaryMenu.js +1 -1
  19. package/dist/components/Header/HeaderSecondaryMenu.js.map +1 -1
  20. package/dist/components/OfficesAtmsMap/AtmsMap.js +1 -1
  21. package/dist/components/OfficesAtmsMap/AtmsMap.js.map +1 -1
  22. package/dist/components/OfficesAtmsMap/OfficesMap.js +1 -1
  23. package/dist/components/OfficesAtmsMap/OfficesMap.js.map +1 -1
  24. package/dist/components/StickyBottomMenu/BurgerMenuDialog.js +1 -1
  25. package/dist/components/StickyBottomMenu/BurgerMenuDialog.js.map +1 -1
  26. package/dist/hooks/useLocation.d.ts +4 -1
  27. package/dist/hooks/useLocation.js +16 -34
  28. package/dist/hooks/useLocation.js.map +1 -1
  29. package/dist/hooks/useRegions.js +3 -1
  30. package/dist/hooks/useRegions.js.map +1 -1
  31. package/dist/ui-kit/DialogManager/useDialogsList.js +3 -0
  32. package/dist/ui-kit/DialogManager/useDialogsList.js.map +1 -1
  33. package/dist/ui-kit/LocationDialog/LocationDialog.js +11 -14
  34. package/dist/ui-kit/LocationDialog/LocationDialog.js.map +1 -1
  35. package/dist/ui-kit/LocationDialog/SelectedLocation.d.ts +5 -0
  36. package/dist/ui-kit/LocationDialog/SelectedLocation.js +15 -0
  37. package/dist/ui-kit/LocationDialog/SelectedLocation.js.map +1 -0
  38. package/dist/ui-kit/PopupManager/PopupManager.js +3 -0
  39. package/dist/ui-kit/PopupManager/PopupManager.js.map +1 -1
  40. package/lib/EventBus/EventBus.d.ts +1 -8
  41. package/lib/EventBus/EventBus.js +1 -27
  42. package/lib/EventBus/EventBus.js.map +1 -1
  43. package/lib/EventBus/defaultEventBus.d.ts +0 -9
  44. package/lib/EventBus/defaultEventBus.js.map +1 -1
  45. package/lib/components/CarouselTariffsCard/CarouselTariffsCard.js +1 -1
  46. package/lib/components/CarouselTariffsCard/CarouselTariffsCard.js.map +1 -1
  47. package/lib/components/ContentPage/ContentPage.js +2 -0
  48. package/lib/components/ContentPage/ContentPage.js.map +1 -1
  49. package/lib/components/ExchangeRateTile/ExchangeRateTile.js +1 -1
  50. package/lib/components/ExchangeRateTile/ExchangeRateTile.js.map +1 -1
  51. package/lib/components/Header/HeaderSecondaryMenu.js +1 -1
  52. package/lib/components/Header/HeaderSecondaryMenu.js.map +1 -1
  53. package/lib/components/OfficesAtmsMap/AtmsMap.js +1 -1
  54. package/lib/components/OfficesAtmsMap/AtmsMap.js.map +1 -1
  55. package/lib/components/OfficesAtmsMap/OfficesMap.js +1 -1
  56. package/lib/components/OfficesAtmsMap/OfficesMap.js.map +1 -1
  57. package/lib/components/StickyBottomMenu/BurgerMenuDialog.js +1 -1
  58. package/lib/components/StickyBottomMenu/BurgerMenuDialog.js.map +1 -1
  59. package/lib/hooks/useLocation.d.ts +4 -1
  60. package/lib/hooks/useLocation.js +15 -34
  61. package/lib/hooks/useLocation.js.map +1 -1
  62. package/lib/hooks/useRegions.js +3 -1
  63. package/lib/hooks/useRegions.js.map +1 -1
  64. package/lib/ui-kit/DialogManager/useDialogsList.js +3 -0
  65. package/lib/ui-kit/DialogManager/useDialogsList.js.map +1 -1
  66. package/lib/ui-kit/LocationDialog/LocationDialog.js +13 -16
  67. package/lib/ui-kit/LocationDialog/LocationDialog.js.map +1 -1
  68. package/lib/ui-kit/LocationDialog/SelectedLocation.d.ts +5 -0
  69. package/lib/ui-kit/LocationDialog/SelectedLocation.js +13 -0
  70. package/lib/ui-kit/LocationDialog/SelectedLocation.js.map +1 -0
  71. package/lib/ui-kit/PopupManager/PopupManager.js +3 -0
  72. package/lib/ui-kit/PopupManager/PopupManager.js.map +1 -1
  73. package/mobile/bundle/EventBus/EventBus.d.ts +1 -8
  74. package/mobile/bundle/EventBus/defaultEventBus.d.ts +0 -9
  75. package/mobile/bundle/bundle.umd.js +398 -132
  76. package/mobile/bundle/bundle.umd.min.js +1 -1
  77. package/mobile/bundle/hooks/useLocation.d.ts +4 -1
  78. package/mobile/bundle/ui-kit/LocationDialog/SelectedLocation.d.ts +5 -0
  79. package/mobile/dist/EventBus/EventBus.d.ts +1 -8
  80. package/mobile/dist/EventBus/EventBus.js +2 -28
  81. package/mobile/dist/EventBus/EventBus.js.map +1 -1
  82. package/mobile/dist/EventBus/defaultEventBus.d.ts +0 -9
  83. package/mobile/dist/EventBus/defaultEventBus.js.map +1 -1
  84. package/mobile/dist/components/CarouselTariffsCard/CarouselTariffsCard.js +1 -1
  85. package/mobile/dist/components/CarouselTariffsCard/CarouselTariffsCard.js.map +1 -1
  86. package/mobile/dist/components/ContentPage/ContentPage.js +2 -0
  87. package/mobile/dist/components/ContentPage/ContentPage.js.map +1 -1
  88. package/mobile/dist/components/ExchangeRateTile/ExchangeRateTile.js +1 -1
  89. package/mobile/dist/components/ExchangeRateTile/ExchangeRateTile.js.map +1 -1
  90. package/mobile/dist/components/Header/HeaderSecondaryMenu.js +1 -1
  91. package/mobile/dist/components/Header/HeaderSecondaryMenu.js.map +1 -1
  92. package/mobile/dist/components/OfficesAtmsMap/AtmsMap.js +1 -1
  93. package/mobile/dist/components/OfficesAtmsMap/AtmsMap.js.map +1 -1
  94. package/mobile/dist/components/OfficesAtmsMap/OfficesMap.js +1 -1
  95. package/mobile/dist/components/OfficesAtmsMap/OfficesMap.js.map +1 -1
  96. package/mobile/dist/components/StickyBottomMenu/BurgerMenuDialog.js +1 -1
  97. package/mobile/dist/components/StickyBottomMenu/BurgerMenuDialog.js.map +1 -1
  98. package/mobile/dist/hooks/useLocation.d.ts +4 -1
  99. package/mobile/dist/hooks/useLocation.js +16 -34
  100. package/mobile/dist/hooks/useLocation.js.map +1 -1
  101. package/mobile/dist/hooks/useRegions.js +3 -1
  102. package/mobile/dist/hooks/useRegions.js.map +1 -1
  103. package/mobile/dist/ui-kit/DialogManager/useDialogsList.js +3 -0
  104. package/mobile/dist/ui-kit/DialogManager/useDialogsList.js.map +1 -1
  105. package/mobile/dist/ui-kit/LocationDialog/LocationDialog.js +11 -14
  106. package/mobile/dist/ui-kit/LocationDialog/LocationDialog.js.map +1 -1
  107. package/mobile/dist/ui-kit/LocationDialog/SelectedLocation.d.ts +5 -0
  108. package/mobile/dist/ui-kit/LocationDialog/SelectedLocation.js +15 -0
  109. package/mobile/dist/ui-kit/LocationDialog/SelectedLocation.js.map +1 -0
  110. package/mobile/dist/ui-kit/PopupManager/PopupManager.js +3 -0
  111. package/mobile/dist/ui-kit/PopupManager/PopupManager.js.map +1 -1
  112. package/mobile/lib/EventBus/EventBus.d.ts +1 -8
  113. package/mobile/lib/EventBus/EventBus.js +1 -27
  114. package/mobile/lib/EventBus/EventBus.js.map +1 -1
  115. package/mobile/lib/EventBus/defaultEventBus.d.ts +0 -9
  116. package/mobile/lib/EventBus/defaultEventBus.js.map +1 -1
  117. package/mobile/lib/components/CarouselTariffsCard/CarouselTariffsCard.js +1 -1
  118. package/mobile/lib/components/CarouselTariffsCard/CarouselTariffsCard.js.map +1 -1
  119. package/mobile/lib/components/ContentPage/ContentPage.js +2 -0
  120. package/mobile/lib/components/ContentPage/ContentPage.js.map +1 -1
  121. package/mobile/lib/components/ExchangeRateTile/ExchangeRateTile.js +1 -1
  122. package/mobile/lib/components/ExchangeRateTile/ExchangeRateTile.js.map +1 -1
  123. package/mobile/lib/components/Header/HeaderSecondaryMenu.js +1 -1
  124. package/mobile/lib/components/Header/HeaderSecondaryMenu.js.map +1 -1
  125. package/mobile/lib/components/OfficesAtmsMap/AtmsMap.js +1 -1
  126. package/mobile/lib/components/OfficesAtmsMap/AtmsMap.js.map +1 -1
  127. package/mobile/lib/components/OfficesAtmsMap/OfficesMap.js +1 -1
  128. package/mobile/lib/components/OfficesAtmsMap/OfficesMap.js.map +1 -1
  129. package/mobile/lib/components/StickyBottomMenu/BurgerMenuDialog.js +1 -1
  130. package/mobile/lib/components/StickyBottomMenu/BurgerMenuDialog.js.map +1 -1
  131. package/mobile/lib/hooks/useLocation.d.ts +4 -1
  132. package/mobile/lib/hooks/useLocation.js +15 -34
  133. package/mobile/lib/hooks/useLocation.js.map +1 -1
  134. package/mobile/lib/hooks/useRegions.js +3 -1
  135. package/mobile/lib/hooks/useRegions.js.map +1 -1
  136. package/mobile/lib/ui-kit/DialogManager/useDialogsList.js +3 -0
  137. package/mobile/lib/ui-kit/DialogManager/useDialogsList.js.map +1 -1
  138. package/mobile/lib/ui-kit/LocationDialog/LocationDialog.js +13 -16
  139. package/mobile/lib/ui-kit/LocationDialog/LocationDialog.js.map +1 -1
  140. package/mobile/lib/ui-kit/LocationDialog/SelectedLocation.d.ts +5 -0
  141. package/mobile/lib/ui-kit/LocationDialog/SelectedLocation.js +13 -0
  142. package/mobile/lib/ui-kit/LocationDialog/SelectedLocation.js.map +1 -0
  143. package/mobile/lib/ui-kit/PopupManager/PopupManager.js +3 -0
  144. package/mobile/lib/ui-kit/PopupManager/PopupManager.js.map +1 -1
  145. package/mobile/src/EventBus/EventBus.ts +1 -36
  146. package/mobile/src/EventBus/defaultEventBus.ts +0 -10
  147. package/mobile/src/components/CarouselTariffsCard/CarouselTariffsCard.tsx +1 -1
  148. package/mobile/src/components/ContentPage/ContentPage.tsx +2 -0
  149. package/mobile/src/components/ExchangeRateTile/ExchangeRateTile.tsx +1 -1
  150. package/mobile/src/components/Header/HeaderSecondaryMenu.tsx +1 -1
  151. package/mobile/src/components/OfficesAtmsMap/AtmsMap.tsx +1 -1
  152. package/mobile/src/components/OfficesAtmsMap/OfficesMap.tsx +1 -1
  153. package/mobile/src/components/StickyBottomMenu/BurgerMenuDialog.tsx +1 -1
  154. package/mobile/src/hooks/useLocation.ts +25 -47
  155. package/mobile/src/hooks/useRegions.ts +4 -1
  156. package/mobile/src/ui-kit/DialogManager/useDialogsList.ts +3 -0
  157. package/mobile/src/ui-kit/LocationDialog/LocationDialog.tsx +22 -28
  158. package/mobile/src/ui-kit/LocationDialog/SelectedLocation.tsx +27 -0
  159. package/mobile/src/ui-kit/PopupManager/PopupManager.tsx +3 -0
  160. package/package.json +5 -5
  161. package/src/EventBus/EventBus.ts +1 -36
  162. package/src/EventBus/defaultEventBus.ts +0 -10
  163. package/src/components/CarouselTariffsCard/CarouselTariffsCard.tsx +1 -1
  164. package/src/components/ContentPage/ContentPage.tsx +2 -0
  165. package/src/components/ExchangeRateTile/ExchangeRateTile.tsx +1 -1
  166. package/src/components/Header/HeaderSecondaryMenu.tsx +1 -1
  167. package/src/components/OfficesAtmsMap/AtmsMap.tsx +1 -1
  168. package/src/components/OfficesAtmsMap/OfficesMap.tsx +1 -1
  169. package/src/components/StickyBottomMenu/BurgerMenuDialog.tsx +1 -1
  170. package/src/hooks/useLocation.ts +25 -47
  171. package/src/hooks/useRegions.ts +4 -1
  172. package/src/ui-kit/DialogManager/useDialogsList.ts +3 -0
  173. package/src/ui-kit/LocationDialog/LocationDialog.tsx +22 -28
  174. package/src/ui-kit/LocationDialog/SelectedLocation.tsx +27 -0
  175. package/src/ui-kit/PopupManager/PopupManager.tsx +3 -0
@@ -414,32 +414,53 @@
414
414
  className,
415
415
  ].join(' ');
416
416
 
417
- class EventBus {
418
- subscribers = {};
419
- subjectsStateMap = {};
420
- subscribe(type, listener) {
421
- this.subscribers[type] = (this.subscribers[type] || []).concat(listener);
422
- const latestEvent = this.subjectsStateMap[type];
423
- if (latestEvent) {
424
- listener(latestEvent);
425
- }
426
- return () => {
427
- this.unsubscribe(type, listener);
428
- };
429
- }
430
- unsubscribe(type, listener) {
431
- this.subscribers[type] = this.subscribers[type]?.filter((s) => s !== listener);
432
- }
433
- fire(type, event) {
434
- const isSubjectDeclared = type in this.subjectsStateMap;
435
- if (isSubjectDeclared) {
436
- this.subjectsStateMap[type] = event;
437
- }
438
- this.subscribers[type]?.forEach((s) => s(event));
439
- }
440
- subject(type, event) {
441
- this.subjectsStateMap[type] = event;
442
- }
417
+ class EventBus {
418
+ watchers = new Set();
419
+ subscribersMap = {};
420
+ subjectsStateMap = {};
421
+ emitter = this;
422
+ observable = this;
423
+ watch(watcher) {
424
+ this.watchers.add(watcher);
425
+ return () => {
426
+ this.watchers.delete(watcher);
427
+ };
428
+ }
429
+ subscribe(type, listener) {
430
+ this.subscribersMap[type] ||= new Set();
431
+ this.subscribersMap[type]?.add(listener);
432
+ const initialEvent = this.subjectsStateMap[type];
433
+ initialEvent && listener(initialEvent);
434
+ return () => {
435
+ this.subscribersMap[type]?.delete(listener);
436
+ };
437
+ }
438
+ fire(type, event) {
439
+ const isSubjectDeclared = type in this.subjectsStateMap;
440
+ if (isSubjectDeclared) {
441
+ this.subject(type, event);
442
+ }
443
+ else {
444
+ this.fireSubscribers(type, event);
445
+ }
446
+ }
447
+ subject(type, event) {
448
+ if (this.subjectsStateMap[type] !== event) {
449
+ this.subjectsStateMap[type] = event ?? undefined;
450
+ this.fireSubscribers(type, event);
451
+ }
452
+ return () => {
453
+ delete this.subjectsStateMap[type];
454
+ };
455
+ }
456
+ fireSubscribers(type, event) {
457
+ for (const _ of this.subscribersMap[type] ?? []) {
458
+ _(event ?? null);
459
+ }
460
+ for (const _ of this.watchers) {
461
+ _({ type, event: event ?? null });
462
+ }
463
+ }
443
464
  }
444
465
 
445
466
  const defaultEventBus = new EventBus();
@@ -725,26 +746,166 @@
725
746
  const leftOrRightImage = (img, directionRight) => directionRight ? { rightImage: img } : { leftImage: img };
726
747
  const renderTags = (tags) => (tags?.length ? jsx(Tags, { tags: tags }) : null);
727
748
 
749
+ class JSONBox {
750
+ _;
751
+ constructor(_) {
752
+ this._ = _;
753
+ }
754
+ of(_) {
755
+ return new this.constructor(_ instanceof JSONBox ? _._ : _);
756
+ }
757
+ filter(predicate) {
758
+ return this.from(this.entries().filter(predicate));
759
+ }
760
+ map(mapper) {
761
+ return this.from(this.entries().map(mapper));
762
+ }
763
+ flatMap(mapper) {
764
+ return this.from(this.entries().flatMap(mapper));
765
+ }
766
+ reduce(reducer, initial) {
767
+ return this.entries().reduce(reducer.bind(this), initial);
768
+ }
769
+ }
770
+
771
+ const trueF = () => true;
772
+ const and = (a, b) => (...args) => a(...args) && b(...args);
773
+
774
+ const table = (...table) => (...input) => {
775
+ const [, unit] = assertNonEmpty$1(table.find(([predicate]) => predicate(...input)));
776
+ return unit(...input);
777
+ };
778
+ function assertNonEmpty$1(value) {
779
+ if (!value) {
780
+ throw new Error('Value should be fulfilled');
781
+ }
782
+ return value;
783
+ }
784
+
728
785
  const isJSONArray = (_) => Boolean(_ && Array.isArray(_));
729
- const isJSONRecord = (_) => Boolean(_ && !Array.isArray(_) && typeof _ === 'object');
730
- const isJSONRef = (_) => Boolean(isJSONRecord(_) && typeof _.$ref === 'string');
786
+ const isJSONRecord = (_) => Boolean(_ && typeof _ === 'object' && !isJSONArray(_));
731
787
 
732
- const mapJSONNode = (json, handlers) => {
733
- if (isJSONRef(json)) {
734
- return handlers.ref(json);
788
+ const identity$1 = (x) => x;
789
+
790
+ const t0 = (fn = identity$1) => ([_]) => fn(_);
791
+ const t1 = (fn = identity$1) => ([, _]) => fn(_);
792
+
793
+ function unbox(box) {
794
+ return box instanceof JSONBox ? box._ : box;
795
+ }
796
+
797
+ class JSONArrayBox extends JSONBox {
798
+ from(entries) {
799
+ return this.of(entries.map(t1(unbox)));
735
800
  }
736
- else if (isJSONRecord(json)) {
737
- return handlers.record(json);
801
+ entries() {
802
+ return (this._ ?? []).map((node, p) => [p, this.of(node)]);
738
803
  }
739
- else if (isJSONArray(json)) {
740
- return handlers.array(json);
804
+ size() {
805
+ return this._?.length ?? 0;
741
806
  }
742
- else {
743
- return handlers.scalar ? handlers.scalar(json) : json;
807
+ get(p) {
808
+ return this.of(typeof p === 'number' ? this._?.[p] : undefined);
809
+ }
810
+ set(p, child) {
811
+ return this.of(isJSONArray(this._)
812
+ ? Array.from({ length: Math.max(this._.length, Number(p) + 1) }, (x, i) => (i === p ? child : this._[i]))
813
+ : Array.from({ length: Number(p) + 1 }, (x, i) => (i === p ? child : undefined)));
814
+ }
815
+ }
816
+
817
+ class JSONLeafBox extends JSONBox {
818
+ from() {
819
+ return this;
820
+ }
821
+ entries() {
822
+ return [];
823
+ }
824
+ size() {
825
+ return 0;
826
+ }
827
+ get(p) {
828
+ return this.of(p !== undefined ? undefined /* no childs */ : this._ /* self */);
829
+ }
830
+ set(p, child) {
831
+ return this.of(child);
832
+ }
833
+ }
834
+
835
+ class JSONRecordBox extends JSONBox {
836
+ from(entries) {
837
+ return this.of(Object.fromEntries(entries.map(([p, box]) => [p, unbox(box)])));
838
+ }
839
+ entries() {
840
+ return Object.entries(this._ ?? {}).map(([p, node]) => [p, this.of(node)]);
841
+ }
842
+ size() {
843
+ return Object.keys(this._ ?? {}).length;
844
+ }
845
+ get(p) {
846
+ return this.of(typeof p === 'string' ? this._?.[p] : undefined);
744
847
  }
848
+ set(p, child) {
849
+ return this.of({ ...this._, [p]: child });
850
+ }
851
+ }
852
+
853
+ class JSONBoxDefault extends JSONBox {
854
+ proto = table([p => isJSONArray(this._) || typeof p === 'number', () => JSONArrayBox.prototype], [p => isJSONRecord(this._) || typeof p === 'string', () => JSONRecordBox.prototype], [trueF, () => JSONLeafBox.prototype]);
855
+ from(entries) {
856
+ return this.proto(undefined).from.call(this, entries);
857
+ }
858
+ entries() {
859
+ return this.proto(undefined).entries.call(this);
860
+ }
861
+ size() {
862
+ return this.proto(undefined).size.call(this);
863
+ }
864
+ get(p) {
865
+ return this.proto(p).get.call(this, p);
866
+ }
867
+ set(p, child) {
868
+ return this.proto(p).set.call(this, p, child);
869
+ }
870
+ }
871
+
872
+ const box = (_) => (_ instanceof JSONBox ? _ : new JSONBoxDefault(_));
873
+
874
+ const boxed = (fn) => {
875
+ const boxedFn = (node, ...args) => unbox(fn(box(node), ...args));
876
+ boxedFn.fn = fn;
877
+ return boxedFn;
745
878
  };
746
879
 
747
- const mergeRecords = (entries) => entries.reduce((acc, _) => Object.assign(acc, _), {});
880
+ const ROOT = [];
881
+ const endsWith = (suffix) => suffix
882
+ .map((predicate, i) => (path) => cmp(predicate)(path[i + path.length - suffix.length]))
883
+ .reduceRight(and, trueF);
884
+ const cmp = (a) => a instanceof Function ? a : (b) => a === b;
885
+
886
+ const reduce = (reducer) => (node, initial, path = ROOT) => box(node)
887
+ .entries()
888
+ .reduce((acc, [p, _]) => reduce(reducer)(_, acc, path.concat(p)), reducer(initial, [path, box(node)]));
889
+
890
+ const set = boxed((target, [path, node]) => {
891
+ const [p, ...tail] = path;
892
+ return target.set(p, tail.length ? set(target.get(p), [tail, node]) : node);
893
+ });
894
+
895
+ const fromEntries = boxed((initial, tree) => tree.reduce(set.fn, initial));
896
+
897
+ const leafs = (node) => reduce((acc, [path, _]) => (isLeaf(_) ? [...acc, [path, unbox(_)]] : acc))(node, []);
898
+ const isLeaf = (_) => _.size() === 0;
899
+
900
+ const map = (mapper, initial = {}) => (node) => fromEntries(initial, leafs(node).map(_ => mapper(_)));
901
+
902
+ const init = (list) => list.slice(0, -1);
903
+
904
+ boxed((target, path = ROOT) => path.reduce((_, p) => _.get(p), target));
905
+
906
+ const remove = boxed((target, [p, ...tail]) => tail.length ? target.set(p, remove(target.get(p), tail)) : target.filter(([i]) => i !== p));
907
+
908
+ const isJSONRefPath = endsWith(['$ref']);
748
909
 
749
910
  const parseJPointer = (uri) => uri.includes('#')
750
911
  ? uri
@@ -754,46 +915,17 @@
754
915
  : [];
755
916
 
756
917
  const resolveJPointer = (json, uri) => parseJPointer(uri).reduce(selectNodeByKey, json);
757
- const selectNodeByKey = (json, key) => {
758
- if (!json || !key) {
759
- return json;
760
- }
761
- if (isJSONRecord(json)) {
762
- return json[key];
763
- }
764
- else if (isJSONArray(json)) {
765
- return json[parseInt(key, 10)];
766
- }
767
- else {
768
- return json;
769
- }
770
- };
918
+ const selectNodeByKey = table([isJSONArray, (json, key) => json[parseInt(key, 10)]], [isJSONRecord, (json, key) => json[key]], [trueF, identity$1]);
771
919
 
772
- const resolveRef = (json, resolver) => mapJSONNode(json, {
773
- ref: ({ $ref, ...rest }) => resolveRef($ref ? resolveJPointer(resolver($ref), $ref) : rest, resolver),
774
- record: record => mergeRecords(Object.entries(record).map(([key, value]) => ({ [key]: resolveRef(value, resolver) }))),
775
- array: list => list.map(_ => resolveRef(_, resolver))
776
- });
920
+ const resolveRef = (json, resolver) => map(([path, node]) => isJSONRefPath(path)
921
+ ? [init(path), resolveJPointer(resolver(node), node)]
922
+ : [path, node])(json);
777
923
 
778
- const visitRef = (json, visitor, path = []) => {
779
- mapJSONNode(json, {
780
- ref: json => visitor(json.$ref, path),
781
- record: record => {
782
- for (const key in record)
783
- visitRef(record[key], visitor, [...path, key]);
784
- },
785
- array: list => {
786
- for (let i = 0; i < list.length; i++)
787
- visitRef(list[i], visitor, [...path, i]);
788
- }
789
- });
790
- };
924
+ const refEntries = (json) => leafs(json).filter(t0(isJSONRefPath));
791
925
 
792
- const collectRef = (json) => {
793
- const refs = [];
794
- visitRef(json, _ => refs.push(_));
795
- return refs;
796
- };
926
+ const unique$1 = (list) => [...new Set(list)];
927
+
928
+ const collectRef = (json) => unique$1(refEntries(json).map(([, _]) => _));
797
929
 
798
930
  async function fetchJSON(url, options) {
799
931
  try {
@@ -3156,10 +3288,10 @@
3156
3288
  const LegalFormField = JSX(({ field, input }) => (jsx(InputControl, { label: "\u041E\u041F\u0424", placeholder: "\u041E\u041E\u041E, \u041F\u0410\u041E \u0438 \u0434\u0440.", ...getValidation(field('legalForm'), validatorObj.legalForm, input?.required), ...input })));
3157
3289
 
3158
3290
  const OUT_SERVICE_BASE_URL = `${API_BASE_URI}/outservice`;
3159
- const EMPTY_REGIONS = [];
3291
+ const EMPTY_REGIONS$1 = [];
3160
3292
  async function getOutServiceRegions() {
3161
3293
  const data = await fetchJSON(`${OUT_SERVICE_BASE_URL}/outserviceregions`);
3162
- return data && Array.isArray(data) ? data : EMPTY_REGIONS;
3294
+ return data && Array.isArray(data) ? data : EMPTY_REGIONS$1;
3163
3295
  }
3164
3296
 
3165
3297
  const LocalitiesField = JSX(({ field, input }) => {
@@ -3292,9 +3424,11 @@
3292
3424
  const arrayToOptions = (array) => (array ?? []).map((_) => ({ key: _, value: _ }));
3293
3425
 
3294
3426
  const REGIONS_URL = `${API_BASE_URI}/regions`;
3427
+ const EMPTY_REGIONS = [];
3428
+ // TODO Почему url можно менять? Разве смысл не в инкапсуляции api url. Тоже под рефакторинг попадает
3295
3429
  function useRegions(url = REGIONS_URL) {
3296
3430
  const { data } = useAsyncData(url, fetchJSONUnsafe);
3297
- return Array.isArray(data) ? data : [];
3431
+ return Array.isArray(data) ? data : EMPTY_REGIONS;
3298
3432
  }
3299
3433
 
3300
3434
  const RegionField = JSX(({ field, input, url }) => {
@@ -6010,7 +6144,7 @@
6010
6144
  : [cellsNode, []];
6011
6145
  const [isVisible, setIsVisible] = useState(false);
6012
6146
  useEffect(() => defaultEventBus.subscribe('fold', (event) => {
6013
- if (options?.parent !== undefined && event.parent === options?.parent) {
6147
+ if (event && options?.parent !== undefined && event.parent === options?.parent) {
6014
6148
  setIsVisible(event.isUnfolded);
6015
6149
  }
6016
6150
  }), [options?.parent]);
@@ -7914,47 +8048,166 @@
7914
8048
  };
7915
8049
  const ErrorBlock = JSX(({ className = '', title, description, error, button, ...rest }) => (jsxs(BlockWrapper, { className: style('flex flex-col justify-center items-center', className), defaultPadding: style('p-6xl'), version: "transparent", ...rest, children: [jsx("div", { className: "flex justify-center", children: renderErrorContent(error) }), jsx(Headline, { title: title, description: description, headlineVersion: "XL", isEmbedded: true, className: "mb-2xl last:mb-0" }), button?.text ? (jsx(LinkButton, { version: button?.version, text: button?.text, ...button })) : null] })));
7916
8050
 
7917
- const useLatestEvent = (eventBus, type, initialEvent) => {
7918
- const [latestEvent, setLatestEvent] = useState(initialEvent || null);
7919
- useEffect(() => eventBus.subscribe(type, (_) => setLatestEvent(_)), [eventBus, type]);
7920
- const fireEvent = useCallback((_) => eventBus.fire(type, _), [eventBus, type]);
7921
- return [latestEvent, fireEvent];
7922
- };
8051
+ function copy(source, target) {
8052
+ for (const [k, v] of source.entries()) {
8053
+ if (v !== null && v !== undefined) {
8054
+ target.setItem(k, v);
8055
+ }
8056
+ else {
8057
+ target.removeItem(k);
8058
+ }
8059
+ }
8060
+ }
8061
+
8062
+ function replicate(primary, secondary) {
8063
+ copy(primary, secondary);
8064
+ copy(secondary, primary);
8065
+ return primary.bus.watch(({ type, event }) => {
8066
+ if (event !== null && event !== undefined) {
8067
+ secondary.setItem(type, event);
8068
+ }
8069
+ else {
8070
+ secondary.removeItem(type);
8071
+ }
8072
+ });
8073
+ }
8074
+
8075
+ class StorageAdapter {
8076
+ storage;
8077
+ bus;
8078
+ get size() {
8079
+ return this.storage?.length ?? 0;
8080
+ }
8081
+ constructor(storage, bus = new EventBus()) {
8082
+ this.storage = storage;
8083
+ this.bus = bus;
8084
+ }
8085
+ hasItem(key) {
8086
+ return Boolean(this.storage?.getItem(String(key)));
8087
+ }
8088
+ getItem(key) {
8089
+ const _ = this.storage?.getItem(String(key)) ?? null;
8090
+ try {
8091
+ return JSON.parse(String(_));
8092
+ }
8093
+ catch (ex) {
8094
+ return null;
8095
+ }
8096
+ }
8097
+ entries() {
8098
+ return Array.from({ length: this.size }, (_, i) => {
8099
+ const k = String(this.storage?.key(i));
8100
+ return [k, this.getItem(k)];
8101
+ });
8102
+ }
8103
+ setItem(key, value) {
8104
+ if (value !== null) {
8105
+ this.storage?.setItem(String(key), JSON.stringify(value));
8106
+ }
8107
+ else {
8108
+ this.storage?.removeItem(String(key));
8109
+ }
8110
+ this.bus?.subject(key, value);
8111
+ }
8112
+ removeItem(key) {
8113
+ this.storage?.removeItem(String(key));
8114
+ this.bus?.subject(key, null);
8115
+ }
8116
+ }
8117
+
8118
+ class Store {
8119
+ bus;
8120
+ store = new Map();
8121
+ get size() {
8122
+ return this.store.size;
8123
+ }
8124
+ constructor(bus = new EventBus()) {
8125
+ this.bus = bus;
8126
+ }
8127
+ hasItem(key) {
8128
+ return this.store.has(key);
8129
+ }
8130
+ getItem(key) {
8131
+ return this.store.get(key);
8132
+ }
8133
+ entries() {
8134
+ return this.store.entries();
8135
+ }
8136
+ setItem(key, value) {
8137
+ this.store.set(key, value);
8138
+ this.bus.subject(key, value);
8139
+ }
8140
+ removeItem(key) {
8141
+ this.store.delete(key);
8142
+ this.bus.subject(key, null);
8143
+ }
8144
+ }
8145
+
8146
+ function useRerender() {
8147
+ const [, setCount] = useState(0);
8148
+ return useCallback(() => setCount(_ => (_ + 1) % (1 << 16)), []);
8149
+ }
8150
+
8151
+ const DEFAULT_METHODS = {};
8152
+ /**
8153
+ * MobX like reactivity (simplified).
8154
+ * Can be used to migrate from Redux/MobX or something else
8155
+ *
8156
+ * @param store
8157
+ * @returns reactive proxy backed by store
8158
+ */
8159
+ function useStore(store, methods = DEFAULT_METHODS) {
8160
+ const deps = useRef(null);
8161
+ const render = useRerender();
8162
+ useEffect(() => store.bus.watch(ev => {
8163
+ if (deps.current?.has(String(ev.type))) {
8164
+ render();
8165
+ }
8166
+ }), [store, render]);
8167
+ return useMemo(() => new Proxy(methods, {
8168
+ get(_, key) {
8169
+ deps.current ||= new Set();
8170
+ deps.current.add(key);
8171
+ return store.getItem(key);
8172
+ },
8173
+ has(_, key) {
8174
+ deps.current ||= new Set();
8175
+ deps.current.add(key);
8176
+ return store.hasItem(key);
8177
+ },
8178
+ set(_, key, value) {
8179
+ store.setItem(key, value);
8180
+ return true;
8181
+ },
8182
+ deleteProperty(_, key) {
8183
+ store.removeItem(key);
8184
+ return true;
8185
+ }
8186
+ }), [store]);
8187
+ }
8188
+
8189
+ const localStore = new Store(); // localStorage cache
8190
+ replicate(localStore, new StorageAdapter(globalThis?.localStorage));
8191
+ function useLocalStore(methods) {
8192
+ return useStore(localStore, methods);
8193
+ }
7923
8194
 
7924
8195
  const REGION_URL = `${API_BASE_URI}/region`;
7925
- const LOCATION_STORAGE_KEY = 'location';
7926
8196
  function useLocation(defaultLocation = 'Москва') {
7927
- const [currentLocation, fireCurrentLocation] = useLatestEvent(defaultEventBus, 'location', restoreLocation() ?? { name: defaultLocation });
7928
- const selectCurrentLocation = useCallback((_) => {
7929
- storeLocation(_);
7930
- fireCurrentLocation(_);
7931
- }, []);
7932
- const { data } = useAsyncData(hasStoredLocation() ? null : REGION_URL, fetchJSONUnsafe);
7933
- useEffect(() => {
7934
- if (data && !hasStoredLocation()) {
7935
- fireCurrentLocation(data);
7936
- }
7937
- }, [data]);
7938
- return [currentLocation ?? { name: defaultLocation }, selectCurrentLocation];
8197
+ const locationStore = useLocalStore();
8198
+ return locationStore.location ?? { name: defaultLocation };
8199
+ }
8200
+ function useDefaultLocation(defaultLocation = 'Москва') {
8201
+ const locationStore = useLocalStore();
8202
+ const preselectLocation = useCallback(async () => {
8203
+ if (!locationStore.location) {
8204
+ const region = await fetchJSON(REGION_URL);
8205
+ locationStore.location = region ?? { name: defaultLocation };
8206
+ }
8207
+ }, [locationStore, defaultLocation]);
8208
+ useAsyncData(REGION_URL, preselectLocation);
8209
+ return locationStore;
7939
8210
  }
7940
- const hasStoredLocation = () => Boolean(globalThis.localStorage?.getItem(LOCATION_STORAGE_KEY));
7941
- const restoreLocation = () => {
7942
- try {
7943
- const data = globalThis.localStorage?.getItem(LOCATION_STORAGE_KEY);
7944
- return data && JSON.parse(data);
7945
- }
7946
- catch (ex) {
7947
- return null;
7948
- }
7949
- };
7950
- const storeLocation = (_) => {
7951
- try {
7952
- globalThis.localStorage?.setItem(LOCATION_STORAGE_KEY, JSON.stringify(_));
7953
- }
7954
- catch (ex) {
7955
- // Do nothing
7956
- }
7957
- };
7958
8211
 
7959
8212
  var Currency;
7960
8213
  (function (Currency) {
@@ -8096,7 +8349,7 @@
8096
8349
  }
8097
8350
 
8098
8351
  const ExchangeRateTile = JSX(({ className = '', title = 'Курсы обмена валют', button, ...rest }) => {
8099
- const [currentLocation] = useLocation();
8352
+ const currentLocation = useLocation();
8100
8353
  const exchangeRates = useFetchExchangeRateData(currentLocation);
8101
8354
  const currencyRates = getCurrencyRates(exchangeRates?.exchangeRate?.currencies);
8102
8355
  const currencyRatesBuy = currencyRates.filter((_) => _.buyExchangeRate);
@@ -8583,7 +8836,7 @@
8583
8836
  designDisabledPeople: (item) => Boolean(item.designDisabledPeople),
8584
8837
  };
8585
8838
  const AtmsMap = JSX(({ descriptionData, className }) => {
8586
- const [currentLocation] = useLocation();
8839
+ const currentLocation = useLocation();
8587
8840
  const regionCode = currentLocation?.code ?? '000';
8588
8841
  const { data: officesData, isLoad } = useAtms(regionCode);
8589
8842
  return (jsx(OfficesAtmsMapLayout, { className: className, filterItems: filterItems, data: officesData, isLoad: isLoad, initFilterState: INITIAL_FILTRATION_STATE, renderCard: renderAtmCard, getBalloon: getAtmPoint, title: `Банкоматы филиала ${currentLocation?.name}`, descriptionData: descriptionData }));
@@ -8636,7 +8889,7 @@
8636
8889
  };
8637
8890
 
8638
8891
  const OfficesMap = JSX(({ className }) => {
8639
- const [currentLocation] = useLocation();
8892
+ const currentLocation = useLocation();
8640
8893
  const regionCode = currentLocation?.code ?? '000';
8641
8894
  const { data, isLoad } = useOffices(regionCode);
8642
8895
  return (jsx(OfficesAtmsMapLayout, { className: className, data: data?.branches, isLoad: isLoad, remoteWorkplaces: data?.remoteWorkplaces, renderCard: renderOfficeCard, renderRemoteWorkplaceCard: renderRemoteWorkplaceCard, getBalloon: getOfficePoint, getBalloonRemoteWorkplaces: getRemoteWorkplacePoint, title: `Офисы филиала ${currentLocation?.name}` }));
@@ -8885,6 +9138,9 @@
8885
9138
  pop();
8886
9139
  }, [dialogs, onClose]);
8887
9140
  useEffect(() => defaultEventBus.subscribe('dialog', (action) => {
9141
+ if (!action) {
9142
+ return;
9143
+ }
8888
9144
  switch (action.type) {
8889
9145
  case 'open':
8890
9146
  push(action);
@@ -8993,27 +9249,33 @@
8993
9249
  return (jsxs("form", { className: `font-sans relative ${className}`, children: [jsx("div", { className: "absolute rounded h-full flex items-center justify-center pl-m max-w-44 gap-s pointer-events-none", children: searchTerm ? null : (jsx("label", { htmlFor: "search-bar-input", className: `text-secondary-text `, children: "\u041F\u043E\u0438\u0441\u043A \u043F\u043E \u0444\u0438\u043B\u0438\u0430\u043B\u0430\u043C" })) }), jsx("input", { id: "search-bar-input", className: style(inputValidStyle, `h-12 pl-m w-full peer text-l text-black rounded-md box-border`), value: searchTerm, onChange: (e) => onSearch(e.target.value.toLowerCase()), type: "text", name: "location-search-bar-input" })] }));
8994
9250
  });
8995
9251
 
8996
- const SEARCH_TERM_MIN_LENGTH = 3;
8997
- const LocationDialog = JSX(({ foreignOffices, branches }) => {
8998
- const [currentLocation, selectCurrentLocation] = useLocation(branches?.default);
9252
+ const SelectedLocation = JSX(({ defaultLocation }) => {
9253
+ const currentLocation = useLocation(defaultLocation);
8999
9254
  const link = useLink();
9000
9255
  const { href } = link({ href: `/branches/${currentLocation.slug}` });
9256
+ return currentLocation ? (jsx("div", { className: "mb-s", children: jsxs(Paragraph, { size: "text-l", color: "text-primary-text", children: ["\u0421\u0435\u0439\u0447\u0430\u0441 \u0432\u044B\u0431\u0440\u0430\u043D:", jsx(LinkWrapper, { href: href, className: "inline mx-2xs text-primary-main", children: currentLocation.name })] }) })) : null;
9257
+ });
9258
+
9259
+ const SEARCH_TERM_MIN_LENGTH = 3;
9260
+ const LocationDialog = JSX(({ foreignOffices, branches }) => {
9261
+ const locationStore = useDefaultLocation(branches?.default);
9001
9262
  const [query, setQuery] = useState('');
9002
- const regions = cleanUpRegions(useRegions()).sort((a, b) => a.name.localeCompare(b.name));
9003
- const regionsGroupByLetter = groupBy(regions, regionFirstLetter);
9263
+ const rawRegions = useRegions();
9264
+ const regions = useMemo(() => cleanUpRegions(rawRegions).sort((a, b) => a.name.localeCompare(b.name)), [rawRegions]);
9265
+ const regionsGroupByLetter = useMemo(() => groupBy(regions, regionFirstLetter), [regions]);
9004
9266
  const { close } = useDialogManager();
9005
- const handleChangeLocation = useCallback((region) => {
9006
- selectCurrentLocation(region);
9267
+ const handleChangeLocation = useCallback((_) => {
9268
+ locationStore.location = _;
9007
9269
  close();
9008
- }, []);
9009
- return (jsxs(Dialog, { className: "pb-20", head: jsxs("div", { children: [jsx(Text, { size: "text-h4", color: "text-primary-text", children: "\u0412\u044B\u0431\u0435\u0440\u0438\u0442\u0435 \u0444\u0438\u043B\u0438\u0430\u043B" }), currentLocation ? (jsx("div", { className: "mb-s", children: jsxs(Paragraph, { size: "text-l", color: "text-primary-text", children: ["\u0421\u0435\u0439\u0447\u0430\u0441 \u0432\u044B\u0431\u0440\u0430\u043D:", jsx(LinkWrapper, { href: href, className: "inline mx-2xs text-primary-main", children: currentLocation.name })] }) })) : null, jsx(SearchBar, { onSearch: setQuery, searchTerm: query })] }), children: [query && query.length >= SEARCH_TERM_MIN_LENGTH ? (jsx("div", { children: regions
9270
+ }, [locationStore]);
9271
+ return (jsxs(Dialog, { className: "pb-20", head: jsxs("div", { children: [jsx(Text, { size: "text-h4", color: "text-primary-text", children: "\u0412\u044B\u0431\u0435\u0440\u0438\u0442\u0435 \u0444\u0438\u043B\u0438\u0430\u043B" }), jsx(SelectedLocation, { defaultLocation: branches?.default }), jsx(SearchBar, { onSearch: setQuery, searchTerm: query })] }), children: [query && query.length >= SEARCH_TERM_MIN_LENGTH ? (jsx("div", { children: regions
9010
9272
  .filter(({ name }) => name && jaroWinklerDistance(name.toLowerCase())(query.toLowerCase()) >= 0.8)
9011
9273
  .map(renderRegion(branches?.dataSelect, handleChangeLocation)) })) : (jsx("div", { className: "columns-1 sm:columns-3 md:columns-4 lg:columns-5", children: Array.from(regionsGroupByLetter.entries()).map(renderRegionGroup(handleChangeLocation, branches?.dataSelect)) })), renderForeignOffices(foreignOffices)] }));
9012
9274
  });
9013
- const regionFirstLetter = (region) => region.name?.charAt(0) || '';
9275
+ const regionFirstLetter = (region) => region.name?.charAt(0) ?? '';
9014
9276
  const cleanUpRegions = (regions) => regions.map((region) => ({
9015
9277
  ...region,
9016
- name: region.name?.replace(/республика|область|край'/gi, '').trim() || '',
9278
+ name: region.name?.replace(/республика|область|край'/gi, '').trim() ?? '',
9017
9279
  }));
9018
9280
 
9019
9281
  const useLocationDialog = (props) => {
@@ -9026,7 +9288,7 @@
9026
9288
 
9027
9289
  const BurgerMenuDialog = JSX(({ menuRef, menuItem, locationDialogProps, closeAll }) => {
9028
9290
  const locationDialog = useLocationDialog(locationDialogProps || {});
9029
- const [{ name: location }] = useLocation();
9291
+ const { name: location } = useLocation();
9030
9292
  const menuDimensions = menuRef?.current?.getBoundingClientRect();
9031
9293
  const basePath = getBasePath(env.SITE_URL);
9032
9294
  const handleIframeLoad = () => {
@@ -9589,6 +9851,9 @@
9589
9851
  setPopup(null);
9590
9852
  }, []);
9591
9853
  useEffect(() => defaultEventBus.subscribe('popup', (action) => {
9854
+ if (!action) {
9855
+ return;
9856
+ }
9592
9857
  switch (action.type) {
9593
9858
  case 'open':
9594
9859
  case 'update':
@@ -9622,6 +9887,7 @@
9622
9887
  const { slots, blocks, fallback, ...pageContent } = data;
9623
9888
  const resolvedPageContent = useJSONRef(pageContent, fallback);
9624
9889
  useClickHandler();
9890
+ useDefaultLocation();
9625
9891
  const options = {
9626
9892
  key: '',
9627
9893
  page: { slots, blocks, fallback, ...resolvedPageContent },
@@ -9643,7 +9909,7 @@
9643
9909
  slots: () => [HEADER_SLOT, FOOTER_SLOT, STICKY_FOOTER_SLOT],
9644
9910
  });
9645
9911
 
9646
- const packageVersion = "0.14.674";
9912
+ const packageVersion = "0.14.675";
9647
9913
 
9648
9914
  exports.Blocks = Blocks;
9649
9915
  exports.ContentPage = ContentPage;