@redneckz/wildless-cms-uni-blocks 0.14.59 → 0.14.61

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 (41) hide show
  1. package/bundle/bundle.umd.js +49 -74
  2. package/bundle/bundle.umd.min.js +1 -1
  3. package/bundle/components/ExchangeRateTile/useFetchExchangeRateData.d.ts +2 -10
  4. package/dist/components/ExchangeRateTile/ExchangeRateTile.js +3 -1
  5. package/dist/components/ExchangeRateTile/ExchangeRateTile.js.map +1 -1
  6. package/dist/components/ExchangeRateTile/useFetchExchangeRateData.d.ts +2 -10
  7. package/dist/components/ExchangeRateTile/useFetchExchangeRateData.js +4 -35
  8. package/dist/components/ExchangeRateTile/useFetchExchangeRateData.js.map +1 -1
  9. package/dist/components/InsuranceAmountBlock/InsuranceAmountBlockInner.js +2 -1
  10. package/dist/components/InsuranceAmountBlock/InsuranceAmountBlockInner.js.map +1 -1
  11. package/lib/components/ExchangeRateTile/ExchangeRateTile.js +3 -1
  12. package/lib/components/ExchangeRateTile/ExchangeRateTile.js.map +1 -1
  13. package/lib/components/ExchangeRateTile/useFetchExchangeRateData.d.ts +2 -10
  14. package/lib/components/ExchangeRateTile/useFetchExchangeRateData.js +3 -33
  15. package/lib/components/ExchangeRateTile/useFetchExchangeRateData.js.map +1 -1
  16. package/lib/components/InsuranceAmountBlock/InsuranceAmountBlockInner.js +2 -1
  17. package/lib/components/InsuranceAmountBlock/InsuranceAmountBlockInner.js.map +1 -1
  18. package/mobile/bundle/bundle.umd.js +48 -73
  19. package/mobile/bundle/bundle.umd.min.js +1 -1
  20. package/mobile/bundle/components/ExchangeRateTile/useFetchExchangeRateData.d.ts +2 -10
  21. package/mobile/dist/components/ExchangeRateTile/ExchangeRateTile.js +3 -1
  22. package/mobile/dist/components/ExchangeRateTile/ExchangeRateTile.js.map +1 -1
  23. package/mobile/dist/components/ExchangeRateTile/useFetchExchangeRateData.d.ts +2 -10
  24. package/mobile/dist/components/ExchangeRateTile/useFetchExchangeRateData.js +4 -35
  25. package/mobile/dist/components/ExchangeRateTile/useFetchExchangeRateData.js.map +1 -1
  26. package/mobile/dist/components/InsuranceAmountBlock/InsuranceAmountBlockInner.js +2 -1
  27. package/mobile/dist/components/InsuranceAmountBlock/InsuranceAmountBlockInner.js.map +1 -1
  28. package/mobile/lib/components/ExchangeRateTile/ExchangeRateTile.js +3 -1
  29. package/mobile/lib/components/ExchangeRateTile/ExchangeRateTile.js.map +1 -1
  30. package/mobile/lib/components/ExchangeRateTile/useFetchExchangeRateData.d.ts +2 -10
  31. package/mobile/lib/components/ExchangeRateTile/useFetchExchangeRateData.js +3 -33
  32. package/mobile/lib/components/ExchangeRateTile/useFetchExchangeRateData.js.map +1 -1
  33. package/mobile/lib/components/InsuranceAmountBlock/InsuranceAmountBlockInner.js +2 -1
  34. package/mobile/lib/components/InsuranceAmountBlock/InsuranceAmountBlockInner.js.map +1 -1
  35. package/mobile/src/components/ExchangeRateTile/ExchangeRateTile.tsx +3 -1
  36. package/mobile/src/components/ExchangeRateTile/useFetchExchangeRateData.ts +7 -54
  37. package/mobile/src/components/InsuranceAmountBlock/InsuranceAmountBlockInner.tsx +7 -2
  38. package/package.json +1 -1
  39. package/src/components/ExchangeRateTile/ExchangeRateTile.tsx +3 -1
  40. package/src/components/ExchangeRateTile/useFetchExchangeRateData.ts +7 -54
  41. package/src/components/InsuranceAmountBlock/InsuranceAmountBlockInner.tsx +7 -2
@@ -3499,6 +3499,48 @@
3499
3499
  };
3500
3500
  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(Button, { version: button?.version, text: button?.text, ...button }) : null] })));
3501
3501
 
