@redneckz/wildless-cms-uni-blocks 0.8.10 → 0.8.11

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 (141) hide show
  1. package/bundle/bundle.umd.js +73 -91
  2. package/bundle/bundle.umd.min.js +1 -1
  3. package/bundle/services/BlockRouter/BlockRouter.d.ts +1 -3
  4. package/bundle/ui-kit/Img/ImgAsPicture.d.ts +0 -2
  5. package/bundle/utils/adjustHref.d.ts +3 -0
  6. package/bundle/utils/dirname.d.ts +1 -0
  7. package/bundle/utils/url.d.ts +2 -2
  8. package/dist/ProjectSettings.js +3 -4
  9. package/dist/ProjectSettings.js.map +1 -1
  10. package/dist/hooks/useLink.js +4 -16
  11. package/dist/hooks/useLink.js.map +1 -1
  12. package/dist/services/BlockRouter/BlockRouter.d.ts +1 -3
  13. package/dist/services/BlockRouter/BlockRouter.js +3 -9
  14. package/dist/services/BlockRouter/BlockRouter.js.map +1 -1
  15. package/dist/services/BlockRouter/useBlockRouterProvider.js +2 -10
  16. package/dist/services/BlockRouter/useBlockRouterProvider.js.map +1 -1
  17. package/dist/setup-fixture.js +3 -4
  18. package/dist/setup-fixture.js.map +1 -1
  19. package/dist/ui-kit/Icon/Icon.js +5 -1
  20. package/dist/ui-kit/Icon/Icon.js.map +1 -1
  21. package/dist/ui-kit/Img/ImgAsPicture.d.ts +0 -2
  22. package/dist/ui-kit/Img/ImgAsPicture.js +18 -21
  23. package/dist/ui-kit/Img/ImgAsPicture.js.map +1 -1
  24. package/dist/utils/adjustHref.d.ts +3 -0
  25. package/dist/utils/adjustHref.js +14 -0
  26. package/dist/utils/adjustHref.js.map +1 -0
  27. package/dist/utils/dirname.d.ts +1 -0
  28. package/dist/utils/dirname.js +5 -0
  29. package/dist/utils/dirname.js.map +1 -0
  30. package/dist/utils/url.d.ts +2 -2
  31. package/dist/utils/url.js +1 -1
  32. package/dist/utils/url.js.map +1 -1
  33. package/dist/wlc.json +0 -1
  34. package/lib/ProjectSettings.js +3 -4
  35. package/lib/ProjectSettings.js.map +1 -1
  36. package/lib/hooks/useLink.js +5 -17
  37. package/lib/hooks/useLink.js.map +1 -1
  38. package/lib/services/BlockRouter/BlockRouter.d.ts +1 -3
  39. package/lib/services/BlockRouter/BlockRouter.js +2 -7
  40. package/lib/services/BlockRouter/BlockRouter.js.map +1 -1
  41. package/lib/services/BlockRouter/useBlockRouterProvider.js +2 -10
  42. package/lib/services/BlockRouter/useBlockRouterProvider.js.map +1 -1
  43. package/lib/setup-fixture.js +3 -4
  44. package/lib/setup-fixture.js.map +1 -1
  45. package/lib/ui-kit/Icon/Icon.js +5 -1
  46. package/lib/ui-kit/Icon/Icon.js.map +1 -1
  47. package/lib/ui-kit/Img/ImgAsPicture.d.ts +0 -2
  48. package/lib/ui-kit/Img/ImgAsPicture.js +17 -19
  49. package/lib/ui-kit/Img/ImgAsPicture.js.map +1 -1
  50. package/lib/utils/adjustHref.d.ts +3 -0
  51. package/lib/utils/adjustHref.js +11 -0
  52. package/lib/utils/adjustHref.js.map +1 -0
  53. package/lib/utils/dirname.d.ts +1 -0
  54. package/lib/utils/dirname.js +2 -0
  55. package/lib/utils/dirname.js.map +1 -0
  56. package/lib/utils/url.d.ts +2 -2
  57. package/lib/utils/url.js +1 -1
  58. package/lib/utils/url.js.map +1 -1
  59. package/lib/wlc.json +0 -1
  60. package/mobile/bundle/bundle.umd.js +73 -91
  61. package/mobile/bundle/bundle.umd.min.js +1 -1
  62. package/mobile/bundle/services/BlockRouter/BlockRouter.d.ts +1 -3
  63. package/mobile/bundle/ui-kit/Img/ImgAsPicture.d.ts +0 -2
  64. package/mobile/bundle/utils/adjustHref.d.ts +3 -0
  65. package/mobile/bundle/utils/dirname.d.ts +1 -0
  66. package/mobile/bundle/utils/url.d.ts +2 -2
  67. package/mobile/dist/ProjectSettings.js +3 -4
  68. package/mobile/dist/ProjectSettings.js.map +1 -1
  69. package/mobile/dist/hooks/useLink.js +4 -16
  70. package/mobile/dist/hooks/useLink.js.map +1 -1
  71. package/mobile/dist/services/BlockRouter/BlockRouter.d.ts +1 -3
  72. package/mobile/dist/services/BlockRouter/BlockRouter.js +3 -9
  73. package/mobile/dist/services/BlockRouter/BlockRouter.js.map +1 -1
  74. package/mobile/dist/services/BlockRouter/useBlockRouterProvider.js +2 -10
  75. package/mobile/dist/services/BlockRouter/useBlockRouterProvider.js.map +1 -1
  76. package/mobile/dist/setup-fixture.js +3 -4
  77. package/mobile/dist/setup-fixture.js.map +1 -1
  78. package/mobile/dist/ui-kit/Icon/Icon.js +5 -1
  79. package/mobile/dist/ui-kit/Icon/Icon.js.map +1 -1
  80. package/mobile/dist/ui-kit/Img/ImgAsPicture.d.ts +0 -2
  81. package/mobile/dist/ui-kit/Img/ImgAsPicture.js +18 -21
  82. package/mobile/dist/ui-kit/Img/ImgAsPicture.js.map +1 -1
  83. package/mobile/dist/utils/adjustHref.d.ts +3 -0
  84. package/mobile/dist/utils/adjustHref.js +14 -0
  85. package/mobile/dist/utils/adjustHref.js.map +1 -0
  86. package/mobile/dist/utils/dirname.d.ts +1 -0
  87. package/mobile/dist/utils/dirname.js +5 -0
  88. package/mobile/dist/utils/dirname.js.map +1 -0
  89. package/mobile/dist/utils/url.d.ts +2 -2
  90. package/mobile/dist/utils/url.js +1 -1
  91. package/mobile/dist/utils/url.js.map +1 -1
  92. package/mobile/dist/wlc.json +0 -1
  93. package/mobile/lib/ProjectSettings.js +3 -4
  94. package/mobile/lib/ProjectSettings.js.map +1 -1
  95. package/mobile/lib/hooks/useLink.js +5 -17
  96. package/mobile/lib/hooks/useLink.js.map +1 -1
  97. package/mobile/lib/services/BlockRouter/BlockRouter.d.ts +1 -3
  98. package/mobile/lib/services/BlockRouter/BlockRouter.js +2 -7
  99. package/mobile/lib/services/BlockRouter/BlockRouter.js.map +1 -1
  100. package/mobile/lib/services/BlockRouter/useBlockRouterProvider.js +2 -10
  101. package/mobile/lib/services/BlockRouter/useBlockRouterProvider.js.map +1 -1
  102. package/mobile/lib/setup-fixture.js +3 -4
  103. package/mobile/lib/setup-fixture.js.map +1 -1
  104. package/mobile/lib/ui-kit/Icon/Icon.js +5 -1
  105. package/mobile/lib/ui-kit/Icon/Icon.js.map +1 -1
  106. package/mobile/lib/ui-kit/Img/ImgAsPicture.d.ts +0 -2
  107. package/mobile/lib/ui-kit/Img/ImgAsPicture.js +17 -19
  108. package/mobile/lib/ui-kit/Img/ImgAsPicture.js.map +1 -1
  109. package/mobile/lib/utils/adjustHref.d.ts +3 -0
  110. package/mobile/lib/utils/adjustHref.js +11 -0
  111. package/mobile/lib/utils/adjustHref.js.map +1 -0
  112. package/mobile/lib/utils/dirname.d.ts +1 -0
  113. package/mobile/lib/utils/dirname.js +2 -0
  114. package/mobile/lib/utils/dirname.js.map +1 -0
  115. package/mobile/lib/utils/url.d.ts +2 -2
  116. package/mobile/lib/utils/url.js +1 -1
  117. package/mobile/lib/utils/url.js.map +1 -1
  118. package/mobile/lib/wlc.json +0 -1
  119. package/mobile/src/ProjectSettings.ts +4 -4
  120. package/mobile/src/hooks/useLink.ts +5 -18
  121. package/mobile/src/services/BlockRouter/BlockRouter.ts +6 -9
  122. package/mobile/src/services/BlockRouter/useBlockRouterProvider.ts +4 -10
  123. package/mobile/src/setup-fixture.ts +5 -4
  124. package/mobile/src/ui-kit/Icon/Icon.tsx +5 -1
  125. package/mobile/src/ui-kit/Img/ImgAsPicture.tsx +23 -28
  126. package/mobile/src/utils/adjustHref.ts +17 -0
  127. package/mobile/src/utils/dirname.ts +1 -0
  128. package/mobile/src/utils/url.ts +2 -3
  129. package/mobile/src/wlc.json +0 -1
  130. package/package.json +1 -1
  131. package/src/ProjectSettings.ts +4 -4
  132. package/src/hooks/useLink.ts +5 -18
  133. package/src/services/BlockRouter/BlockRouter.ts +6 -9
  134. package/src/services/BlockRouter/useBlockRouterProvider.ts +4 -10
  135. package/src/setup-fixture.ts +5 -4
  136. package/src/ui-kit/Icon/Icon.tsx +5 -1
  137. package/src/ui-kit/Img/ImgAsPicture.tsx +23 -28
  138. package/src/utils/adjustHref.ts +17 -0
  139. package/src/utils/dirname.ts +1 -0
  140. package/src/utils/url.ts +2 -3
  141. package/src/wlc.json +0 -1
