@redneckz/wildless-cms-uni-blocks 0.6.43 → 0.6.44

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 (142) hide show
  1. package/bundle/ProjectSettings.d.ts +2 -0
  2. package/bundle/bundle.umd.js +39 -22
  3. package/bundle/bundle.umd.min.js +1 -1
  4. package/bundle/services/BlockRouter/BlockRouter.d.ts +1 -1
  5. package/bundle/services/sitemap/checkIsHrefSameOrigin.d.ts +2 -4
  6. package/bundle/utils/normalizeURLPath.d.ts +1 -0
  7. package/bundle/utils/url.d.ts +1 -0
  8. package/dist/ProjectSettings.d.ts +2 -0
  9. package/dist/ProjectSettings.js +5 -0
  10. package/dist/ProjectSettings.js.map +1 -1
  11. package/dist/api/LikeAPI.js +2 -2
  12. package/dist/api/LikeAPI.js.map +1 -1
  13. package/dist/components/Header/Header.js +1 -6
  14. package/dist/components/Header/Header.js.map +1 -1
  15. package/dist/hooks/useLink.js +3 -5
  16. package/dist/hooks/useLink.js.map +1 -1
  17. package/dist/hooks/useLocation.js +11 -5
  18. package/dist/hooks/useLocation.js.map +1 -1
  19. package/dist/services/BlockRouter/BlockRouter.d.ts +1 -1
  20. package/dist/services/BlockRouter/BlockRouter.js.map +1 -1
  21. package/dist/services/sitemap/checkIsHrefSameOrigin.d.ts +2 -4
  22. package/dist/services/sitemap/checkIsHrefSameOrigin.js +1 -1
  23. package/dist/services/sitemap/checkIsHrefSameOrigin.js.map +1 -1
  24. package/dist/services/sitemap/isHrefActive.js +2 -3
  25. package/dist/services/sitemap/isHrefActive.js.map +1 -1
  26. package/dist/setup-fixture.js +3 -3
  27. package/dist/setup-fixture.js.map +1 -1
  28. package/dist/utils/normalizeURLPath.d.ts +1 -0
  29. package/dist/utils/normalizeURLPath.js +12 -0
  30. package/dist/utils/normalizeURLPath.js.map +1 -0
  31. package/dist/utils/url.d.ts +1 -0
  32. package/dist/utils/url.js +9 -1
  33. package/dist/utils/url.js.map +1 -1
  34. package/dist/wlc.json +3 -1
  35. package/lib/ProjectSettings.d.ts +2 -0
  36. package/lib/ProjectSettings.js +5 -0
  37. package/lib/ProjectSettings.js.map +1 -1
  38. package/lib/api/LikeAPI.js +2 -2
  39. package/lib/api/LikeAPI.js.map +1 -1
  40. package/lib/components/Header/Header.js +1 -6
  41. package/lib/components/Header/Header.js.map +1 -1
  42. package/lib/hooks/useLink.js +3 -5
  43. package/lib/hooks/useLink.js.map +1 -1
  44. package/lib/hooks/useLocation.js +11 -5
  45. package/lib/hooks/useLocation.js.map +1 -1
  46. package/lib/services/BlockRouter/BlockRouter.d.ts +1 -1
  47. package/lib/services/BlockRouter/BlockRouter.js.map +1 -1
  48. package/lib/services/sitemap/checkIsHrefSameOrigin.d.ts +2 -4
  49. package/lib/services/sitemap/checkIsHrefSameOrigin.js +1 -1
  50. package/lib/services/sitemap/checkIsHrefSameOrigin.js.map +1 -1
  51. package/lib/services/sitemap/isHrefActive.js +3 -4
  52. package/lib/services/sitemap/isHrefActive.js.map +1 -1
  53. package/lib/setup-fixture.js +3 -3
  54. package/lib/setup-fixture.js.map +1 -1
  55. package/lib/utils/normalizeURLPath.d.ts +1 -0
  56. package/lib/utils/normalizeURLPath.js +9 -0
  57. package/lib/utils/normalizeURLPath.js.map +1 -0
  58. package/lib/utils/url.d.ts +1 -0
  59. package/lib/utils/url.js +7 -0
  60. package/lib/utils/url.js.map +1 -1
  61. package/lib/wlc.json +3 -1
  62. package/mobile/bundle/ProjectSettings.d.ts +2 -0
  63. package/mobile/bundle/bundle.umd.js +38 -16
  64. package/mobile/bundle/bundle.umd.min.js +1 -1
  65. package/mobile/bundle/services/BlockRouter/BlockRouter.d.ts +1 -1
  66. package/mobile/bundle/services/sitemap/checkIsHrefSameOrigin.d.ts +2 -4
  67. package/mobile/bundle/utils/normalizeURLPath.d.ts +1 -0
  68. package/mobile/bundle/utils/url.d.ts +1 -0
  69. package/mobile/dist/ProjectSettings.d.ts +2 -0
  70. package/mobile/dist/ProjectSettings.js +5 -0
  71. package/mobile/dist/ProjectSettings.js.map +1 -1
  72. package/mobile/dist/api/LikeAPI.js +2 -2
  73. package/mobile/dist/api/LikeAPI.js.map +1 -1
  74. package/mobile/dist/hooks/useLink.js +3 -5
  75. package/mobile/dist/hooks/useLink.js.map +1 -1
  76. package/mobile/dist/hooks/useLocation.js +11 -5
  77. package/mobile/dist/hooks/useLocation.js.map +1 -1
  78. package/mobile/dist/services/BlockRouter/BlockRouter.d.ts +1 -1
  79. package/mobile/dist/services/BlockRouter/BlockRouter.js.map +1 -1
  80. package/mobile/dist/services/sitemap/checkIsHrefSameOrigin.d.ts +2 -4
  81. package/mobile/dist/services/sitemap/checkIsHrefSameOrigin.js +1 -1
  82. package/mobile/dist/services/sitemap/checkIsHrefSameOrigin.js.map +1 -1
  83. package/mobile/dist/services/sitemap/isHrefActive.js +2 -3
  84. package/mobile/dist/services/sitemap/isHrefActive.js.map +1 -1
  85. package/mobile/dist/setup-fixture.js +3 -3
  86. package/mobile/dist/setup-fixture.js.map +1 -1
  87. package/mobile/dist/utils/normalizeURLPath.d.ts +1 -0
  88. package/mobile/dist/utils/normalizeURLPath.js +12 -0
  89. package/mobile/dist/utils/normalizeURLPath.js.map +1 -0
  90. package/mobile/dist/utils/url.d.ts +1 -0
  91. package/mobile/dist/utils/url.js +9 -1
  92. package/mobile/dist/utils/url.js.map +1 -1
  93. package/mobile/dist/wlc.json +3 -1
  94. package/mobile/lib/ProjectSettings.d.ts +2 -0
  95. package/mobile/lib/ProjectSettings.js +5 -0
  96. package/mobile/lib/ProjectSettings.js.map +1 -1
  97. package/mobile/lib/api/LikeAPI.js +2 -2
  98. package/mobile/lib/api/LikeAPI.js.map +1 -1
  99. package/mobile/lib/hooks/useLink.js +3 -5
  100. package/mobile/lib/hooks/useLink.js.map +1 -1
  101. package/mobile/lib/hooks/useLocation.js +11 -5
  102. package/mobile/lib/hooks/useLocation.js.map +1 -1
  103. package/mobile/lib/services/BlockRouter/BlockRouter.d.ts +1 -1
  104. package/mobile/lib/services/BlockRouter/BlockRouter.js.map +1 -1
  105. package/mobile/lib/services/sitemap/checkIsHrefSameOrigin.d.ts +2 -4
  106. package/mobile/lib/services/sitemap/checkIsHrefSameOrigin.js +1 -1
  107. package/mobile/lib/services/sitemap/checkIsHrefSameOrigin.js.map +1 -1
  108. package/mobile/lib/services/sitemap/isHrefActive.js +3 -4
  109. package/mobile/lib/services/sitemap/isHrefActive.js.map +1 -1
  110. package/mobile/lib/setup-fixture.js +3 -3
  111. package/mobile/lib/setup-fixture.js.map +1 -1
  112. package/mobile/lib/utils/normalizeURLPath.d.ts +1 -0
  113. package/mobile/lib/utils/normalizeURLPath.js +9 -0
  114. package/mobile/lib/utils/normalizeURLPath.js.map +1 -0
  115. package/mobile/lib/utils/url.d.ts +1 -0
  116. package/mobile/lib/utils/url.js +7 -0
  117. package/mobile/lib/utils/url.js.map +1 -1
  118. package/mobile/lib/wlc.json +3 -1
  119. package/mobile/src/ProjectSettings.ts +6 -0
  120. package/mobile/src/api/LikeAPI.ts +2 -2
  121. package/mobile/src/hooks/useLink.ts +6 -7
  122. package/mobile/src/hooks/useLocation.ts +12 -6
  123. package/mobile/src/services/BlockRouter/BlockRouter.ts +1 -1
  124. package/mobile/src/services/sitemap/checkIsHrefSameOrigin.ts +5 -4
  125. package/mobile/src/services/sitemap/isHrefActive.ts +7 -4
  126. package/mobile/src/setup-fixture.ts +3 -3
  127. package/mobile/src/utils/normalizeURLPath.ts +10 -0
  128. package/mobile/src/utils/url.ts +10 -0
  129. package/mobile/src/wlc.json +3 -1
  130. package/package.json +1 -1
  131. package/src/ProjectSettings.ts +6 -0
  132. package/src/api/LikeAPI.ts +2 -2
  133. package/src/components/Header/Header.tsx +2 -10
  134. package/src/hooks/useLink.ts +6 -7
  135. package/src/hooks/useLocation.ts +12 -6
  136. package/src/services/BlockRouter/BlockRouter.ts +1 -1
  137. package/src/services/sitemap/checkIsHrefSameOrigin.ts +5 -4
  138. package/src/services/sitemap/isHrefActive.ts +7 -4
  139. package/src/setup-fixture.ts +3 -3
  140. package/src/utils/normalizeURLPath.ts +10 -0
  141. package/src/utils/url.ts +10 -0
  142. package/src/wlc.json +3 -1
