@gravity-ui/page-constructor 1.16.3 → 1.17.0

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 (75) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/build/cjs/components/BackLink/__tests__/BackLink.test.d.ts +1 -0
  3. package/build/cjs/components/BackLink/__tests__/BackLink.test.js +63 -0
  4. package/build/cjs/components/OverflowScroller/OverflowScroller.css +16 -5
  5. package/build/cjs/components/OverflowScroller/OverflowScroller.d.ts +1 -1
  6. package/build/cjs/components/OverflowScroller/OverflowScroller.js +13 -5
  7. package/build/cjs/models/constructor-items/sub-blocks.d.ts +1 -0
  8. package/build/cjs/models/navigation.d.ts +9 -3
  9. package/build/cjs/models/navigation.js +1 -0
  10. package/build/cjs/navigation/components/Header/Header.css +2 -2
  11. package/build/cjs/navigation/components/Header/Header.js +1 -1
  12. package/build/cjs/navigation/components/NavigationItem/NavigationItem.css +0 -35
  13. package/build/cjs/navigation/components/NavigationItem/NavigationItem.js +9 -39
  14. package/build/cjs/navigation/components/NavigationItem/components/ContentWrapper/ContentWrapper.css +7 -0
  15. package/build/cjs/navigation/components/NavigationItem/components/ContentWrapper/ContentWrapper.d.ts +6 -0
  16. package/build/cjs/navigation/components/NavigationItem/components/ContentWrapper/ContentWrapper.js +12 -0
  17. package/build/cjs/navigation/components/NavigationItem/components/GithubStars/GithubStars.css +10 -0
  18. package/build/cjs/navigation/components/NavigationItem/components/GithubStars/GithubStars.d.ts +5 -0
  19. package/build/cjs/navigation/components/NavigationItem/components/GithubStars/GithubStars.js +11 -0
  20. package/build/cjs/navigation/components/NavigationItem/components/NavigationButton/NavigationButton.css +3 -0
  21. package/build/cjs/navigation/components/NavigationItem/components/NavigationButton/NavigationButton.d.ts +6 -0
  22. package/build/cjs/navigation/components/NavigationItem/components/NavigationButton/NavigationButton.js +15 -0
  23. package/build/cjs/navigation/components/NavigationItem/components/NavigationDropdown/NavigationDropdown.css +4 -0
  24. package/build/cjs/navigation/components/NavigationItem/components/NavigationDropdown/NavigationDropdown.d.ts +6 -0
  25. package/build/cjs/navigation/components/NavigationItem/components/NavigationDropdown/NavigationDropdown.js +19 -0
  26. package/build/cjs/navigation/components/NavigationItem/components/NavigationLink/NavigationLink.css +21 -0
  27. package/build/cjs/navigation/components/NavigationItem/components/NavigationLink/NavigationLink.d.ts +6 -0
  28. package/build/cjs/navigation/components/NavigationItem/components/NavigationLink/NavigationLink.js +30 -0
  29. package/build/cjs/sub-blocks/BasicCard/BasicCard.js +2 -2
  30. package/build/cjs/sub-blocks/BasicCard/schema.d.ts +4 -0
  31. package/build/cjs/sub-blocks/BasicCard/schema.js +4 -1
  32. package/build/cjs/utils/url.d.ts +1 -0
  33. package/build/cjs/utils/url.js +13 -10
  34. package/build/cjs/utils/url.test.d.ts +1 -0
  35. package/build/cjs/utils/url.test.js +76 -0
  36. package/build/esm/components/BackLink/__tests__/BackLink.test.d.ts +1 -0
  37. package/build/esm/components/BackLink/__tests__/BackLink.test.js +60 -0
  38. package/build/esm/components/OverflowScroller/OverflowScroller.css +16 -5
  39. package/build/esm/components/OverflowScroller/OverflowScroller.d.ts +1 -1
  40. package/build/esm/components/OverflowScroller/OverflowScroller.js +13 -5
  41. package/build/esm/models/constructor-items/sub-blocks.d.ts +1 -0
  42. package/build/esm/models/navigation.d.ts +9 -3
  43. package/build/esm/models/navigation.js +1 -0
  44. package/build/esm/navigation/components/Header/Header.css +2 -2
  45. package/build/esm/navigation/components/Header/Header.js +1 -1
  46. package/build/esm/navigation/components/NavigationItem/NavigationItem.css +0 -35
  47. package/build/esm/navigation/components/NavigationItem/NavigationItem.js +9 -39
  48. package/build/esm/navigation/components/NavigationItem/components/ContentWrapper/ContentWrapper.css +7 -0
  49. package/build/esm/navigation/components/NavigationItem/components/ContentWrapper/ContentWrapper.d.ts +7 -0
  50. package/build/esm/navigation/components/NavigationItem/components/ContentWrapper/ContentWrapper.js +8 -0
  51. package/build/esm/navigation/components/NavigationItem/components/GithubStars/GithubStars.css +10 -0
  52. package/build/esm/navigation/components/NavigationItem/components/GithubStars/GithubStars.d.ts +6 -0
  53. package/build/esm/navigation/components/NavigationItem/components/GithubStars/GithubStars.js +7 -0
  54. package/build/esm/navigation/components/NavigationItem/components/NavigationButton/NavigationButton.css +3 -0
  55. package/build/esm/navigation/components/NavigationItem/components/NavigationButton/NavigationButton.d.ts +7 -0
  56. package/build/esm/navigation/components/NavigationItem/components/NavigationButton/NavigationButton.js +11 -0
  57. package/build/esm/navigation/components/NavigationItem/components/NavigationDropdown/NavigationDropdown.css +4 -0
  58. package/build/esm/navigation/components/NavigationItem/components/NavigationDropdown/NavigationDropdown.d.ts +7 -0
  59. package/build/esm/navigation/components/NavigationItem/components/NavigationDropdown/NavigationDropdown.js +16 -0
  60. package/build/esm/navigation/components/NavigationItem/components/NavigationLink/NavigationLink.css +21 -0
  61. package/build/esm/navigation/components/NavigationItem/components/NavigationLink/NavigationLink.d.ts +7 -0
  62. package/build/esm/navigation/components/NavigationItem/components/NavigationLink/NavigationLink.js +27 -0
  63. package/build/esm/sub-blocks/BasicCard/BasicCard.js +3 -2
  64. package/build/esm/sub-blocks/BasicCard/schema.d.ts +4 -0
  65. package/build/esm/sub-blocks/BasicCard/schema.js +4 -1
  66. package/build/esm/utils/url.d.ts +1 -0
  67. package/build/esm/utils/url.js +11 -9
  68. package/build/esm/utils/url.test.d.ts +1 -0
  69. package/build/esm/utils/url.test.js +74 -0
  70. package/package.json +2 -1
  71. package/server/models/constructor-items/sub-blocks.d.ts +1 -0
  72. package/server/models/navigation.d.ts +9 -3
  73. package/server/models/navigation.js +1 -0
  74. package/server/utils/url.d.ts +1 -0
  75. package/server/utils/url.js +13 -10