@@ -81,12 +81,10 @@
81
81
  return this._.FOOTER;
82
82
  }
83
83
  get CDN() {
84
- return this._.CDN;
84
+ return appendSlash(this._.CDN);
85
85
  }
86
86
  get BASE_PATH() {
87
- return this._.BASE_PATH && !this._.BASE_PATH.endsWith('/')
88
- ? `${this._.BASE_PATH}/`
89
- : this._.BASE_PATH;
87
+ return appendSlash(this._.BASE_PATH);
90
88
  }
91
89
  get YANDEX_MAP_API_KEY() {
92
90
  return this._.YANDEX_MAP_API_KEY;
@@ -95,6 +93,7 @@
95
93
  return this._.YANDEX_METRIKA_ID;
96
94
  }
97
95
  })();
96
+ const appendSlash = (url) => (url && !url.endsWith('/') ? `${url}/` : url);
98
97
 
99
98
  const AUTH_PREFIX = 'guest';
100
99
  const STORAGE_KEY = 'likesToken';
@@ -419,6 +418,49 @@
419
418
  return (jsx("div", { ref: containerRef, className: `transition-max-h duration-300 overflow-hidden ${containerRef.current || !isUnfolded ? 'max-h-0' : ''} ${className}`, children: children }));
420
419
  });
