@redneckz/wildless-cms-uni-blocks 0.2.63 → 0.2.67

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 (67) hide show
  1. package/dist/Gallery.js +3 -3
  2. package/dist/Gallery.js.map +1 -1
  3. package/dist/Header/isSubItemActive.d.ts +1 -1
  4. package/dist/Header/isSubItemActive.js +2 -4
  5. package/dist/Header/isSubItemActive.js.map +1 -1
  6. package/dist/Header/isTopItemActive.d.ts +1 -1
  7. package/dist/Header/isTopItemActive.js +2 -8
  8. package/dist/Header/isTopItemActive.js.map +1 -1
  9. package/dist/MobileBlocks.d.ts +1 -4
  10. package/dist/MobileBlocks.js +5 -8
  11. package/dist/MobileBlocks.js.map +1 -1
  12. package/dist/Placeholder.js +1 -1
  13. package/dist/Placeholder.js.map +1 -1
  14. package/dist/ProductBlock.mobile.d.ts +5 -0
  15. package/dist/ProductBlock.mobile.js +10 -0
  16. package/dist/ProductBlock.mobile.js.map +1 -0
  17. package/dist/ProductBlockInner.js +4 -2
  18. package/dist/ProductBlockInner.js.map +1 -1
  19. package/dist/ui-kit/ArrowButton.js +1 -1
  20. package/dist/ui-kit/ArrowButton.js.map +1 -1
  21. package/dist/useLink.js +1 -1
  22. package/dist/useLink.js.map +1 -1
  23. package/dist/utils/url.d.ts +13 -1
  24. package/dist/utils/url.js +26 -10
  25. package/dist/utils/url.js.map +1 -1
  26. package/lib/Gallery.js +3 -3
  27. package/lib/Gallery.js.map +1 -1
  28. package/lib/Header/isSubItemActive.d.ts +1 -1
  29. package/lib/Header/isSubItemActive.js +3 -5
  30. package/lib/Header/isSubItemActive.js.map +1 -1
  31. package/lib/Header/isTopItemActive.d.ts +1 -1
  32. package/lib/Header/isTopItemActive.js +3 -9
  33. package/lib/Header/isTopItemActive.js.map +1 -1
  34. package/lib/MobileBlocks.d.ts +1 -4
  35. package/lib/MobileBlocks.js +4 -7
  36. package/lib/MobileBlocks.js.map +1 -1
  37. package/lib/Placeholder.js +1 -1
  38. package/lib/Placeholder.js.map +1 -1
  39. package/lib/ProductBlock.mobile.d.ts +5 -0
  40. package/lib/ProductBlock.mobile.js +8 -0
  41. package/lib/ProductBlock.mobile.js.map +1 -0
  42. package/lib/ProductBlockInner.js +4 -2
  43. package/lib/ProductBlockInner.js.map +1 -1
  44. package/lib/common.css +1 -1
  45. package/lib/ui-kit/ArrowButton.js +1 -1
  46. package/lib/ui-kit/ArrowButton.js.map +1 -1
  47. package/lib/useLink.js +2 -2
  48. package/lib/useLink.js.map +1 -1
  49. package/lib/utils/url.d.ts +13 -1
  50. package/lib/utils/url.js +22 -9
  51. package/lib/utils/url.js.map +1 -1
  52. package/package.json +1 -1
  53. package/src/ContentPage.fixture.tsx +2 -2
  54. package/src/ContentPage.page.json +106 -1
  55. package/src/Gallery.tsx +9 -4
  56. package/src/Header/isSubItemActive.ts +3 -5
  57. package/src/Header/isTopItemActive.ts +4 -9
  58. package/src/MobileBlocks.ts +4 -7
  59. package/src/Placeholder.tsx +1 -1
  60. package/src/ProductBlock.mobile.tsx +19 -0
  61. package/src/ProductBlockInner.tsx +6 -2
  62. package/src/PromoTile.fixture.tsx +25 -0
  63. package/src/setup-fixture.ts +12 -0
  64. package/src/ui-kit/ArrowButton.tsx +1 -2
  65. package/src/useLink.ts +2 -2
  66. package/src/utils/url.spec.ts +53 -0
  67. package/src/utils/url.ts +39 -9
package/src/utils/url.ts CHANGED
@@ -1,22 +1,52 @@
1
+ export const MOBILE_URL_PATH = '/mobile';
2
+
1
3
  export const isURL = (href?: string) => href?.includes('//');
2
4
 
5
+ export const isHrefActive = (
6
+ href: string | undefined,
7
+ router: { pathname?: string; href?: string },
8
+ cmp: (href: string, baseHref: string) => boolean = (href, baseHref) => href === baseHref,
9
+ ) => {
10
+ return cmp(
11
+ withoutQuery(href),
12
+ withoutMobilePath(withoutQuery(isURL(href) ? router.href : router.pathname)),
13
+ );
14
+ };
15
+
3
16
  export const withoutQuery = (href?: string) => (href || '').replace(/\/?\?.*/, '');
4
17
 
18
+ export const withoutMobilePath = (href?: string) => (href || '').replace(MOBILE_URL_PATH, '');
19
+
5
20
  export const getOrigin = (href?: string) => {
6
- if (isURL(href)) {
7
- const url = href!;
8
- const protoSeparator = '://';
9
- const endOfProto = url.indexOf(protoSeparator);
10
- const endOfOrigin = url.indexOf('/', endOfProto + protoSeparator.length);
11
- return endOfOrigin !== -1 ? url.substring(0, endOfOrigin) : url;
21
+ if (!isURL(href)) {
22
+ return undefined;
23
+ }
24
+
25
+ const url = href!;
26
+ const protoSeparator = '//';
27
+ const endOfProto = url.indexOf(protoSeparator);
28
+ const endOfOrigin = url.indexOf('/', endOfProto + protoSeparator.length);
29
+ return endOfOrigin !== -1 ? url.substring(0, endOfOrigin) : url;
30
+ };
31
+
32
+ export const adjustHref = (
33
+ href: string | undefined,
34
+ router: { pathname: string; href?: string },
35
+ ) => {
36
+ if (!href) {
37
+ return href;
12
38
  }
13
- return undefined;
39
+
40
+ const relativeHref = toRelativeHref(href, router)!;
41
+ const isMobilePage = router?.pathname.startsWith(MOBILE_URL_PATH);
42
+ return isMobilePage && !isURL(relativeHref) ? `${MOBILE_URL_PATH}${relativeHref}` : relativeHref;
14
43
  };
15
44
 
16
- export const toRelativeHref = (href?: string, baseURL?: string) => {
45
+ export const toRelativeHref = (href: string | undefined, router: { href?: string }) => {
17
46
  if (!href) {
18
47
  return href;
19
48
  }
20
- const origin = getOrigin(baseURL);
49
+
50
+ const origin = getOrigin(router?.href);
21
51
  return origin ? href.replace(origin, '') || '/' : href;
22
52
  };