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

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 (152) hide show
  1. package/bundle/ProjectSettings.d.ts +2 -0
  2. package/bundle/bundle.umd.js +41 -23
  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/services/sitemap/isTopItemActive.js +3 -1
  27. package/dist/services/sitemap/isTopItemActive.js.map +1 -1
  28. package/dist/setup-fixture.js +3 -3
  29. package/dist/setup-fixture.js.map +1 -1
  30. package/dist/utils/normalizeURLPath.d.ts +1 -0
  31. package/dist/utils/normalizeURLPath.js +12 -0
  32. package/dist/utils/normalizeURLPath.js.map +1 -0
  33. package/dist/utils/url.d.ts +1 -0
  34. package/dist/utils/url.js +9 -1
  35. package/dist/utils/url.js.map +1 -1
  36. package/dist/wlc.json +3 -1
  37. package/lib/ProjectSettings.d.ts +2 -0
  38. package/lib/ProjectSettings.js +5 -0
  39. package/lib/ProjectSettings.js.map +1 -1
  40. package/lib/api/LikeAPI.js +2 -2
  41. package/lib/api/LikeAPI.js.map +1 -1
  42. package/lib/components/Header/Header.js +1 -6
  43. package/lib/components/Header/Header.js.map +1 -1
  44. package/lib/hooks/useLink.js +3 -5
  45. package/lib/hooks/useLink.js.map +1 -1
  46. package/lib/hooks/useLocation.js +11 -5
  47. package/lib/hooks/useLocation.js.map +1 -1
  48. package/lib/services/BlockRouter/BlockRouter.d.ts +1 -1
  49. package/lib/services/BlockRouter/BlockRouter.js.map +1 -1
  50. package/lib/services/sitemap/checkIsHrefSameOrigin.d.ts +2 -4
  51. package/lib/services/sitemap/checkIsHrefSameOrigin.js +1 -1
  52. package/lib/services/sitemap/checkIsHrefSameOrigin.js.map +1 -1
  53. package/lib/services/sitemap/isHrefActive.js +3 -4
  54. package/lib/services/sitemap/isHrefActive.js.map +1 -1
  55. package/lib/services/sitemap/isTopItemActive.js +3 -1
  56. package/lib/services/sitemap/isTopItemActive.js.map +1 -1
  57. package/lib/setup-fixture.js +3 -3
  58. package/lib/setup-fixture.js.map +1 -1
  59. package/lib/utils/normalizeURLPath.d.ts +1 -0
  60. package/lib/utils/normalizeURLPath.js +9 -0
  61. package/lib/utils/normalizeURLPath.js.map +1 -0
  62. package/lib/utils/url.d.ts +1 -0
  63. package/lib/utils/url.js +7 -0
  64. package/lib/utils/url.js.map +1 -1
  65. package/lib/wlc.json +3 -1
  66. package/mobile/bundle/ProjectSettings.d.ts +2 -0
  67. package/mobile/bundle/bundle.umd.js +40 -17
  68. package/mobile/bundle/bundle.umd.min.js +1 -1
  69. package/mobile/bundle/services/BlockRouter/BlockRouter.d.ts +1 -1
  70. package/mobile/bundle/services/sitemap/checkIsHrefSameOrigin.d.ts +2 -4
  71. package/mobile/bundle/utils/normalizeURLPath.d.ts +1 -0
  72. package/mobile/bundle/utils/url.d.ts +1 -0
  73. package/mobile/dist/ProjectSettings.d.ts +2 -0
  74. package/mobile/dist/ProjectSettings.js +5 -0
  75. package/mobile/dist/ProjectSettings.js.map +1 -1
  76. package/mobile/dist/api/LikeAPI.js +2 -2
  77. package/mobile/dist/api/LikeAPI.js.map +1 -1
  78. package/mobile/dist/hooks/useLink.js +3 -5
  79. package/mobile/dist/hooks/useLink.js.map +1 -1
  80. package/mobile/dist/hooks/useLocation.js +11 -5
  81. package/mobile/dist/hooks/useLocation.js.map +1 -1
  82. package/mobile/dist/services/BlockRouter/BlockRouter.d.ts +1 -1
  83. package/mobile/dist/services/BlockRouter/BlockRouter.js.map +1 -1
  84. package/mobile/dist/services/sitemap/checkIsHrefSameOrigin.d.ts +2 -4
  85. package/mobile/dist/services/sitemap/checkIsHrefSameOrigin.js +1 -1
  86. package/mobile/dist/services/sitemap/checkIsHrefSameOrigin.js.map +1 -1
  87. package/mobile/dist/services/sitemap/isHrefActive.js +2 -3
  88. package/mobile/dist/services/sitemap/isHrefActive.js.map +1 -1
  89. package/mobile/dist/services/sitemap/isTopItemActive.js +3 -1
  90. package/mobile/dist/services/sitemap/isTopItemActive.js.map +1 -1
  91. package/mobile/dist/setup-fixture.js +3 -3
  92. package/mobile/dist/setup-fixture.js.map +1 -1
  93. package/mobile/dist/utils/normalizeURLPath.d.ts +1 -0
  94. package/mobile/dist/utils/normalizeURLPath.js +12 -0
  95. package/mobile/dist/utils/normalizeURLPath.js.map +1 -0
  96. package/mobile/dist/utils/url.d.ts +1 -0
  97. package/mobile/dist/utils/url.js +9 -1
  98. package/mobile/dist/utils/url.js.map +1 -1
  99. package/mobile/dist/wlc.json +3 -1
  100. package/mobile/lib/ProjectSettings.d.ts +2 -0
  101. package/mobile/lib/ProjectSettings.js +5 -0
  102. package/mobile/lib/ProjectSettings.js.map +1 -1
  103. package/mobile/lib/api/LikeAPI.js +2 -2
  104. package/mobile/lib/api/LikeAPI.js.map +1 -1
  105. package/mobile/lib/hooks/useLink.js +3 -5
  106. package/mobile/lib/hooks/useLink.js.map +1 -1
  107. package/mobile/lib/hooks/useLocation.js +11 -5
  108. package/mobile/lib/hooks/useLocation.js.map +1 -1
  109. package/mobile/lib/services/BlockRouter/BlockRouter.d.ts +1 -1
  110. package/mobile/lib/services/BlockRouter/BlockRouter.js.map +1 -1
  111. package/mobile/lib/services/sitemap/checkIsHrefSameOrigin.d.ts +2 -4
  112. package/mobile/lib/services/sitemap/checkIsHrefSameOrigin.js +1 -1
  113. package/mobile/lib/services/sitemap/checkIsHrefSameOrigin.js.map +1 -1
  114. package/mobile/lib/services/sitemap/isHrefActive.js +3 -4
  115. package/mobile/lib/services/sitemap/isHrefActive.js.map +1 -1
  116. package/mobile/lib/services/sitemap/isTopItemActive.js +3 -1
  117. package/mobile/lib/services/sitemap/isTopItemActive.js.map +1 -1
  118. package/mobile/lib/setup-fixture.js +3 -3
  119. package/mobile/lib/setup-fixture.js.map +1 -1
  120. package/mobile/lib/utils/normalizeURLPath.d.ts +1 -0
  121. package/mobile/lib/utils/normalizeURLPath.js +9 -0
  122. package/mobile/lib/utils/normalizeURLPath.js.map +1 -0
  123. package/mobile/lib/utils/url.d.ts +1 -0
  124. package/mobile/lib/utils/url.js +7 -0
  125. package/mobile/lib/utils/url.js.map +1 -1
  126. package/mobile/lib/wlc.json +3 -1
  127. package/mobile/src/ProjectSettings.ts +6 -0
  128. package/mobile/src/api/LikeAPI.ts +2 -2
  129. package/mobile/src/hooks/useLink.ts +6 -7
  130. package/mobile/src/hooks/useLocation.ts +12 -6
  131. package/mobile/src/services/BlockRouter/BlockRouter.ts +1 -1
  132. package/mobile/src/services/sitemap/checkIsHrefSameOrigin.ts +5 -4
  133. package/mobile/src/services/sitemap/isHrefActive.ts +7 -4
  134. package/mobile/src/services/sitemap/isTopItemActive.ts +3 -1
  135. package/mobile/src/setup-fixture.ts +3 -3
  136. package/mobile/src/utils/normalizeURLPath.ts +10 -0
  137. package/mobile/src/utils/url.ts +10 -0
  138. package/mobile/src/wlc.json +3 -1
  139. package/package.json +1 -1
  140. package/src/ProjectSettings.ts +6 -0
  141. package/src/api/LikeAPI.ts +2 -2
  142. package/src/components/Header/Header.tsx +2 -10
  143. package/src/hooks/useLink.ts +6 -7
  144. package/src/hooks/useLocation.ts +12 -6
  145. package/src/services/BlockRouter/BlockRouter.ts +1 -1
  146. package/src/services/sitemap/checkIsHrefSameOrigin.ts +5 -4
  147. package/src/services/sitemap/isHrefActive.ts +7 -4
  148. package/src/services/sitemap/isTopItemActive.ts +3 -1
  149. package/src/setup-fixture.ts +3 -3
  150. package/src/utils/normalizeURLPath.ts +10 -0
  151. package/src/utils/url.ts +10 -0
  152. 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,17 +2259,23 @@
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)) ||
2260
2276
  isHrefActive(topItem.href, router) ||