@@ -0,0 +1,27 @@
1
+ import { __rest } from "tslib";
2
+ import React, { Fragment, useContext } from 'react';
3
+ import { ContentWrapper } from '../ContentWrapper/ContentWrapper';
4
+ import { NavigationArrow } from '../../../../../icons';
5
+ import { RouterLink } from '../../../../../components';
6
+ import { block, getLinkProps } from '../../../../../utils';
7
+ import { getMediaImage } from '../../../../../components/Media/Image/utils';
8
+ import { LocationContext } from '../../../../../context/locationContext';
9
+ import './NavigationLink.css';
10
+ const b = block('navigation-link');
11
+ export const NavigationLink = (props) => {
12
+ const { hostname, Link } = useContext(LocationContext);
13
+ const { url, text, icon, arrow, target, className } = props, rest = __rest(props, ["url", "text", "icon", "arrow", "target", "className"]);
14
+ const linkExtraProps = getLinkProps(url, hostname, target);
15
+ const iconData = icon && getMediaImage(icon);
16
+ const classes = b(null, className);
17
+ const content = (React.createElement(Fragment, null,
18
+ React.createElement(ContentWrapper, { text: text, icon: iconData }),
19
+ arrow && React.createElement(NavigationArrow, { className: b('arrow') })));
20
+ if ((linkExtraProps === null || linkExtraProps === void 0 ? void 0 : linkExtraProps.target) || !Link) {
21
+ return (React.createElement("a", Object.assign({ href: url, title: text, className: classes }, rest, linkExtraProps), content));
22
+ }
23
+ else {
24
+ return (React.createElement(RouterLink, { href: url, passHref: true },
25
+ React.createElement("a", Object.assign({}, rest, { className: classes }), content)));
26
+ }
27
+ };
@@ -1,3 +1,4 @@
1
+ import { __rest } from "tslib";
1
2
  import React from 'react';
2
3
  import { block } from '../../utils';
3
4
  import CardBase from '../../components/CardBase/CardBase';