@@ -7,6 +7,7 @@ export interface ProjectSettings {
7
7
  SITEMAP?: string;
8
8
  FOOTER?: string;
9
9
  CDN?: string;
10
+ BASE_PATH?: string;
10
11
  YANDEX_MAP_API_KEY?: string;
11
12
  YANDEX_METRIKA_ID?: string;
12
13
  }
@@ -21,6 +22,7 @@ export declare const projectSettings: {
21
22
  readonly SITEMAP: string | undefined;
22
23
  readonly FOOTER: string | undefined;
23
24
  readonly CDN: string | undefined;
25
+ readonly BASE_PATH: string | undefined;
24
26
  readonly YANDEX_MAP_API_KEY: string | undefined;
25
27
  readonly YANDEX_METRIKA_ID: string | undefined;
26
28
  };
@@ -85,6 +85,11 @@
85
85
  get CDN() {
86
86
  return this._.CDN;
87
87
  }
88
+ get BASE_PATH() {
89
+ return this._.BASE_PATH && !this._.BASE_PATH.endsWith('/')
90
+ ? `${this._.BASE_PATH}/`
91
+ : this._.BASE_PATH;
92
+ }
88
93
  get YANDEX_MAP_API_KEY() {
89
94
  return this._.YANDEX_MAP_API_KEY;
90
95
  }
