@redneckz/wildless-cms-uni-blocks 0.2.64 → 0.2.68

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 (76) hide show
  1. package/dist/Gallery.js +2 -2
  2. package/dist/Gallery.js.map +1 -1
  3. package/dist/Gallery.mobile.d.ts +2 -0
  4. package/dist/Gallery.mobile.js +18 -0
  5. package/dist/Gallery.mobile.js.map +1 -0
  6. package/dist/Header/isSubItemActive.d.ts +1 -1
  7. package/dist/Header/isSubItemActive.js +2 -4
  8. package/dist/Header/isSubItemActive.js.map +1 -1
  9. package/dist/Header/isTopItemActive.d.ts +1 -1
  10. package/dist/Header/isTopItemActive.js +2 -8
  11. package/dist/Header/isTopItemActive.js.map +1 -1
  12. package/dist/MobileBlocks.d.ts +2 -4
  13. package/dist/MobileBlocks.js +7 -8
  14. package/dist/MobileBlocks.js.map +1 -1
  15. package/dist/Placeholder.js +1 -1
  16. package/dist/Placeholder.js.map +1 -1
  17. package/dist/ProductBlock.mobile.d.ts +5 -0
  18. package/dist/ProductBlock.mobile.js +10 -0
  19. package/dist/ProductBlock.mobile.js.map +1 -0
  20. package/dist/ProductBlockInner.js +4 -2
  21. package/dist/ProductBlockInner.js.map +1 -1
  22. package/dist/ui-kit/ArrowButton.js +1 -1
  23. package/dist/ui-kit/ArrowButton.js.map +1 -1
  24. package/dist/useLink.js +1 -1
  25. package/dist/useLink.js.map +1 -1
  26. package/dist/utils/url.d.ts +13 -1
  27. package/dist/utils/url.js +26 -10
  28. package/dist/utils/url.js.map +1 -1
  29. package/lib/Gallery.js +2 -2
  30. package/lib/Gallery.js.map +1 -1
  31. package/lib/Gallery.mobile.d.ts +2 -0
  32. package/lib/Gallery.mobile.js +16 -0
  33. package/lib/Gallery.mobile.js.map +1 -0
  34. package/lib/Header/isSubItemActive.d.ts +1 -1
  35. package/lib/Header/isSubItemActive.js +3 -5
  36. package/lib/Header/isSubItemActive.js.map +1 -1
  37. package/lib/Header/isTopItemActive.d.ts +1 -1
  38. package/lib/Header/isTopItemActive.js +3 -9
  39. package/lib/Header/isTopItemActive.js.map +1 -1
  40. package/lib/MobileBlocks.d.ts +2 -4
  41. package/lib/MobileBlocks.js +6 -7
  42. package/lib/MobileBlocks.js.map +1 -1
  43. package/lib/Placeholder.js +1 -1
  44. package/lib/Placeholder.js.map +1 -1
  45. package/lib/ProductBlock.mobile.d.ts +5 -0
  46. package/lib/ProductBlock.mobile.js +8 -0
  47. package/lib/ProductBlock.mobile.js.map +1 -0
  48. package/lib/ProductBlockInner.js +4 -2
  49. package/lib/ProductBlockInner.js.map +1 -1
  50. package/lib/common.css +1 -1
  51. package/lib/ui-kit/ArrowButton.js +1 -1
  52. package/lib/ui-kit/ArrowButton.js.map +1 -1
  53. package/lib/useLink.js +2 -2
  54. package/lib/useLink.js.map +1 -1
  55. package/lib/utils/url.d.ts +13 -1
  56. package/lib/utils/url.js +22 -9
  57. package/lib/utils/url.js.map +1 -1
  58. package/package.json +1 -1
  59. package/src/ContentPage.fixture.tsx +2 -2
  60. package/src/ContentPage.page.json +106 -1
  61. package/src/Gallery.fixture.tsx +2 -0
  62. package/src/Gallery.mobile.tsx +70 -0
  63. package/src/Gallery.tsx +7 -2
  64. package/src/Header/isSubItemActive.ts +3 -5
  65. package/src/Header/isTopItemActive.ts +4 -9
  66. package/src/MobileBlocks.ts +6 -7
  67. package/src/Placeholder.tsx +1 -1
  68. package/src/ProductBlock.mobile.tsx +19 -0
  69. package/src/ProductBlockInner.tsx +6 -2
  70. package/src/PromoTile.fixture.tsx +25 -0
  71. package/src/common.css +26 -0
  72. package/src/setup-fixture.ts +12 -0
  73. package/src/ui-kit/ArrowButton.tsx +1 -2
  74. package/src/useLink.ts +2 -2
  75. package/src/utils/url.spec.ts +53 -0
  76. package/src/utils/url.ts +39 -9
package/src/common.css CHANGED
@@ -36,4 +36,30 @@
36
36
  .-translate-x-full {
37
37
  transform: translateX(-100%);
38
38
  }