2261
- checkIsHrefSameOrigin(topItem.href, router);
2277
+ checkIsHrefSameOrigin(topItem.href, router) ||
2278
+ Boolean(projectSettings.BASE_PATH?.startsWith(topItem.href || '/'));
2262
2279
 
2263
2280
  const TEXT_CLASSES$2 = 'font-sans text-s-light';
2264
2281
  const LINK_CLASSES$1 = 'inline-block border border-solid bg-transparent text-center no-underline';
@@ -2303,11 +2320,8 @@
2303
2320
  }
2304
2321
 
2305
2322
  const REGION_URL = '/api/v1/region';
2306
- const localStorageLocation = globalThis?.localStorage.getItem('location');
2307
- const currentLocation = localStorageLocation
2308
- ? JSON.parse(localStorageLocation)
2309
- : null;
2310
2323
  function useLocation(defaultLocation) {
2324
+ const currentLocation = getLocalStorageLocation();
2311
2325
  const [location, setLocation] = useState(currentLocation?.region ?? { name: defaultLocation });
2312
2326
  const { data } = useCachedAsyncData(REGION_URL, fetchJSONUnsafe);
2313
2327
  useEffect(() => {
@@ -2316,11 +2330,20 @@
2316
2330
  : data || { name: defaultLocation });
2317
2331
  }, [data]);