421
420
 
421
+ function useRouter() {
422
+ return useRouter._impl();
423
+ }
424
+ useRouter._impl = () => ({
425
+ href: globalThis.location?.href || '/',
426
+ pathname: globalThis.location?.pathname || '/',
427
+ query: {},
428
+ push: () => {
429
+ // Do nothing
430
+ },
431
+ replace: () => {
432
+ // Do nothing
433
+ },
434
+ });
435
+ useRouter.setup = (impl) => {
436
+ useRouter._impl = impl;
437
+ };
438
+
439
+ const dirname = (path) => path?.split('/').slice(0, -1).join('/');
440
+
441
+ const isURL = (href) => Boolean(href?.includes(':'));
442
+ const isLocalURL = (href, target) => Boolean(href && !isURL(href) && (!target || target === '_self'));
443
+ const isHash = (href) => Boolean(href?.startsWith('#'));
444
+ const withoutQuery = (href) => (href || '').replace(/\?.*/, '').replace(/\/$/, '');
445
+ const joinPath = (...path) => path.filter(Boolean).join('/').replace(/\/+/g, '/');
446
+
447
+ var url = /*#__PURE__*/Object.freeze({
448
+ __proto__: null,
449
+ isURL: isURL,
450
+ isLocalURL: isLocalURL,
451
+ isHash: isHash,
452
+ withoutQuery: withoutQuery,
453
+ joinPath: joinPath
454
+ });
455
+
456
+ const adjustHref = (router) => (href) => {
457
+ if (!href || isURL(href) || (projectSettings.CDN && href.startsWith(projectSettings.CDN))) {
458
+ return href;
459
+ }
460
+ const isRelativeToBase = href.startsWith('/');
461
+ return joinPath(projectSettings.BASE_PATH, isRelativeToBase ? '/' : dirname(router.pathname), href);
462
+ };
463
+
422
464
  const svgUseStyleMap = {
423
465
  normal: '',
424
466
  color: 'text-primary-main',
@@ -426,7 +468,8 @@
426
468
  white: 'text-black',
427
469
  };