3502
+ const useLatestEvent = (eventBus, type, initialEvent) => {
3503
+ const [latestEvent, setLatestEvent] = useState(initialEvent || null);
3504
+ useEffect(() => eventBus.subscribe(type, (_) => setLatestEvent(_)), [eventBus, type]);
3505
+ const fireEvent = useCallback((_) => eventBus.fire(type, _), [eventBus, type]);
3506
+ return [latestEvent, fireEvent];
3507
+ };
3508
+
3509
+ const REGION_URL = '/api/v1/region';
3510
+ const LOCATION_STORAGE_KEY = 'location';
3511
+ function useLocation(defaultLocation = 'Москва') {
3512
+ const [currentLocation, fireCurrentLocation] = useLatestEvent(defaultEventBus, 'location', restoreLocation() ?? { name: defaultLocation });
3513
+ const selectCurrentLocation = useCallback((_) => {
3514
+ storeLocation(_);
3515
+ fireCurrentLocation(_);
3516
+ }, []);
3517
+ const { data } = useAsyncData(REGION_URL, fetchJSONUnsafe);
3518
+ useEffect(() => {
3519
+ if (data && !hasStoredLocation()) {
3520
+ fireCurrentLocation(data);
3521
+ }
3522
+ }, [data]);
3523
+ return [currentLocation ?? { name: defaultLocation }, selectCurrentLocation];
3524
+ }
3525
+ const hasStoredLocation = () => Boolean(globalThis.localStorage?.getItem(LOCATION_STORAGE_KEY));
3526
+ const restoreLocation = () => {
3527
+ try {
3528
+ const data = globalThis.localStorage?.getItem(LOCATION_STORAGE_KEY);
3529
+ return data && JSON.parse(data);
3530
+ }
3531
+ catch (ex) {
3532
+ return null;
3533
+ }
3534
+ };
3535
+ const storeLocation = (_) => {
3536
+ try {
3537
+ globalThis.localStorage?.setItem(LOCATION_STORAGE_KEY, JSON.stringify(_));
3538
+ }
3539
+ catch (ex) {
3540
+ // Do nothing
3541
+ }
3542
+ };
3543
+
3502
3544
  var Currency;