@@ -175,7 +180,7 @@
175
180
  }
176
181
  async function auth() {
177
182
  try {
178
- const userData = JSON.parse(globalThis.localStorage.getItem(STORAGE_KEY) || '');
183
+ const userData = JSON.parse(globalThis.localStorage?.getItem(STORAGE_KEY) || '');
179
184
  if (userData?.token) {
180
185
  return userData;
181
186
  }
@@ -195,7 +200,7 @@
195
200
  }),
196
201
  });
197
202
  const { token, name } = await response.json();
198
- globalThis.localStorage.setItem(STORAGE_KEY, JSON.stringify({ token, name }));
203
+ globalThis.localStorage?.setItem(STORAGE_KEY, JSON.stringify({ token, name }));
199
204
  return { token, name };
200
205
  }
201
206
  catch (e) {
@@ -585,6 +590,13 @@
585
590
  const endOfOrigin = url.indexOf('/', endOfProto + protoSeparator.length);
586
591
  return endOfOrigin !== -1 ? url.substring(0, endOfOrigin) : url;
587
592
  };
593
+ const getPathname = (href) => {
594
+ if (!href || !isURL(href)) {
595
+ return undefined;
596
+ }
597
+ const url = new URL(href);
598
+ return url.pathname;
599
+ };
588
600
  const getHash = (href) => {
589
601
  if (!href || !isURL(href)) {
590
602
  return undefined;
@@ -599,6 +611,7 @@
599
611
  isURL: isURL,
600
612
  withoutQuery: withoutQuery,
601
613
  getOrigin: getOrigin,
614
+ getPathname: getPathname,
602
615
  getHash: getHash,
603
616
  isHash: isHash
604
617
  });
