@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
@@ -406,32 +406,53 @@
406
406
  className,
407
407
  ].join(' ');
408
408
 
409
- class EventBus {
410
- subscribers = {};
411
- subjectsStateMap = {};
412
- subscribe(type, listener) {
413
- this.subscribers[type] = (this.subscribers[type] || []).concat(listener);
414
- const latestEvent = this.subjectsStateMap[type];
415
- if (latestEvent) {
416
- listener(latestEvent);
417
- }
418
- return () => {
419
- this.unsubscribe(type, listener);
420
- };
421
- }
422
- unsubscribe(type, listener) {
423
- this.subscribers[type] = this.subscribers[type]?.filter((s) => s !== listener);
424
- }
425
- fire(type, event) {
426
- const isSubjectDeclared = type in this.subjectsStateMap;
427
- if (isSubjectDeclared) {
428
- this.subjectsStateMap[type] = event;
429
- }
430
- this.subscribers[type]?.forEach((s) => s(event));
431
- }
432
- subject(type, event) {
433
- this.subjectsStateMap[type] = event;
434
- }
409
+ class EventBus {
410
+ watchers = new Set();
411
+ subscribersMap = {};
412
+ subjectsStateMap = {};
413
+ emitter = this;
414
+ observable = this;
415
+ watch(watcher) {
416
+ this.watchers.add(watcher);
417
+ return () => {
418
+ this.watchers.delete(watcher);
419
+ };
420
+ }
421
+ subscribe(type, listener) {
422
+ this.subscribersMap[type] ||= new Set();
423
+ this.subscribersMap[type]?.add(listener);
424
+ const initialEvent = this.subjectsStateMap[type];
425
+ initialEvent && listener(initialEvent);
426
+ return () => {
427
+ this.subscribersMap[type]?.delete(listener);
428
+ };
429
+ }
430
+ fire(type, event) {
431
+ const isSubjectDeclared = type in this.subjectsStateMap;
432
+ if (isSubjectDeclared) {
433
+ this.subject(type, event);
434
+ }
435
+ else {
436
+ this.fireSubscribers(type, event);
437
+ }
438
+ }
439
+ subject(type, event) {
440
+ if (this.subjectsStateMap[type] !== event) {
441
+ this.subjectsStateMap[type] = event ?? undefined;
442
+ this.fireSubscribers(type, event);
443
+ }
444
+ return () => {
445
+ delete this.subjectsStateMap[type];
446
+ };
447
+ }
448
+ fireSubscribers(type, event) {
449
+ for (const _ of this.subscribersMap[type] ?? []) {
450
+ _(event ?? null);
451
+ }
452
+ for (const _ of this.watchers) {
453
+ _({ type, event: event ?? null });
454
+ }
455
+ }
435
456
  }
436
457
 
437
458
  const defaultEventBus = new EventBus();
@@ -717,26 +738,166 @@
717
738
  const leftOrRightImage = (img, directionRight) => directionRight ? { rightImage: img } : { leftImage: img };
718
739
  const renderTags = (tags) => (tags?.length ? jsx(Tags, { tags: tags }) : null);
719
740
 
741
+ class JSONBox {
742
+ _;
743
+ constructor(_) {
744
+ this._ = _;
745
+ }
746
+ of(_) {
747
+ return new this.constructor(_ instanceof JSONBox ? _._ : _);
748
+ }
749
+ filter(predicate) {
750
+ return this.from(this.entries().filter(predicate));
751
+ }
752
+ map(mapper) {
753
+ return this.from(this.entries().map(mapper));
754
+ }
755
+ flatMap(mapper) {
756
+ return this.from(this.entries().flatMap(mapper));
757
+ }
758
+ reduce(reducer, initial) {
759
+ return this.entries().reduce(reducer.bind(this), initial);
760
+ }
761
+ }
762
+
763
+ const trueF = () => true;
764
+ const and = (a, b) => (...args) => a(...args) && b(...args);
765
+
766
+ const table = (...table) => (...input) => {
767
+ const [, unit] = assertNonEmpty$1(table.find(([predicate]) => predicate(...input)));
768
+ return unit(...input);
769
+ };
770
+ function assertNonEmpty$1(value) {
771
+ if (!value) {
772
+ throw new Error('Value should be fulfilled');
773
+ }
774
+ return value;
775
+ }
776
+
720
777
  const isJSONArray = (_) => Boolean(_ && Array.isArray(_));
721
- const isJSONRecord = (_) => Boolean(_ && !Array.isArray(_) && typeof _ === 'object');
722
- const isJSONRef = (_) => Boolean(isJSONRecord(_) && typeof _.$ref === 'string');
778
+ const isJSONRecord = (_) => Boolean(_ && typeof _ === 'object' && !isJSONArray(_));
723
779
 
724
- const mapJSONNode = (json, handlers) => {
725
- if (isJSONRef(json)) {
726
- return handlers.ref(json);
780
+ const identity$1 = (x) => x;
781
+
782
+ const t0 = (fn = identity$1) => ([_]) => fn(_);
783
+ const t1 = (fn = identity$1) => ([, _]) => fn(_);
784
+
785
+ function unbox(box) {
786
+ return box instanceof JSONBox ? box._ : box;
787
+ }
788
+
789
+ class JSONArrayBox extends JSONBox {
790
+ from(entries) {
791
+ return this.of(entries.map(t1(unbox)));
727
792
  }
728
- else if (isJSONRecord(json)) {
729
- return handlers.record(json);
793
+ entries() {
794
+ return (this._ ?? []).map((node, p) => [p, this.of(node)]);
730
795
  }
731
- else if (isJSONArray(json)) {
732
- return handlers.array(json);
796
+ size() {
797
+ return this._?.length ?? 0;
733
798
  }
734
- else {
735
- return handlers.scalar ? handlers.scalar(json) : json;
799
+ get(p) {
800
+ return this.of(typeof p === 'number' ? this._?.[p] : undefined);
801
+ }
802
+ set(p, child) {
803
+ return this.of(isJSONArray(this._)
804
+ ? Array.from({ length: Math.max(this._.length, Number(p) + 1) }, (x, i) => (i === p ? child : this._[i]))
805
+ : Array.from({ length: Number(p) + 1 }, (x, i) => (i === p ? child : undefined)));
806
+ }
807
+ }
808
+
809
+ class JSONLeafBox extends JSONBox {
810
+ from() {
811
+ return this;
812
+ }
813
+ entries() {
814
+ return [];
815
+ }
816
+ size() {
817
+ return 0;
818
+ }
819
+ get(p) {
820
+ return this.of(p !== undefined ? undefined /* no childs */ : this._ /* self */);
821
+ }
822
+ set(p, child) {
823
+ return this.of(child);
824
+ }
825
+ }
826
+
827
+ class JSONRecordBox extends JSONBox {
828
+ from(entries) {
829
+ return this.of(Object.fromEntries(entries.map(([p, box]) => [p, unbox(box)])));
830
+ }
831
+ entries() {
832
+ return Object.entries(this._ ?? {}).map(([p, node]) => [p, this.of(node)]);
833
+ }
834
+ size() {
835
+ return Object.keys(this._ ?? {}).length;
836
+ }
837
+ get(p) {
838
+ return this.of(typeof p === 'string' ? this._?.[p] : undefined);
736
839
  }
840
+ set(p, child) {
841
+ return this.of({ ...this._, [p]: child });
842
+ }
843
+ }
844
+
845
+ class JSONBoxDefault extends JSONBox {
846
+ proto = table([p => isJSONArray(this._) || typeof p === 'number', () => JSONArrayBox.prototype], [p => isJSONRecord(this._) || typeof p === 'string', () => JSONRecordBox.prototype], [trueF, () => JSONLeafBox.prototype]);
847
+ from(entries) {
848
+ return this.proto(undefined).from.call(this, entries);
849
+ }
850
+ entries() {
851
+ return this.proto(undefined).entries.call(this);
852
+ }
853
+ size() {
854
+ return this.proto(undefined).size.call(this);
855
+ }
856
+ get(p) {
857
+ return this.proto(p).get.call(this, p);
858
+ }
859
+ set(p, child) {
860
+ return this.proto(p).set.call(this, p, child);
861
+ }
862
+ }
863
+
864
+ const box = (_) => (_ instanceof JSONBox ? _ : new JSONBoxDefault(_));
865
+
866
+ const boxed = (fn) => {
867
+ const boxedFn = (node, ...args) => unbox(fn(box(node), ...args));
868
+ boxedFn.fn = fn;
869
+ return boxedFn;
737
870
  };
738
871
 
739
- const mergeRecords = (entries) => entries.reduce((acc, _) => Object.assign(acc, _), {});
872
+ const ROOT = [];
873
+ const endsWith = (suffix) => suffix
874
+ .map((predicate, i) => (path) => cmp(predicate)(path[i + path.length - suffix.length]))
875
+ .reduceRight(and, trueF);
876
+ const cmp = (a) => a instanceof Function ? a : (b) => a === b;
877
+
878
+ const reduce = (reducer) => (node, initial, path = ROOT) => box(node)
879
+ .entries()
880
+ .reduce((acc, [p, _]) => reduce(reducer)(_, acc, path.concat(p)), reducer(initial, [path, box(node)]));
881
+
882
+ const set = boxed((target, [path, node]) => {
883
+ const [p, ...tail] = path;
884
+ return target.set(p, tail.length ? set(target.get(p), [tail, node]) : node);
885
+ });
886
+
887
+ const fromEntries = boxed((initial, tree) => tree.reduce(set.fn, initial));
888
+
889
+ const leafs = (node) => reduce((acc, [path, _]) => (isLeaf(_) ? [...acc, [path, unbox(_)]] : acc))(node, []);
890
+ const isLeaf = (_) => _.size() === 0;
891
+
892
+ const map = (mapper, initial = {}) => (node) => fromEntries(initial, leafs(node).map(_ => mapper(_)));
893
+
894
+ const init = (list) => list.slice(0, -1);
895
+
896
+ boxed((target, path = ROOT) => path.reduce((_, p) => _.get(p), target));
897
+
898
+ const remove = boxed((target, [p, ...tail]) => tail.length ? target.set(p, remove(target.get(p), tail)) : target.filter(([i]) => i !== p));
899
+
900
+ const isJSONRefPath = endsWith(['$ref']);
740
901
 
741
902
  const parseJPointer = (uri) => uri.includes('#')
742
903
  ? uri
@@ -746,46 +907,17 @@
746
907
  : [];
747
908
 
748
909
  const resolveJPointer = (json, uri) => parseJPointer(uri).reduce(selectNodeByKey, json);
749
- const selectNodeByKey = (json, key) => {
750
- if (!json || !key) {
751
- return json;
752
- }
753
- if (isJSONRecord(json)) {
754
- return json[key];
755
- }
756
- else if (isJSONArray(json)) {
757
- return json[parseInt(key, 10)];
758
- }
759
- else {
760
- return json;
761
- }
762
- };
910
+ const selectNodeByKey = table([isJSONArray, (json, key) => json[parseInt(key, 10)]], [isJSONRecord, (json, key) => json[key]], [trueF, identity$1]);
763
911
 
764
- const resolveRef = (json, resolver) => mapJSONNode(json, {
765
- ref: ({ $ref, ...rest }) => resolveRef($ref ? resolveJPointer(resolver($ref), $ref) : rest, resolver),
766
- record: record => mergeRecords(Object.entries(record).map(([key, value]) => ({ [key]: resolveRef(value, resolver) }))),
767
- array: list => list.map(_ => resolveRef(_, resolver))
768
- });
912
+ const resolveRef = (json, resolver) => map(([path, node]) => isJSONRefPath(path)
913
+ ? [init(path), resolveJPointer(resolver(node), node)]
914
+ : [path, node])(json);
769
915
 
770
- const visitRef = (json, visitor, path = []) => {
771
- mapJSONNode(json, {
772
- ref: json => visitor(json.$ref, path),
773
- record: record => {
774
- for (const key in record)
775
- visitRef(record[key], visitor, [...path, key]);
776
- },
777
- array: list => {
778
- for (let i = 0; i < list.length; i++)
779
- visitRef(list[i], visitor, [...path, i]);
780
- }
781
- });
782
- };
916
+ const refEntries = (json) => leafs(json).filter(t0(isJSONRefPath));
783
917
 
784
- const collectRef = (json) => {
785
- const refs = [];
786
- visitRef(json, _ => refs.push(_));
787
- return refs;
788
- };
918
+ const unique$1 = (list) => [...new Set(list)];
919
+
920
+ const collectRef = (json) => unique$1(refEntries(json).map(([, _]) => _));
789
921
 
790
922
  async function fetchJSON(url, options) {
791
923
  try {
@@ -3148,10 +3280,10 @@
3148
3280
  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 })));
3149
3281
 
3150
3282
  const OUT_SERVICE_BASE_URL = `${API_BASE_URI}/outservice`;
3151
- const EMPTY_REGIONS = [];
3283
+ const EMPTY_REGIONS$1 = [];
3152
3284
  async function getOutServiceRegions() {
3153
3285
  const data = await fetchJSON(`${OUT_SERVICE_BASE_URL}/outserviceregions`);
3154
- return data && Array.isArray(data) ? data : EMPTY_REGIONS;
3286
+ return data && Array.isArray(data) ? data : EMPTY_REGIONS$1;
3155
3287
  }
3156
3288
 
3157
3289
  const LocalitiesField = JSX(({ field, input }) => {
@@ -3284,9 +3416,11 @@
3284
3416
  const arrayToOptions = (array) => (array ?? []).map((_) => ({ key: _, value: _ }));
3285
3417
 
3286
3418
  const REGIONS_URL = `${API_BASE_URI}/regions`;
3419
+ const EMPTY_REGIONS = [];
3420
+ // TODO Почему url можно менять? Разве смысл не в инкапсуляции api url. Тоже под рефакторинг попадает
3287
3421
  function useRegions(url = REGIONS_URL) {
3288
3422
  const { data } = useAsyncData(url, fetchJSONUnsafe);
3289
- return Array.isArray(data) ? data : [];
3423
+ return Array.isArray(data) ? data : EMPTY_REGIONS;
3290
3424
  }
3291
3425
 
3292
3426
  const RegionField = JSX(({ field, input, url }) => {
@@ -6042,7 +6176,7 @@
6042
6176
  : [cellsNode, []];
6043
6177
  const [isVisible, setIsVisible] = useState(false);
6044
6178
  useEffect(() => defaultEventBus.subscribe('fold', (event) => {
6045
- if (options?.parent !== undefined && event.parent === options?.parent) {
6179
+ if (event && options?.parent !== undefined && event.parent === options?.parent) {
6046
6180
  setIsVisible(event.isUnfolded);
6047
6181
  }
6048
6182
  }), [options?.parent]);
@@ -7935,47 +8069,166 @@
7935
8069
  };
7936
8070
  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] })));
7937
8071
 
7938
- const useLatestEvent = (eventBus, type, initialEvent) => {
7939
- const [latestEvent, setLatestEvent] = useState(initialEvent || null);
7940
- useEffect(() => eventBus.subscribe(type, (_) => setLatestEvent(_)), [eventBus, type]);
7941
- const fireEvent = useCallback((_) => eventBus.fire(type, _), [eventBus, type]);
7942
- return [latestEvent, fireEvent];
7943
- };
8072
+ function copy(source, target) {
8073
+ for (const [k, v] of source.entries()) {
8074
+ if (v !== null && v !== undefined) {
8075
+ target.setItem(k, v);
8076
+ }
8077
+ else {
8078
+ target.removeItem(k);
8079
+ }
8080
+ }
8081
+ }
8082
+
8083
+ function replicate(primary, secondary) {
8084
+ copy(primary, secondary);
8085
+ copy(secondary, primary);
8086
+ return primary.bus.watch(({ type, event }) => {
8087
+ if (event !== null && event !== undefined) {
8088
+ secondary.setItem(type, event);
8089
+ }
8090
+ else {
8091
+ secondary.removeItem(type);
8092
+ }
8093
+ });
8094
+ }
8095
+
8096
+ class StorageAdapter {
8097
+ storage;
8098
+ bus;
8099
+ get size() {
8100
+ return this.storage?.length ?? 0;
8101
+ }
8102
+ constructor(storage, bus = new EventBus()) {
8103
+ this.storage = storage;
8104
+ this.bus = bus;
8105
+ }
8106
+ hasItem(key) {
8107
+ return Boolean(this.storage?.getItem(String(key)));
8108
+ }
8109
+ getItem(key) {
8110
+ const _ = this.storage?.getItem(String(key)) ?? null;
8111
+ try {
8112
+ return JSON.parse(String(_));
8113
+ }
8114
+ catch (ex) {
8115
+ return null;
8116
+ }
8117
+ }
8118
+ entries() {
8119
+ return Array.from({ length: this.size }, (_, i) => {
8120
+ const k = String(this.storage?.key(i));
8121
+ return [k, this.getItem(k)];
8122
+ });
8123
+ }
8124
+ setItem(key, value) {
8125
+ if (value !== null) {
8126
+ this.storage?.setItem(String(key), JSON.stringify(value));
8127
+ }
8128
+ else {
8129
+ this.storage?.removeItem(String(key));
8130
+ }
8131
+ this.bus?.subject(key, value);
8132
+ }
8133
+ removeItem(key) {
8134
+ this.storage?.removeItem(String(key));
8135
+ this.bus?.subject(key, null);
8136
+ }
8137
+ }
8138
+
8139
+ class Store {
8140
+ bus;
8141
+ store = new Map();
8142
+ get size() {
8143
+ return this.store.size;
8144
+ }
8145
+ constructor(bus = new EventBus()) {
8146
+ this.bus = bus;
8147
+ }
8148
+ hasItem(key) {
8149
+ return this.store.has(key);
8150
+ }
8151
+ getItem(key) {
8152
+ return this.store.get(key);
8153
+ }
8154
+ entries() {
8155
+ return this.store.entries();
8156
+ }
8157
+ setItem(key, value) {
8158
+ this.store.set(key, value);
8159
+ this.bus.subject(key, value);
8160
+ }
8161
+ removeItem(key) {
8162
+ this.store.delete(key);
8163
+ this.bus.subject(key, null);
8164
+ }
8165
+ }
8166
+
8167
+ function useRerender() {
8168
+ const [, setCount] = useState(0);
8169
+ return useCallback(() => setCount(_ => (_ + 1) % (1 << 16)), []);
8170
+ }
8171
+
8172
+ const DEFAULT_METHODS = {};
8173
+ /**
8174
+ * MobX like reactivity (simplified).
8175
+ * Can be used to migrate from Redux/MobX or something else
8176
+ *
8177
+ * @param store
8178
+ * @returns reactive proxy backed by store
8179
+ */
8180
+ function useStore(store, methods = DEFAULT_METHODS) {
8181
+ const deps = useRef(null);
8182
+ const render = useRerender();
8183
+ useEffect(() => store.bus.watch(ev => {
8184
+ if (deps.current?.has(String(ev.type))) {
8185
+ render();
8186
+ }
8187
+ }), [store, render]);
8188
+ return useMemo(() => new Proxy(methods, {
8189
+ get(_, key) {
8190
+ deps.current ||= new Set();
8191
+ deps.current.add(key);
8192
+ return store.getItem(key);
8193
+ },
8194
+ has(_, key) {
8195
+ deps.current ||= new Set();
8196
+ deps.current.add(key);
8197
+ return store.hasItem(key);
8198
+ },
8199
+ set(_, key, value) {
8200
+ store.setItem(key, value);
8201
+ return true;
8202
+ },
8203
+ deleteProperty(_, key) {
8204
+ store.removeItem(key);
8205
+ return true;
8206
+ }
8207
+ }), [store]);
8208
+ }
8209
+
8210
+ const localStore = new Store(); // localStorage cache
8211
+ replicate(localStore, new StorageAdapter(globalThis?.localStorage));
8212
+ function useLocalStore(methods) {
8213
+ return useStore(localStore, methods);
8214
+ }
7944
8215
 
7945
8216
  const REGION_URL = `${API_BASE_URI}/region`;
7946
- const LOCATION_STORAGE_KEY = 'location';
7947
8217
  function useLocation(defaultLocation = 'Москва') {
7948
- const [currentLocation, fireCurrentLocation] = useLatestEvent(defaultEventBus, 'location', restoreLocation() ?? { name: defaultLocation });
7949
- const selectCurrentLocation = useCallback((_) => {
7950
- storeLocation(_);
7951
- fireCurrentLocation(_);
7952
- }, []);
7953
- const { data } = useAsyncData(hasStoredLocation() ? null : REGION_URL, fetchJSONUnsafe);
7954
- useEffect(() => {
7955
- if (data && !hasStoredLocation()) {
7956
- fireCurrentLocation(data);
7957
- }
7958
- }, [data]);
7959
- return [currentLocation ?? { name: defaultLocation }, selectCurrentLocation];
8218
+ const locationStore = useLocalStore();
8219
+ return locationStore.location ?? { name: defaultLocation };
8220
+ }
8221
+ function useDefaultLocation(defaultLocation = 'Москва') {
8222
+ const locationStore = useLocalStore();
8223
+ const preselectLocation = useCallback(async () => {
8224
+ if (!locationStore.location) {
8225
+ const region = await fetchJSON(REGION_URL);
8226
+ locationStore.location = region ?? { name: defaultLocation };
8227
+ }
8228
+ }, [locationStore, defaultLocation]);
8229
+ useAsyncData(REGION_URL, preselectLocation);
8230
+ return locationStore;
7960
8231
  }
7961
- const hasStoredLocation = () => Boolean(globalThis.localStorage?.getItem(LOCATION_STORAGE_KEY));
7962
- const restoreLocation = () => {
7963
- try {
7964
- const data = globalThis.localStorage?.getItem(LOCATION_STORAGE_KEY);
7965
- return data && JSON.parse(data);
7966
- }
7967
- catch (ex) {
7968
- return null;
7969
- }
7970
- };
7971
- const storeLocation = (_) => {
7972
- try {
7973
- globalThis.localStorage?.setItem(LOCATION_STORAGE_KEY, JSON.stringify(_));
7974
- }
7975
- catch (ex) {
7976
- // Do nothing
7977
- }
7978
- };
7979
8232
 
7980
8233
  var Currency;
7981
8234
  (function (Currency) {
@@ -8117,7 +8370,7 @@
8117
8370
  }
8118
8371
 
8119
8372
  const ExchangeRateTile = JSX(({ className = '', title = 'Курсы обмена валют', button, ...rest }) => {
8120
- const [currentLocation] = useLocation();
8373
+ const currentLocation = useLocation();
8121
8374
  const exchangeRates = useFetchExchangeRateData(currentLocation);
8122
8375
  const currencyRates = getCurrencyRates(exchangeRates?.exchangeRate?.currencies);
8123
8376
  const currencyRatesBuy = currencyRates.filter((_) => _.buyExchangeRate);
@@ -8597,27 +8850,33 @@
8597
8850
  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" })] }));
8598
8851
  });
8599
8852
 
8600
- const SEARCH_TERM_MIN_LENGTH = 3;
8601
- const LocationDialog = JSX(({ foreignOffices, branches }) => {
8602
- const [currentLocation, selectCurrentLocation] = useLocation(branches?.default);
8853
+ const SelectedLocation = JSX(({ defaultLocation }) => {
8854
+ const currentLocation = useLocation(defaultLocation);
8603
8855
  const link = useLink();
8604
8856
  const { href } = link({ href: `/branches/${currentLocation.slug}` });
8857
+ 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;
8858
+ });
8859
+
8860
+ const SEARCH_TERM_MIN_LENGTH = 3;
8861
+ const LocationDialog = JSX(({ foreignOffices, branches }) => {
8862
+ const locationStore = useDefaultLocation(branches?.default);
8605
8863
  const [query, setQuery] = useState('');
8606
- const regions = cleanUpRegions(useRegions()).sort((a, b) => a.name.localeCompare(b.name));
8607
- const regionsGroupByLetter = groupBy(regions, regionFirstLetter);
8864
+ const rawRegions = useRegions();
8865
+ const regions = useMemo(() => cleanUpRegions(rawRegions).sort((a, b) => a.name.localeCompare(b.name)), [rawRegions]);
8866
+ const regionsGroupByLetter = useMemo(() => groupBy(regions, regionFirstLetter), [regions]);
8608
8867
  const { close } = useDialogManager();
8609
- const handleChangeLocation = useCallback((region) => {
8610
- selectCurrentLocation(region);
8868
+ const handleChangeLocation = useCallback((_) => {
8869
+ locationStore.location = _;
8611
8870
  close();
8612
- }, []);
8613
- 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
8871
+ }, [locationStore]);
8872
+ 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
8614
8873
  .filter(({ name }) => name && jaroWinklerDistance(name.toLowerCase())(query.toLowerCase()) >= 0.8)
8615
8874
  .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)] }));
8616
8875
  });
8617
- const regionFirstLetter = (region) => region.name?.charAt(0) || '';
8876
+ const regionFirstLetter = (region) => region.name?.charAt(0) ?? '';
8618
8877
  const cleanUpRegions = (regions) => regions.map((region) => ({
8619
8878
  ...region,
8620
- name: region.name?.replace(/республика|область|край'/gi, '').trim() || '',
8879
+ name: region.name?.replace(/республика|область|край'/gi, '').trim() ?? '',
8621
8880
  }));
8622
8881
 
8623
8882
  const useLocationDialog = (props) => {
@@ -8645,7 +8904,7 @@
8645
8904
 
8646
8905
  const HeaderSecondaryMenu = JSX(({ className, version, ...rest }) => {
8647
8906
  const iconVersion = version === 'transparent' ? 'white' : 'black';
8648
- const [currentLocation] = useLocation(rest?.branches?.default);
8907
+ const currentLocation = useLocation(rest?.branches?.default);
8649
8908
  const searchDialog = useSearchDialog(rest);
8650
8909
  const locationDialog = useLocationDialog(rest);
8651
8910
  const openSearchDialog = useCallback(() => searchDialog.open(), [searchDialog]);
@@ -9177,7 +9436,7 @@
9177
9436
  designDisabledPeople: (item) => Boolean(item.designDisabledPeople),
9178
9437
  };
9179
9438
  const AtmsMap = JSX(({ descriptionData, className }) => {
9180
- const [currentLocation] = useLocation();
9439
+ const currentLocation = useLocation();
9181
9440
  const regionCode = currentLocation?.code ?? '000';
9182
9441
  const { data: officesData, isLoad } = useAtms(regionCode);
9183
9442
  return (jsx(OfficesAtmsMapLayout, { className: className, filterItems: filterItems, data: officesData, isLoad: isLoad, initFilterState: INITIAL_FILTRATION_STATE, renderCard: renderAtmCard, getBalloon: getAtmPoint, title: `Банкоматы филиала ${currentLocation?.name}`, descriptionData: descriptionData }));
@@ -9230,7 +9489,7 @@
9230
9489
  };
9231
9490
 
9232
9491
  const OfficesMap = JSX(({ className }) => {
9233
- const [currentLocation] = useLocation();
9492
+ const currentLocation = useLocation();
9234
9493
  const regionCode = currentLocation?.code ?? '000';
9235
9494
  const { data, isLoad } = useOffices(regionCode);
9236
9495
  return (jsx(OfficesAtmsMapLayout, { className: className, data: data?.branches, isLoad: isLoad, remoteWorkplaces: data?.remoteWorkplaces, renderCard: renderOfficeCard, renderRemoteWorkplaceCard: renderRemoteWorkplaceCard, getBalloon: getOfficePoint, getBalloonRemoteWorkplaces: getRemoteWorkplacePoint, title: `Офисы филиала ${currentLocation?.name}` }));
@@ -9918,6 +10177,9 @@
9918
10177
  pop();
9919
10178
  }, [dialogs, onClose]);
9920
10179
  useEffect(() => defaultEventBus.subscribe('dialog', (action) => {
10180
+ if (!action) {
10181
+ return;
10182
+ }
9921
10183
  switch (action.type) {
9922
10184
  case 'open':
9923
10185
  push(action);
@@ -9975,6 +10237,9 @@
9975
10237
  setPopup(null);
9976
10238
  }, []);
9977
10239
  useEffect(() => defaultEventBus.subscribe('popup', (action) => {
10240
+ if (!action) {
10241
+ return;
10242
+ }
9978
10243
  switch (action.type) {
9979
10244
  case 'open':
9980
10245
  case 'update':
@@ -10008,6 +10273,7 @@
10008
10273
  const { slots, blocks, fallback, ...pageContent } = data;
10009
10274
  const resolvedPageContent = useJSONRef(pageContent, fallback);
10010
10275
  useClickHandler();
10276
+ useDefaultLocation();
10011
10277
  const options = {
10012
10278
  key: '',
10013
10279
  page: { slots, blocks, fallback, ...resolvedPageContent },
@@ -10029,7 +10295,7 @@
10029
10295
  slots: () => [HEADER_SLOT, FOOTER_SLOT, STICKY_FOOTER_SLOT],
10030
10296
  });
10031
10297
 
10032
- const packageVersion = "0.14.674";
10298
+ const packageVersion = "0.14.675";
10033
10299
 
10034
10300
  exports.Blocks = Blocks;
10035
10301
  exports.ContentPage = ContentPage;