428
470
  const Icon = JSX(({ className = '', imageClassName = '', name = '', alt = `Иконка ${name}`, title = alt, iconVersion = 'color', asSVG, ...imgProps }) => {
429
- const href = `${projectSettings.CDN || ''}icons/${name}.svg`;
471
+ const router = useRouter();
472
+ const href = adjustHref(router)(joinPath(projectSettings.CDN, '/icons', `${name}.svg`));
430
473
  if (asSVG && iconVersion !== 'normal') {
431
474
  return (jsx(Background, { className: className, children: jsxs("svg", { className: style(getSvgSize(imgProps.width), svgUseStyleMap[iconVersion], iconVersion === 'white' ? 'invert' : '', imageClassName), ...imgProps, "aria-hidden": "true", children: [title ? jsx("title", { children: title }) : null, alt ? jsx("desc", { children: alt }) : null, jsx("use", { href: `${href}#icon`, xlinkHref: `${href}#icon` })] }) }));
432
475
  }
@@ -435,22 +478,18 @@
435
478
  const getSvgSize = (width) => (width ? '' : 'w-full h-full');
436
479
  const Background = JSX(({ className, children }) => className ? jsx("div", { className: className, children: children }) : children);
437
480
 
438
- const sourcesComparator = (a, b) => {
439
- if (a.media && b.media) {
440
- return a.media - b.media;
441
- }
442
- return 0;
443
- };
481
+ const sourcesComparator = (a, b) => a?.media && b?.media ? a.media - b.media : 0;
444
482
  const ImgAsPicture = JSX(({ className = '', image, imageClassName = '', isMobile = false, pathPrefix }) => {
445
- if (!image || (!image?.sources && !image?.src)) {
446
- return null;
447
- }
483
+ const router = useRouter();
448
484
  const pictureStyles = isMobile ? 'flex' : 'flex-none';
449
485
  return (jsxs("picture", { className: `${pictureStyles} ${className}`, children: [image?.sources?.length
450
486
  ? image.sources
487
+ .filter((_) => _?.src)
451
488
  .sort(sourcesComparator)
452
- .map(({ src, format, media }, index) => (jsx("source", { srcSet: addPathPrefixToSrcSet(src, pathPrefix), type: formatToMimeType(format), media: media ? `(max-width: ${media}px)` : '', ...image.size }, `${index}_${src}`)))
453
- : null, renderImg({ ...image, src: addPathPrefixToSrc(image.src, pathPrefix) }, imageClassName, isMobile)] }));
489
+ .map(({ src, format, media }, index) => (jsx("source", { srcSet: adjustSrcset(router, pathPrefix)(src), type: formatToMimeType(format), media: media ? `(max-width: ${media}px)` : '', ...image.size }, `${index}_${src}`)))
490
+ : null, image?.src
491
+ ? renderImg({ ...image, src: adjustSrcset(router, pathPrefix)(image.src) }, imageClassName, isMobile)
492
+ : null] }));
454
493
  });