@@ -7,9 +8,9 @@ import { getMediaImage } from '../../components/Media/Image/utils';
7
8
  import './BasicCard.css';
8
9
  const b = block('basic-card');
9
10
  const BasicCard = (props) => {
10
- const { url, title, text, border, icon, additionalInfo, links, buttons } = props;
11
+ const { title, text, icon, additionalInfo, links, buttons } = props, cardParams = __rest(props, ["title", "text", "icon", "additionalInfo", "links", "buttons"]);
11
12
  const iconProps = icon && getMediaImage(icon);
12
- return (React.createElement(CardBase, { className: b(), url: url, border: border },
13
+ return (React.createElement(CardBase, Object.assign({ className: b() }, cardParams),
13
14
  React.createElement(CardBase.Content, null,
14
15
  iconProps && React.createElement(Image, Object.assign({}, iconProps, { className: b('icon') })),
15
16
  React.createElement(Content, { title: title, text: text, additionalInfo: additionalInfo, links: links, buttons: buttons, colSizes: { all: 12, md: 12 }, size: "s" }))));
@@ -19,6 +19,10 @@ export declare const BasicCard: {
19
19
  pattern: string;
20
20
  })[];
21
21
  };
22
+ target: {
23
+ type: string;
24
+ enum: string[];
25
+ };
22
26
  title: {
23
27
  oneOf: ({
24
28
  type: string;
@@ -9,6 +9,9 @@ export const BasicCard = {
9
9
  required: ['url'],
10
10
  properties: Object.assign(Object.assign(Object.assign(Object.assign({}, BaseProps), CardBase), BasicCardContentProps), { url: {
11
11
  type: 'string',
12
- }, icon: ImageProps }),
12
+ }, icon: ImageProps, target: {
13
+ type: 'string',
14
+ enum: ['_blank', '_parent', '_top', '_self'],
15
+ } }),
13
16
  },
14
17
  };