2318
2332
  const onChangeLocation = useCallback((region) => {
2319
- globalThis?.localStorage.setItem('location', JSON.stringify({ manual: true, region }));
2333
+ globalThis.localStorage?.setItem('location', JSON.stringify({ manual: true, region }));
2320
2334
  setLocation(region);
2321
2335
  }, [setLocation]);
2322
2336
  return [location, onChangeLocation];
2323
2337
  }
2338
+ const getLocalStorageLocation = () => {
2339
+ const localStorageLocation = globalThis.localStorage?.getItem('location');
2340
+ try {
2341
+ return localStorageLocation ? JSON.parse(localStorageLocation) : null;
2342
+ }
2343
+ catch (_) {
2344
+ return null;
2345
+ }
2346
+ };
2324
2347
 
2325
2348
  const REGIONS_URL$1 = '/api/v1/regions';
2326
2349
  function useRegions() {
@@ -2480,15 +2503,10 @@
2480
2503
  const Header = JSX(({ bgColor = 'bg-white', className = '', showSubMenu = true, ...rest }) => {
2481
2504
  const router = useRouter();
2482
2505
  const { topItems, logo, defaultLocation, foreignOffices, officesLink } = useSWRResource(projectSettings.SITEMAP || 'sitemap', rest.options?.page?.fallback);
2483
- const activeTopItem = showSubMenu ? getActiveItem(topItems, router) : null;
2506
+ const activeTopItem = topItems?.find(isTopItemActive(router));
2484
2507
  const topMenu = topItems?.map((_, i) => (jsx(TopItem, { active: _ === activeTopItem, "aria-label": _.text, bgColor: bgColor, ..._ }, String(i))));
2485
2508
  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
2509
  });
2487
- const getActiveItem = (topItems, router) => {
2488
- const [firstPortal] = topItems || [];
2489
- // Если по слагу невозможно понять к какому подпорталу этот слаг относиться, то выбираем первый подпортал.
2490
- return topItems?.find(isTopItemActive(router)) || firstPortal;
2491
- };
2492
2510
 
2493
2511
  const ImgBlock = JSX((props) => {
2494
2512
  const { className, image, ...rest } = props;
@@ -4107,7 +4125,7 @@
4107
4125
  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
4126
  }
4109
4127
 
4110
- const packageVersion = "0.6.43";
4128
+ const packageVersion = "0.6.45";
4111
4129
 
4112
4130
  exports.Blocks = Blocks;
4113
4131
  exports.ContentPage = ContentPage;