455
494
  const renderImg = (image, imageClassName = '', isMobile = false) => {
456
495
  const style = {
@@ -462,15 +501,14 @@
462
501
  const imgStyle = isMobile ? 'm-auto' : 'm-0';
463
502
  return (jsx("img", { src: image.src, className: `${imgStyle} ${imageClassName}`, alt: alt, title: title, style: style, ...image.size }));
464
503
  };
465
- const normalizePathPrefix = (pathPrefix = '') => pathPrefix && !pathPrefix.endsWith('/') ? `${pathPrefix}/` : pathPrefix;
466
- const addPathPrefixToSrc = (src, pathPrefix) => !src || src?.startsWith('data:image') ? src : `${normalizePathPrefix(pathPrefix)}${src}`;
467
- const addPathPrefixToSrcSet = (srcset, pathPrefix) => srcset
468
- ?.split(',')
469
- .map((src) => addPathPrefixToSrc(src.trim(), pathPrefix))
504
+ const adjustSrcset = (router, pathPrefix) => (srcset) => srcset
505
+ ?.split(/\s*,\s*/)
506
+ .map((src) => src.trim())
507
+ .filter(Boolean)
508
+ .map((src) => (isURL(src) ? src : joinPath(pathPrefix, src)))
509
+ .map(adjustHref(router))
470
510
  .join(', ');
471
- function formatToMimeType(format) {
472
- return format ? `image/${String(format)}` : undefined;
473
- }
511
+ const formatToMimeType = (format) => format ? `image/${String(format)}` : undefined;
474
512
 
475
513
  const ImgInner = JSX(({ className = '', image, imageClassName = '', isMobile, pathPrefix, ...iconProps }) => {
476
514
  if (!image?.src && !image?.icon) {
@@ -614,31 +652,6 @@
614
652
  },
615
653
  ];
616
654
 
617
- const normalizeAnchor = (anchor) => anchor?.replace('#', '') || '';
618
- function gotoBlock(router, anchor) {
619
- router.replace(`#${normalizeAnchor(anchor)}`);
620
- }
621
- function trackBlock(router, block) {
622
- router.replace(`#${normalizeAnchor(block?.anchor)}`, undefined, {
623
- scroll: false,
624
- });
625
- }
626
-
627
- const isURL = (href) => Boolean(href?.includes('//'));
628
- const isLocalURL = (href, target) => Boolean(href && !isURL(href) && (!target || target === '_self'));
629
- const isHash = (href) => Boolean(href?.startsWith('#'));
630
- const withoutQuery = (href) => (href || '').replace(/\?.*/, '').replace(/\/$/, '');
631
- const joinPath = (...path) => path.filter(Boolean).join('/').replace(/\/+/g, '/');
632
-
633
- var url = /*#__PURE__*/Object.freeze({
634
- __proto__: null,
635
- isURL: isURL,
636
- isLocalURL: isLocalURL,
637
- isHash: isHash,
638
- withoutQuery: withoutQuery,
639
- joinPath: joinPath
640
- });
641
-
642
655
  /* eslint-disable @typescript-eslint/ban-types */
643
656
  const handlerDecorator = (handler, targetContent) => {
644
657
  return handlerDecorator._impl(handler, targetContent);
@@ -648,53 +661,24 @@
648
661
  handlerDecorator._impl = impl;
649
662
  };
650
663
 
651
- function useRouter() {
652
- return useRouter._impl();
653
- }
654
- useRouter._impl = () => ({
655
- href: globalThis.location?.href || '/',
656
- pathname: globalThis.location?.pathname || '/',
657
- query: {},
658
- push: () => {
659
- // Do nothing
660
- },
661
- replace: () => {
662
- // Do nothing
663
- },
664
- });
665
- useRouter.setup = (impl) => {
666
- useRouter._impl = impl;
667
- };
668
-
669
664
  function useLink(isRemote) {
670
665
  const router = useRouter();
671
666
  return (props) => ({
672
667
  ...props,
673
- href: adjustHref(props.href),
668
+ href: isRemote ? props.href : adjustHref(router)(props.href),
674
669
  'aria-label': props.text,
675
670
  onClick: handlerDecorator(handleHref(props), props),
676
671
  });
677
- function adjustHref(href) {
678
- const isRelativeToBase = !isRemote && href?.startsWith('/');
679
- return projectSettings.BASE_PATH && href && isRelativeToBase
680
- ? joinPath(projectSettings.BASE_PATH, href)
681
- : href;
682
- }
683
672
  function handleHref({ href, target, onClick }) {
684
673
  return (ev) => {
685
674
  onClick && onClick(ev);
686
- if (isRemote || !isLocalURL(href, target)) {
675
+ if (!href || isRemote || !isLocalURL(href, target)) {
687
676
  // Default routing
688
677
  return;
689
678
  }
690
679
  // Client routing
691
680
  ev?.preventDefault();
692
- if (isHash(href)) {
693
- gotoBlock(router, href);
694
- }
695
- else if (href) {
696
- router.push(href);
697
- }
681
+ router.push(href);
698
682
  };
699
683
  }
700
684
  }
@@ -4449,6 +4433,11 @@
4449
4433
  return debouncedCallback;
4450
4434
  };
4451
4435
 
4436
+ const normalizeAnchor = (anchor) => anchor?.replace('#', '') || '';
4437
+ function trackBlock(block) {
4438
+ globalThis.history?.replaceState(globalThis.history?.state, '', `#${normalizeAnchor(block?.anchor)}`);
4439
+ }
4440
+
4452
4441
  const SPECIAL_BLOCK_TYPES = ['Header', 'Footer'];
4453
4442
  const EPS = 0.01;
4454
4443
  const topLineDelta = ([, { target }]) => Math.abs(target.getBoundingClientRect().top);
@@ -4462,7 +4451,6 @@
4462
4451
 
4463
4452
  const isScrolledEnough = () => globalThis.scrollY > (globalThis.innerHeight * 3) / 4;
4464
4453
  function useBlockRouterProvider(scrollTarget = globalThis) {
4465
- const router = useRouter();
4466
4454
  const intersectionsMapRef = useRef(new Map());
4467
4455
  useEffect(() => blockRouterEventBus.subscribe('intersection', ({ block, intersection }) => {
4468
4456
  if (intersectionsMapRef.current) {
@@ -4471,20 +4459,14 @@
4471
4459
  }), []);
4472
4460
  useEffect(() => {
4473
4461
  const handleScroll = debounce(() => {
4474
- if (isScrolledEnough()) {
4475
- const activeBlock = findActiveBlock([...(intersectionsMapRef.current || [])]);
4476
- trackBlock(router, activeBlock);
4477
- }
4478
- else {
4479
- trackBlock(router);
4480
- }
4462
+ trackBlock(isScrolledEnough() ? findActiveBlock([...(intersectionsMapRef.current || [])]) : undefined);
4481
4463
  }, 100);
4482
4464
  scrollTarget.addEventListener('scroll', handleScroll);
4483
4465
  return () => {
4484
4466
  handleScroll.dispose();
4485
4467
  scrollTarget.removeEventListener('scroll', handleScroll);
4486
4468
  };
4487
- }, [router, scrollTarget]);
4469
+ }, [scrollTarget]);
4488
4470
  }
4489
4471
 
4490
4472
  const api = LikeAPI();
@@ -4555,7 +4537,7 @@
4555
4537
  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" }) }));
4556
4538
  }
4557
4539
 
4558
- const packageVersion = "0.8.10";
4540
+ const packageVersion = "0.8.11";
4559
4541
 
4560
4542
  exports.Blocks = Blocks;
4561
4543
  exports.ContentPage = ContentPage;