3503
3545
  (function (Currency) {
3504
3546
  Currency["RUB"] = "RUB";
@@ -3629,40 +3671,15 @@
3629
3671
  };
3630
3672
 
3631
3673
  const EXCHANGE_RATES_URL = '/api/v1/exchangerates';
3632
- const REGION_URL$1 = '/api/v1/region';
3633
- function useFetchExchangeRateData() {
3634
- const { data } = useAsyncData(EXCHANGE_RATES_URL, fetchData);
3674
+ function useFetchExchangeRateData(currentRegion) {
3675
+ const regionCode = currentRegion?.code || '000';
3676
+ const { data } = useAsyncData(EXCHANGE_RATES_URL + `?regionCode=${regionCode}`, fetchJSONUnsafe);
3635
3677
  return data || {};
3636
3678
  }
3637
- const fetchData = async (urlExchangeRates) => {
3638
- const region = await fetchRegion();
3639
- const regionCode = region?.code || '000';
3640
- const exchangeRates = await fetchExchangeRates(urlExchangeRates, regionCode);
3641
- return { region, exchangeRates };
3642
- };
3643
- const fetchRegion = async () => {
3644
- try {
3645
- return await fetchJSONUnsafe(REGION_URL$1, { method: 'GET' });
3646
- }
3647
- catch (error) {
3648
- console.log(error);
3649
- return {};
3650
- }
3651
- };
3652
- const fetchExchangeRates = async (url, regionCode) => {
3653
- try {
3654
- return await fetchJSONUnsafe(url + `?regionCode=${regionCode}`, {
3655
- method: 'GET',
3656
- });
3657
- }
3658
- catch (error) {
3659
- console.log(error);
3660
- return {};
3661
- }
3662
- };
3663
3679
 
3664
3680
  const ExchangeRateTile = JSX(({ className = '', title = 'Курсы обмена валют', button, ...rest }) => {
3665
- const { exchangeRates } = useFetchExchangeRateData();
3681
+ const [currentLocation] = useLocation();
3682
+ const exchangeRates = useFetchExchangeRateData(currentLocation);
3666
3683
  const currencyRates = getCurrencyRates(exchangeRates?.exchangeRate?.currencies);
3667
3684
  const currencyRatesBuy = currencyRates.filter((_) => _.buyExchangeRate);
3668
3685
  currencyRatesBuy.unshift({ currency: { currency: Currency.RUB } });
@@ -4017,48 +4034,6 @@
4017
4034
  ? 'text-primary-main'
4018
4035
  : style(flat ? 'text-primary-text' : 'text-secondary-text', 'hover:text-primary-main'), 'group-data-transparent:text-white group-data-transparent:hover:text-primary-hover');
4019
4036
 
4020
- const useLatestEvent = (eventBus, type, initialEvent) => {
4021
- const [latestEvent, setLatestEvent] = useState(initialEvent || null);
4022
- useEffect(() => eventBus.subscribe(type, (_) => setLatestEvent(_)), [eventBus, type]);
4023
- const fireEvent = useCallback((_) => eventBus.fire(type, _), [eventBus, type]);
4024
- return [latestEvent, fireEvent];
4025
- };
4026
-
4027
- const REGION_URL = '/api/v1/region';
4028
- const LOCATION_STORAGE_KEY = 'location';
4029
- function useLocation(defaultLocation = 'Москва') {
4030
- const [currentLocation, fireCurrentLocation] = useLatestEvent(defaultEventBus, 'location', restoreLocation() ?? { name: defaultLocation });
4031
- const selectCurrentLocation = useCallback((_) => {
4032
- storeLocation(_);
4033
- fireCurrentLocation(_);
4034
- }, []);
4035
- const { data } = useAsyncData(REGION_URL, fetchJSONUnsafe);
4036
- useEffect(() => {
4037
- if (data && !hasStoredLocation()) {
4038
- fireCurrentLocation(data);
4039
- }
4040
- }, [data]);
4041
- return [currentLocation ?? { name: defaultLocation }, selectCurrentLocation];
4042
- }
4043
- const hasStoredLocation = () => Boolean(globalThis.localStorage?.getItem(LOCATION_STORAGE_KEY));
4044
- const restoreLocation = () => {
4045
- try {
4046
- const data = globalThis.localStorage?.getItem(LOCATION_STORAGE_KEY);
4047
- return data && JSON.parse(data);
4048
- }
4049
- catch (ex) {
4050
- return null;
4051
- }
4052
- };
4053
- const storeLocation = (_) => {
4054
- try {
4055
- globalThis.localStorage?.setItem(LOCATION_STORAGE_KEY, JSON.stringify(_));
4056
- }
4057
- catch (ex) {
4058
- // Do nothing
4059
- }
4060
- };
4061
-
4062
4037
  const REGIONS_URL = '/api/v1/regions';
4063
4038
  function useRegions() {
4064
4039
  const { data } = useAsyncData(REGIONS_URL, fetchJSONUnsafe);
@@ -4341,7 +4316,7 @@
4341
4316
  return (jsxs("button", { type: "button", onClick: onClick, className: `p-3xl min-w-fit flex items-center gap-2xl bg-white border-solid border relative ${btnClassName}`, children: [slide?.icon ? (jsx(Img, { className: "p-lg rounded-full bg-secondary-light", image: slide.icon, width: "108", height: "108" })) : null, jsxs("div", { className: "flex gap-s", children: [slide?.sum ? renderValueBlock('страховая сумма', slide.sum) : null, slide?.fee ? renderValueBlock('страховой взнос', slide.fee) : null] }), renderDoneIcon(isActive)] }, String(i)));
4342
4317
  }
4343
4318
  function renderValueBlock(title, sum) {
4344
- return (jsxs("div", { className: "flex flex-col text-left whitespace-pre", children: [jsxs("span", { className: "text-h6", children: [toLocalNumberFormat(2)(sum), " \u20BD"] }), jsx("span", { className: "text-secondary-text text-l mt-2xs", children: title })] }));
4319
+ return (jsxs("div", { className: "flex flex-col text-left whitespace-pre", children: [jsxs(Text, { size: "text-h6", children: [toLocalNumberFormat(2)(sum), " \u20BD"] }), jsx("div", { className: "mt-2xs", children: jsx(Text, { size: "text-l", color: "text-secondary-text", children: title }) })] }));
4345
4320
  }
4346
4321
  function renderDoneIcon(isActive) {
4347
4322
  return isActive ? (jsx(Img, { className: `h-6 w-6 min-w-6 min-h-6 absolute right-4 top-4`, image: { icon: 'DoneIcon' }, width: "24", height: "24" })) : null;
@@ -5825,7 +5800,7 @@
5825
5800
  return (jsx("div", { className: "flex items-end absolute bottom-0 right-0 h-full pointer-events-none", children: jsx(LikeControl, { className: "rounded-tl-3xl sticky bottom-0 pointer-events-auto" }) }));
5826
5801
  }
5827
5802
 
5828
- const packageVersion = "0.14.58";
5803
+ const packageVersion = "0.14.60";
5829
5804
 
5830
5805
  exports.Blocks = Blocks;
5831
5806
  exports.ContentPage = ContentPage;