@@ -650,10 +663,7 @@
650
663
  'aria-label': props.text,
651
664
  onClick: handlerDecorator((ev) => {
652
665
  props.onClick && props.onClick(ev);
653
- const isLocalHref = href && !isURL(href);
654
- const isLocalTarget = !props.target || props.target === '_self';
655
- if (!isLocalHref || !isLocalTarget) {
656
- // Default handle
666
+ if (isRemoteHref(href, props.target)) {
657
667
  return;
658
668
  }
659
669
  ev?.preventDefault();
@@ -661,12 +671,13 @@
661
671
  blockRouter.goto(href);
662
672
  }
663
673
  else {
664
- router.push(href);
674
+ href && router.push(href);
665
675
  }
666
676
  }, props),
667
677
  };
668
678
  };
669
679
  }
680
+ const isRemoteHref = (href, target) => isURL(href) || (target && target !== '_self') || href?.startsWith('/');
670
681
 
671
682
  const buttonStyleMap = {
672
683
  primary: 'text-white bg-primary-main hover:bg-primary-hover active:bg-primary-active',
@@ -2248,12 +2259,17 @@
2248
2259
  const renderMonthNames = (item, colSize) => item.month?.map((_, i) => (jsx("div", { style: { flexBasis: `${colSize}%` }, children: _.text }, `monthName-${i}`)));
2249
2260
  const renderMonthImages = (item) => item.month?.map((_) => _.image?.src ? (jsx("div", { className: "h-[207px] border-r pr-3 mr-3 border-main-divider last:border-r-0 last:pr-0 last:mr-0", children: jsx(ImgInner, { image: _.image, className: "flex" }) }, `monthImage-${_.image.src}`)) : null);
2250
2261
 
2251
- const checkIsHrefSameOrigin = (href, router) => getOrigin(href) === getOrigin(router.href);
2262
+ const checkIsHrefSameOrigin = (href, router) => [getOrigin(href), getOrigin(router.href)].every((link, _, arr) => Boolean(link) && link === arr[0]);
2252
2263
 
2253
- const isHrefActive = (href, router, cmp = (targetHref, baseHref) => baseHref.startsWith(targetHref)) => {
2254
- return cmp(withoutQuery(href), withoutQuery(isURL(href) ? router.href : router.pathname));
2264
+ const normalizeURLPath = (href) => {
2265
+ if (isURL(href) || href?.startsWith('/')) {
2266
+ return href;
2267
+ }
2268
+ return `${projectSettings.BASE_PATH || ''}${href}`;
2255
2269
  };
2256
2270
 
2271
+ const isHrefActive = (href, router, cmp = (targetHref, baseHref) => baseHref.startsWith(targetHref)) => cmp(withoutQuery(normalizeURLPath(href)), withoutQuery(isURL(href) ? router.href : getPathname(router.href)));
2272
+
2257
2273
  const isSubItemActive = (router) => (subItem) => isHrefActive(subItem.href, router);
2258
2274
 
2259
2275
  const isTopItemActive = (router) => (topItem) => topItem.items?.some(isSubItemActive(router)) ||
@@ -2303,11 +2319,8 @@
2303
2319
  }
2304
2320
 
2305
2321
  const REGION_URL = '/api/v1/region';
2306
- const localStorageLocation = globalThis?.localStorage.getItem('location');
2307
- const currentLocation = localStorageLocation
2308
- ? JSON.parse(localStorageLocation)
2309
- : null;
2310
2322
  function useLocation(defaultLocation) {
2323
+ const currentLocation = getLocalStorageLocation();
2311
2324
  const [location, setLocation] = useState(currentLocation?.region ?? { name: defaultLocation });
2312
2325
  const { data } = useCachedAsyncData(REGION_URL, fetchJSONUnsafe);
2313
2326
  useEffect(() => {
@@ -2316,11 +2329,20 @@
2316
2329
  : data || { name: defaultLocation });
2317
2330
  }, [data]);
2318
2331
  const onChangeLocation = useCallback((region) => {
2319
- globalThis?.localStorage.setItem('location', JSON.stringify({ manual: true, region }));
2332
+ globalThis.localStorage?.setItem('location', JSON.stringify({ manual: true, region }));
2320
2333
  setLocation(region);
2321
2334
  }, [setLocation]);
2322
2335
  return [location, onChangeLocation];
2323
2336
  }