@@ -6,6 +6,7 @@ export declare const EXTERNAL_LINK_PROPS: {
6
6
  export declare function getLinkProps(url: string, hostname?: string, target?: string): {
7
7
  target: string | undefined;
8
8
  };
9
+ export declare function isAbsoluteUrl(url: string | URL): boolean;
9
10
  export declare function isLinkExternal(url: string, routerHostname?: string): boolean;
10
11
  export declare function getNonLocaleHostName(hostname: string): string;
11
12
  export declare function setUrlTld(url: string, tld?: string): string;
@@ -1,21 +1,23 @@
1
1
  import { parse, format } from 'url';
2
+ const EXAMPLE_URL = 'https://example.org';
2
3
  export const EXTERNAL_LINK_PROPS = { target: '_blank', rel: 'noopener noreferrer' };
3
4
  export function getLinkProps(url, hostname, target) {
4
5
  let linkProps = { target };
5
- if (target === '_blank' || isLinkExternal(url, hostname)) {
6
+ if (isLinkExternal(url, hostname)) {
6
7
  linkProps = Object.assign(Object.assign({}, linkProps), EXTERNAL_LINK_PROPS);
7
8
  }
8
9
  return linkProps;
9
10
  }
11
+ export function isAbsoluteUrl(url) {
12
+ // Using example URL as base for relative links
13
+ const urlObj = new URL(url, EXAMPLE_URL);
14
+ return (
15
+ // Compare url origin with example and check that original url was not example one
16
+ urlObj.origin !== EXAMPLE_URL || (typeof url === 'string' && url.startsWith(EXAMPLE_URL)));
17
+ }
10
18
  export function isLinkExternal(url, routerHostname) {
11
- if (!routerHostname) {
12
- return true;
13
- }
14
- const { hostname } = parse(url);
15
- if (!hostname) {
16
- return false;
17
- }
18
- return getNonLocaleHostName(hostname) !== getNonLocaleHostName(routerHostname);
19
+ return (isAbsoluteUrl(url) &&
20
+ getNonLocaleHostName(new URL(url).hostname) !== getNonLocaleHostName(routerHostname !== null && routerHostname !== void 0 ? routerHostname : ''));
19
21
  }
20
22
  export function getNonLocaleHostName(hostname) {
21
23
  return hostname.replace(/\.(ru|com)$/, '');
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,74 @@
1
+ import { getLinkProps, isAbsoluteUrl, isLinkExternal } from './url';
2
+ describe('URL utils check', () => {
3
+ test.each([
4
+ ['https://user:pass@sub.example.com:8080/p/a/t/h?query=string&query2=1#hash', true],
5
+ ['http://example.net/path', true],
6
+ ['/p/a/t/h?query=string&query2=1#hash', false],
7
+ ['/path', false],
8
+ ['path', false],
9
+ ])("isAbsoluteUrl('%s') should return '%s'", (url, result) => {
10
+ expect(isAbsoluteUrl(url)).toEqual(result);
11
+ });
12
+ test.each([
13
+ [
14
+ 'https://user:pass@sub.example.com:8080/p/a/t/h?query=string&query2=1#hash',
15
+ 'example.net',
16
+ true,
17
+ ],
18
+ [
19
+ 'https://user:pass@sub.example.com:8080/p/a/t/h?query=string&query2=1#hash',
20
+ 'sub.example.com',
21
+ false,
22
+ ],
23
+ [
24
+ 'https://user:pass@sub.example.com:8080/p/a/t/h?query=string&query2=1#hash',
25
+ undefined,
26
+ true,
27
+ ],
28
+ ['http://example.net/path', 'example.net', false],
29
+ ['http://example.net/path', 'sub.example.com', true],
30
+ ['http://example.net/path', undefined, true],
31
+ ['/p/a/t/h?query=string&query2=1#hash', 'example.net', false],
32
+ ['/p/a/t/h?query=string&query2=1#hash', undefined, false],
33
+ ['/path', 'example.net', false],
34
+ ['/path', undefined, false],
35
+ ['path', 'example.net', false],
36
+ ['path', undefined, false],
37
+ ])("isLinkExternal('%s', '%s') should return '%s'", (url, hostname, result) => {
38
+ expect(isLinkExternal(url, hostname)).toEqual(result);
39
+ });
40
+ test.each([
41
+ ['http://example.net/path', 'example.net', '_blank', { target: '_blank' }],
42
+ ['http://example.net/path', 'example.net', undefined, {}],
43
+ [
44
+ 'http://example.net/path',
45
+ 'example.com',
46
+ '_blank',
47
+ { target: '_blank', rel: 'noopener noreferrer' },
48
+ ],
49
+ [
50
+ 'http://example.net/path',
51
+ 'example.com',
52
+ undefined,
53
+ { target: '_blank', rel: 'noopener noreferrer' },
54
+ ],
55
+ [
56
+ 'http://example.net/path',
57
+ undefined,
58
+ '_blank',
59
+ { target: '_blank', rel: 'noopener noreferrer' },
60
+ ],
61
+ [
62
+ 'http://example.net/path',
63
+ undefined,
64
+ undefined,
65
+ { target: '_blank', rel: 'noopener noreferrer' },
66
+ ],
67
+ ['/path', 'example.net', '_blank', { target: '_blank' }],
68
+ ['/path', 'example.net', undefined, {}],
69
+ ['/path', undefined, '_blank', { target: '_blank' }],
70
+ ['/path', undefined, undefined, {}],
71
+ ])("getLinkProps('%s', '%s', '%s') should return '%s'", (url, hostname, target, result) => {
72
+ expect(getLinkProps(url, hostname, target)).toEqual(result);
73
+ });
74
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/page-constructor",
3
- "version": "1.16.3",
3
+ "version": "1.17.0",
4
4
  "description": "Gravity UI Page Constructor",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -49,6 +49,7 @@
49
49
  "@gravity-ui/i18n": "^1.0.0",
50
50
  "bem-cn-lite": "^4.0.0",
51
51
  "lodash": "^4.17.21",
52
+ "react-github-btn": "^1.4.0",
52
53
  "react-player": "^2.9.0",
53
54
  "react-slick": "^0.28.1",
54
55
  "react-spring": "^9.3.0",
@@ -106,6 +106,7 @@ export interface BackgroundCardProps extends CardBaseProps, Omit<ContentBlockPro
106
106
  export interface BasicCardProps extends CardBaseProps, Omit<ContentBlockProps, 'colSizes' | 'centered' | 'size' | 'theme'> {
107
107
  url: string;
108
108
  icon?: ImageProps;
109
+ target?: string;
109
110
  }
110
111
  export interface BannerCardProps {
111
112
  title: string;
@@ -4,13 +4,19 @@ export declare enum NavigationItemType {
4
4
  Link = "link",
5
5
  Dropdown = "dropdown",
6
6
  Button = "button",
7
- Social = "social"
7
+ Social = "social",
8
+ GithubStars = "github-stars"
8
9
  }
9
10
  export interface NavigationItemBase {
10
11
  text: string;
11
12
  icon?: ImageProps;
12
13
  url?: string;
13
14
  }
15
+ export interface NavigationGithubButton extends Omit<NavigationItemBase, 'icon'> {
16
+ type: NavigationItemType.GithubStars;
17
+ url: string;
18
+ label?: string;
19
+ }
14
20
  export interface NavigationLinkItem extends Omit<NavigationItemBase, 'url'> {
15
21
  type: NavigationItemType.Link;
16
22
  url: string;
@@ -29,8 +35,8 @@ export interface NavigationSocialItem extends Omit<NavigationItemBase, 'text'> {
29
35
  icon: ImageProps;
30
36
  url: string;
31
37
  }
32
- export type NavigationItemModel = NavigationLinkItem | NavigationButtonItem | NavigationDropdownItem;
33
- export type NavigationItemData = NavigationLinkItem | NavigationButtonItem | NavigationSocialItem | DropdownItemData;
38
+ export type NavigationItemModel = NavigationLinkItem | NavigationButtonItem | NavigationDropdownItem | NavigationGithubButton;
39
+ export type NavigationItemData = NavigationLinkItem | NavigationButtonItem | NavigationSocialItem | DropdownItemData | NavigationGithubButton;
34
40
  export type DropdownItemData = Omit<NavigationDropdownItem, 'items'>;
35
41
  export interface NavigationLogoData {
36
42
  icon: ImageProps;
@@ -7,4 +7,5 @@ var NavigationItemType;
7
7
  NavigationItemType["Dropdown"] = "dropdown";
8
8
  NavigationItemType["Button"] = "button";
9
9
  NavigationItemType["Social"] = "social";
10
+ NavigationItemType["GithubStars"] = "github-stars";
10
11
  })(NavigationItemType = exports.NavigationItemType || (exports.NavigationItemType = {}));
@@ -6,6 +6,7 @@ export declare const EXTERNAL_LINK_PROPS: {
6
6
  export declare function getLinkProps(url: string, hostname?: string, target?: string): {
7
7
  target: string | undefined;
8
8
  };
9
+ export declare function isAbsoluteUrl(url: string | URL): boolean;
9
10
  export declare function isLinkExternal(url: string, routerHostname?: string): boolean;
10
11
  export declare function getNonLocaleHostName(hostname: string): string;
11
12
  export declare function setUrlTld(url: string, tld?: string): string;
@@ -1,25 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAbsolutePath = exports.getPageSearchParams = exports.setUrlTld = exports.getNonLocaleHostName = exports.isLinkExternal = exports.getLinkProps = exports.EXTERNAL_LINK_PROPS = void 0;
3
+ exports.getAbsolutePath = exports.getPageSearchParams = exports.setUrlTld = exports.getNonLocaleHostName = exports.isLinkExternal = exports.isAbsoluteUrl = exports.getLinkProps = exports.EXTERNAL_LINK_PROPS = void 0;
4
4
  const url_1 = require("url");
5
+ const EXAMPLE_URL = 'https://example.org';
5
6
  exports.EXTERNAL_LINK_PROPS = { target: '_blank', rel: 'noopener noreferrer' };
6
7
  function getLinkProps(url, hostname, target) {
7
8
  let linkProps = { target };
8
- if (target === '_blank' || isLinkExternal(url, hostname)) {
9
+ if (isLinkExternal(url, hostname)) {
9
10
  linkProps = Object.assign(Object.assign({}, linkProps), exports.EXTERNAL_LINK_PROPS);
10
11
  }
11
12
  return linkProps;
12
13
  }
13
14
  exports.getLinkProps = getLinkProps;
15
+ function isAbsoluteUrl(url) {
16
+ // Using example URL as base for relative links
17
+ const urlObj = new URL(url, EXAMPLE_URL);
18
+ return (
19
+ // Compare url origin with example and check that original url was not example one
20
+ urlObj.origin !== EXAMPLE_URL || (typeof url === 'string' && url.startsWith(EXAMPLE_URL)));
21
+ }
22
+ exports.isAbsoluteUrl = isAbsoluteUrl;
14
23
  function isLinkExternal(url, routerHostname) {
15
- if (!routerHostname) {
16
- return true;
17
- }
18
- const { hostname } = (0, url_1.parse)(url);
19
- if (!hostname) {
20
- return false;
21
- }
22
- return getNonLocaleHostName(hostname) !== getNonLocaleHostName(routerHostname);
24
+ return (isAbsoluteUrl(url) &&
25
+ getNonLocaleHostName(new URL(url).hostname) !== getNonLocaleHostName(routerHostname !== null && routerHostname !== void 0 ? routerHostname : ''));
23
26
  }
24
27
  exports.isLinkExternal = isLinkExternal;
25
28
  function getNonLocaleHostName(hostname) {