39
+
40
+ /* Chrome, Safari and Opera */
41
+ .no-scrollbar::-webkit-scrollbar {
42
+ display: none;
43
+ }
44
+
45
+ .no-scrollbar {
46
+ -ms-overflow-style: none; /* IE and Edge */
47
+ scrollbar-width: none; /* Firefox */
48
+ }
49
+
50
+ .horizontal-list {
51
+ display: flex;
52
+ overflow-x: scroll;
53
+ overscroll-behavior: contain;
54
+ -webkit-overflow-scrolling: touch;
55
+ touch-action: pan-x;
56
+ scroll-snap-type: x mandatory;
57
+ }
58
+
59
+ .horizontal-list-item {
60
+ flex-shrink: 0;
61
+ scroll-snap-align: start;
62
+ scroll-snap-stop: always;
63
+ width: 100%;
64
+ }
39
65
  }
@@ -70,3 +70,15 @@ export const context: ContentPageContext = {
70
70
  };
71
71
  },
72
72
  };
73
+
74
+ export const mobileContext: ContentPageContext = {
75
+ ...context,
76
+ useRouter: () => ({
77
+ href: `${TEST_ORIGIN}/mobile/credits`,
78
+ pathname: '/mobile/credits',
79
+ query: {},
80
+ push: (url: string) => {
81
+ console.log(url);
82
+ },
83
+ }),
84
+ };
@@ -1,5 +1,4 @@
1
1
  import { JSX } from '@redneckz/uni-jsx';
2
- import { Icon } from './Icon';
3
2
 
4
3
  export interface ArrowButtonProps {
5
4
  onClick?: () => void;
@@ -23,7 +22,7 @@ export const ArrowButton = JSX<ArrowButtonProps>(({ className, onClick, ariaLabe
23
22
  fill="none"
24
23
  xmlns="http://www.w3.org/2000/svg"
25
24
  >
26
- <path d="M7 12L3 8L7 4" stroke="currentColor" stroke-width="2" stroke-linecap="round" />
25
+ <path d="M7 12L3 8L7 4" stroke="currentColor" strokeWidth="2" strokeLinecap="round" />
27
26
  <path
28
27
  d="M14 9C14.5523 9 15 8.55228 15 8C15 7.44772 14.5523 7 14 7L14 9ZM8 7C7.44772 7 7 7.44772 7 8C7 8.55229 7.44772 9 8 9L8 7ZM14 7L8 7L8 9L14 9L14 7Z"
29
28
  fill="currentColor"
package/src/useLink.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { HandlerDecorator, Router } from './ContentPageContext';
2
2
  import type { LinkContent } from './types';
3
- import { isURL, toRelativeHref } from './utils/url';
3
+ import { adjustHref, isURL } from './utils/url';
4
4
 
5
5
  const defaultHandlerDecorator: HandlerDecorator = (handler, targetContent) => handler;
6
6
 
@@ -11,7 +11,7 @@ export function useLink(
11
11
  }: { router: Router; handlerDecorator?: HandlerDecorator },
12
12
  link: Partial<LinkContent>,
13
13
  ) {
14
- const href = toRelativeHref(link.href, router.href);
14
+ const href = adjustHref(link.href, router);
15
15
  return {
16
16
  ...link,
17
17
  href,
@@ -0,0 +1,53 @@
1
+ import { adjustHref, getOrigin, toRelativeHref, withoutQuery } from './url';
2
+
3
+ describe('url', () => {
4
+ describe('withoutQuery', () => {
5
+ it('should return URL without query params', () => {
6
+ expect(withoutQuery('http://foo.ru/other/path?first=1&second=2')).toBe(
7
+ 'http://foo.ru/other/path',
8
+ );
9
+ });
10
+ });
11
+
12
+ describe('getOrigin', () => {
13
+ it('should return origin of specified URL', () => {
14
+ expect(getOrigin('http://foo.ru/other/path?first=1&second=2')).toBe('http://foo.ru');
15
+ });
16
+ });
17
+
18
+ describe('adjustHref', () => {
19
+ it('should compute URL relative to some base URL', () => {
20
+ expect(
21
+ adjustHref('http://foo.ru/other/path', {
22
+ pathname: '/some/path',
23
+ href: 'http://foo.ru/some/path',
24
+ }),
25
+ ).toBe('/other/path');
26
+ });
27
+
28
+ it('should compute mobile URL for mobile pages', () => {
29
+ expect(
30
+ adjustHref('http://foo.ru/other/path', {
31
+ pathname: '/mobile/some/path',
32
+ href: 'http://foo.ru/mobile/some/path',
33
+ }),
34
+ ).toBe('/mobile/other/path');
35
+ });
36
+
37
+ it('should return nothing if nothing provided', () => {
38
+ expect(adjustHref(undefined, { pathname: '/mobile/some/path' })).toBe(undefined);
39
+ });
40
+ });
41
+
42
+ describe('toRelativeHref', () => {
43
+ it('should compute URL relative to some base URL', () => {
44
+ expect(toRelativeHref('http://foo.ru/other/path', { href: 'http://foo.ru/some/path' })).toBe(
45
+ '/other/path',
46
+ );
47
+ });
48
+
49
+ it('should return nothing if nothing provided', () => {
50
+ expect(toRelativeHref(undefined, {})).toBe(undefined);
51
+ });
52
+ });
53
+ });
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
  };