2337
+ const getLocalStorageLocation = () => {
2338
+ const localStorageLocation = globalThis.localStorage?.getItem('location');
2339
+ try {
2340
+ return localStorageLocation ? JSON.parse(localStorageLocation) : null;
2341
+ }
2342
+ catch (_) {
2343
+ return null;
2344
+ }
2345
+ };
2324
2346
 
2325
2347
  const REGIONS_URL$1 = '/api/v1/regions';
2326
2348
  function useRegions() {
@@ -2480,15 +2502,10 @@
2480
2502
  const Header = JSX(({ bgColor = 'bg-white', className = '', showSubMenu = true, ...rest }) => {
2481
2503
  const router = useRouter();
2482
2504
  const { topItems, logo, defaultLocation, foreignOffices, officesLink } = useSWRResource(projectSettings.SITEMAP || 'sitemap', rest.options?.page?.fallback);
2483
- const activeTopItem = showSubMenu ? getActiveItem(topItems, router) : null;
2505
+ const activeTopItem = topItems?.find(isTopItemActive(router));
2484
2506
  const topMenu = topItems?.map((_, i) => (jsx(TopItem, { active: _ === activeTopItem, "aria-label": _.text, bgColor: bgColor, ..._ }, String(i))));
2485
2507
  return (jsx(BlockWrapper, { tag: "header", className: `pt-6 px-20 ${bgColor} ${className} ${showSubMenu && activeTopItem?.items?.length ? 'pb-4' : 'pb-5'}`, ...rest, children: jsxs("div", { className: "container", children: [jsxs("div", { className: "flex items-center", children: [jsx(Logo, { className: "mr-8", bgColor: bgColor, logo: logo }), topMenu, jsx(HeaderSecondaryMenu, { className: "ml-auto", foreignOffices: foreignOffices, defaultLocation: defaultLocation, officesLink: officesLink, bgColor: bgColor })] }), jsx("div", { className: `mt-6 h-px ${BORDER_COLORS[bgColor]}` }), showSubMenu && activeTopItem?.items?.length ? (jsx(HeaderSubMenu, { subItems: activeTopItem.items, bgColor: bgColor })) : null] }) }));
2486
2508
  });
2487
- const getActiveItem = (topItems, router) => {
2488
- const [firstPortal] = topItems || [];
2489
- // Если по слагу невозможно понять к какому подпорталу этот слаг относиться, то выбираем первый подпортал.
2490
- return topItems?.find(isTopItemActive(router)) || firstPortal;
2491
- };
2492
2509
 
2493
2510
  const ImgBlock = JSX((props) => {
2494
2511
  const { className, image, ...rest } = props;
@@ -4107,7 +4124,7 @@
4107
4124
  return (jsx("div", { className: "flex items-end absolute bottom-0 right-0 h-full pointer-events-none", children: jsx(LikeControl, { className: "rounded-tl-lg sticky bottom-0 pointer-events-auto" }) }));
4108
4125
  }
4109
4126
 
4110
- const packageVersion = "0.6.43";
4127
+ const packageVersion = "0.6.44";
4111
4128
 
4112
4129
  exports.Blocks = Blocks;
4113
4130
  exports.ContentPage = ContentPage;