@blaze-cms/react-page-builder 0.120.1 → 0.122.0-alpha.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 (49) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/lib/application/query/index.js +15 -9
  3. package/lib/application/query/index.js.map +1 -1
  4. package/lib/components/Breadcrumb/Breadcrumb.js +136 -0
  5. package/lib/components/Breadcrumb/Breadcrumb.js.map +1 -0
  6. package/lib/components/Breadcrumb/index.js +16 -0
  7. package/lib/components/Breadcrumb/index.js.map +1 -0
  8. package/lib/components/Image/Image.js +3 -2
  9. package/lib/components/Image/Image.js.map +1 -1
  10. package/lib/components/List/components/Full/FullRender.js +10 -1
  11. package/lib/components/List/components/Full/FullRender.js.map +1 -1
  12. package/lib/components/List/components/Full/FullRenderItem.js.map +1 -1
  13. package/lib/components/SocialFollow/sf.config.js +6 -0
  14. package/lib/components/SocialFollow/sf.config.js.map +1 -1
  15. package/lib/components/index.js +5 -0
  16. package/lib/components/index.js.map +1 -1
  17. package/lib/constants/index.js +1 -1
  18. package/lib/constants/index.js.map +1 -1
  19. package/lib-es/application/query/index.js +15 -1
  20. package/lib-es/application/query/index.js.map +1 -1
  21. package/lib-es/components/Breadcrumb/Breadcrumb.js +91 -0
  22. package/lib-es/components/Breadcrumb/Breadcrumb.js.map +1 -0
  23. package/lib-es/components/Breadcrumb/index.js +3 -0
  24. package/lib-es/components/Breadcrumb/index.js.map +1 -0
  25. package/lib-es/components/Image/Image.js +3 -2
  26. package/lib-es/components/Image/Image.js.map +1 -1
  27. package/lib-es/components/List/components/Full/FullRender.js +9 -2
  28. package/lib-es/components/List/components/Full/FullRender.js.map +1 -1
  29. package/lib-es/components/List/components/Full/FullRenderItem.js.map +1 -1
  30. package/lib-es/components/SocialFollow/sf.config.js +7 -1
  31. package/lib-es/components/SocialFollow/sf.config.js.map +1 -1
  32. package/lib-es/components/index.js +4 -1
  33. package/lib-es/components/index.js.map +1 -1
  34. package/lib-es/constants/index.js +1 -1
  35. package/lib-es/constants/index.js.map +1 -1
  36. package/package.json +3 -2
  37. package/src/application/query/index.js +16 -1
  38. package/src/components/Breadcrumb/Breadcrumb.js +73 -0
  39. package/src/components/Breadcrumb/index.js +3 -0
  40. package/src/components/Image/Image.js +7 -2
  41. package/src/components/List/components/Full/FullRender.js +6 -3
  42. package/src/components/List/components/Full/FullRenderItem.js +0 -1
  43. package/src/components/SocialFollow/sf.config.js +8 -1
  44. package/src/components/index.js +2 -1
  45. package/src/constants/index.js +6 -1
  46. package/tests/unit/src/components/Breadcrumb/Breadcrumb.test.js +103 -0
  47. package/tests/unit/src/components/Breadcrumb/__snapshots__/Breadcrumb.test.js.snap +82 -0
  48. package/tests/unit/src/components/__snapshots__/index.test.js.snap +4 -0
  49. package/tests/unit/src/utils/get-image-data.test.js +7 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blaze-cms/react-page-builder",
3
- "version": "0.120.1",
3
+ "version": "0.122.0-alpha.0",
4
4
  "description": "Blaze react page builder",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib-es/index.js",
@@ -33,6 +33,7 @@
33
33
  "@blaze-cms/nextjs-components": "^0.119.0",
34
34
  "@blaze-cms/setup-ui": "^0.92.0",
35
35
  "@blaze-cms/utils": "^0.118.0",
36
+ "@blaze-react/breadcrumb": "0.8.0-alpha.60",
36
37
  "@blaze-react/button": "0.5.19",
37
38
  "@blaze-react/checkboxes": "0.5.31",
38
39
  "@blaze-react/input": "0.5.30",
@@ -83,5 +84,5 @@
83
84
  "lib/*",
84
85
  "lib-es/*"
85
86
  ],
86
- "gitHead": "1cf69b010ec6b72069e9d9e231c1fec16232a2d7"
87
+ "gitHead": "246146ffdb3f5e5bbdd70f2a6f9d383cab59b3af"
87
88
  }
@@ -45,6 +45,20 @@ const getSingleEntitySchema = gql`
45
45
  }
46
46
  `;
47
47
 
48
+ const getRecordParents = queryName => gql`
49
+ query getRecordParents($id: String!){
50
+ recordParents: ${queryName}(id: $id){
51
+ id,
52
+ name,
53
+ url,
54
+ parents {
55
+ id,
56
+ name
57
+ url
58
+ }
59
+ }
60
+ }`;
61
+
48
62
  const getMultipleSchema = identifiers => {
49
63
  const queryString = identifiers
50
64
  .map(
@@ -136,5 +150,6 @@ export {
136
150
  getSearchPublishedContent,
137
151
  getCount,
138
152
  getMultipleSchema,
139
- getUser
153
+ getUser,
154
+ getRecordParents
140
155
  };
@@ -0,0 +1,73 @@
1
+ import React, { useContext } from 'react';
2
+ import { MainContext, Link } from '@blaze-cms/nextjs-components';
3
+ import PropTypes from 'prop-types';
4
+ import { useQuery } from '@apollo/client';
5
+ import Breadcrumbs from '@blaze-react/breadcrumb';
6
+ import { getRecordParents, getSingleEntitySchema } from '../../application/query';
7
+ import Wrapper from '../Wrapper';
8
+ import { getClassModifiers } from '../../utils';
9
+
10
+ const Breadcrumb = ({ type, ...otherProps }) => {
11
+ const { isPreview } = useContext(MainContext);
12
+ const { parent } = otherProps;
13
+ const { itemEntity, itemId } = parent;
14
+
15
+ const { data = {}, error, loading } = useQuery(getSingleEntitySchema, {
16
+ variables: { id: itemEntity }
17
+ });
18
+
19
+ const { getEntitySchema = {} } = data;
20
+ const { actions: { getPublished, get } = {} } = getEntitySchema;
21
+ const actionKey = isPreview ? get : getPublished || get;
22
+
23
+ const { data: parentsData = [], loading: parentsLoading } = useQuery(
24
+ getRecordParents(actionKey),
25
+ {
26
+ variables: { id: itemId },
27
+ skip: !actionKey
28
+ }
29
+ );
30
+
31
+ if (loading || parentsLoading) return '';
32
+ if (error) return error.message;
33
+ if (!data) return null;
34
+
35
+ const modifiers = getClassModifiers('breadcrumb', otherProps);
36
+ const { recordParents: { name, url, parents = [] } = {} } = parentsData;
37
+
38
+ if (url === '/') return '';
39
+
40
+ const breadcrumbItems = [
41
+ {
42
+ name,
43
+ url
44
+ },
45
+ ...parents,
46
+ {
47
+ name: 'Home',
48
+ url: '/'
49
+ }
50
+ ];
51
+
52
+ return (
53
+ <Wrapper className={type} modifiers={modifiers}>
54
+ <Breadcrumbs>
55
+ {breadcrumbItems.reverse().map(item => (
56
+ <Link key={item.url} href={item.url}>
57
+ {item.name}
58
+ </Link>
59
+ ))}
60
+ </Breadcrumbs>
61
+ </Wrapper>
62
+ );
63
+ };
64
+
65
+ Breadcrumb.propTypes = {
66
+ type: PropTypes.string
67
+ };
68
+
69
+ Breadcrumb.defaultProps = {
70
+ type: 'breadcrumb'
71
+ };
72
+
73
+ export default Breadcrumb;
@@ -0,0 +1,3 @@
1
+ import Breadcrumb from './Breadcrumb';
2
+
3
+ export default Breadcrumb;
@@ -34,7 +34,11 @@ const Image = ({
34
34
  }) => {
35
35
  const [displayLightbox, setDisplayLightbox] = useState(false);
36
36
  const [isIntersecting, outerRef] = useInView(IN_VIEW_CONFIG);
37
- const { caption, altText, hrefUrl } = getImageData(otherProps, imageData);
37
+
38
+ const { caption, altText, hrefUrl, credits: imageDataCredits } = getImageData(
39
+ otherProps,
40
+ imageData
41
+ );
38
42
 
39
43
  const href = url || hrefUrl;
40
44
 
@@ -62,7 +66,7 @@ const Image = ({
62
66
  });
63
67
 
64
68
  // deprecated: imageCredits is deprecated. This code is to handle legacy data. check before changing/removing
65
- const creditsValue = credits || imageCredits;
69
+ const creditsValue = credits || imageCredits || imageDataCredits;
66
70
 
67
71
  const shouldDisplayCredits = shouldShowProperty({
68
72
  isDisplayed: areImageCreditsDisplayed,
@@ -71,6 +75,7 @@ const Image = ({
71
75
  const { shouldDisplayCount, countMessage } = getDisplayCountData(displayCount, images);
72
76
  const sizeKey = [IMAGE, isHero ? HERO : '', _modifier].filter(Boolean).join(':');
73
77
  const shouldDisplayImage = !!imageUrl && (priority || isIntersecting);
78
+
74
79
  return (
75
80
  <Wrapper ref={outerRef} className={wrapperClassName} modifiers={modifiers} {...otherProps}>
76
81
  {elementTitle && <h2 className="heading heading--section">{elementTitle}</h2>}
@@ -1,4 +1,6 @@
1
- import React, { Fragment } from 'react';
1
+ import React, { Fragment, useContext } from 'react';
2
+ import { MainContext } from '@blaze-cms/nextjs-components';
3
+ import { MainContextProvider } from '@blaze-cms/nextjs-tools';
2
4
  import PropTypes from 'prop-types';
3
5
  import uuid from 'uuid/v1';
4
6
  import FullRenderItem from './FullRenderItem';
@@ -9,6 +11,7 @@ import Wrapper from '../../../Wrapper';
9
11
  import { checkIfShouldRenderBanner } from '../helpers';
10
12
 
11
13
  const FullRender = ({ orderedListData, omitWrappers, paginationType, ...props }) => {
14
+ const contextProps = useContext(MainContext);
12
15
  const pageBuilderID = uuid();
13
16
  const { parent, entity, propsToDisplay, banner, hasBanner } = props;
14
17
  const bannerProps = banner
@@ -19,7 +22,7 @@ const FullRender = ({ orderedListData, omitWrappers, paginationType, ...props })
19
22
  const WrapperToUse = omitWrappers ? Fragment : Wrapper;
20
23
 
21
24
  return (
22
- <>
25
+ <MainContextProvider value={{ ...contextProps, isPreview: false }}>
23
26
  <WrapperToUse className="list list--full">
24
27
  {orderedListData.map(({ id, ...entityProps }, i) => {
25
28
  const shouldRenderBanner = !!bannerProps && checkIfShouldRenderBanner(i, bannerProps);
@@ -45,7 +48,7 @@ const FullRender = ({ orderedListData, omitWrappers, paginationType, ...props })
45
48
  {paginationType === LOAD_MORE && (
46
49
  <ListPagination paginationType={paginationType} {...props} />
47
50
  )}
48
- </>
51
+ </MainContextProvider>
49
52
  );
50
53
  };
51
54
 
@@ -31,7 +31,6 @@ const FullRenderItem = ({
31
31
  const currentItemIndex = initialOffset + index;
32
32
  const renderWaypoint =
33
33
  isInfinite && shouldRenderWaypoint(index, currentListLength, currentItemIndex, listTotal);
34
-
35
34
  return (
36
35
  <>
37
36
  {renderWaypoint && <Waypoint onEnter={triggerInfiniteScroll} />}
@@ -4,7 +4,8 @@ import {
4
4
  FaPinterestP,
5
5
  FaInstagram,
6
6
  FaLinkedinIn,
7
- FaYoutube
7
+ FaYoutube,
8
+ FaTiktok
8
9
  } from 'react-icons/fa';
9
10
 
10
11
  export const BASE_CLASS_NAME_FOLLOW = 'social__list-item social__list-item--follow';
@@ -47,5 +48,11 @@ export const SOCIAL_NETWORKS = {
47
48
  className: 'youtube',
48
49
  Icon: FaYoutube,
49
50
  spanClassName: 'hidden'
51
+ },
52
+ tiktok: {
53
+ name: 'TikTok',
54
+ className: 'tiktok',
55
+ Icon: FaTiktok,
56
+ spanClassName: 'hidden'
50
57
  }
51
58
  };
@@ -37,5 +37,6 @@ export default {
37
37
  ),
38
38
  passwordresetrequest: dynamic(() =>
39
39
  import(/* webpackChunkName: "blazePbPasswordResetRequest" */ './PasswordResetRequest')
40
- )
40
+ ),
41
+ breadcrumb: dynamic(() => import(/* webpackChunkName: "blazePbBreadcrumb" */ './Breadcrumb'))
41
42
  };
@@ -110,7 +110,12 @@ const LOAD_MORE = 'loadMore';
110
110
  const PAGINATION_DISPLAY_LIMIT = 10;
111
111
  const PAGINATION_DIFFERENCE = 5;
112
112
 
113
- const PROPS_TO_CHECK = [['altText', 'alt'], ['caption', 'caption'], ['hrefUrl', 'hrefUrl']];
113
+ const PROPS_TO_CHECK = [
114
+ ['altText', 'alt'],
115
+ ['caption', 'caption'],
116
+ ['hrefUrl', 'hrefUrl'],
117
+ ['credits', 'credits']
118
+ ];
114
119
 
115
120
  const JW_PLAYER_TYPE_FILE = 'file';
116
121
  const VIDEO_WRAPPER_CLASS_NAME = 'video__wrapper';
@@ -0,0 +1,103 @@
1
+ import React from 'react';
2
+ import '@testing-library/jest-dom/extend-expect';
3
+ import { render as RenderComponent } from '@testing-library/react';
4
+ import { MockedProvider } from '@apollo/client/testing';
5
+ import { render } from '@blaze-cms/tools/test-helpers/test-functions';
6
+ import Breadcrumb from '../../../../../src/components/Breadcrumb';
7
+ import { getAction, getRecordParents } from '../../../../../src/application/query';
8
+
9
+ jest.mock('@apollo/client', () => ({
10
+ ...jest.requireActual('@apollo/client'),
11
+ useQuery: jest.fn(({ data, loading, error }) => ({ data, loading, error }))
12
+ }));
13
+ jest.mock('next/router', () => ({
14
+ useRouter: jest.fn(() => ({ asPath: 'test-url' }))
15
+ }));
16
+
17
+ const actionKey = 'getPublishedPage';
18
+ const id = 'record id';
19
+ const action = getAction(actionKey, 'id, name');
20
+ const getEntityDataMock = {
21
+ request: {
22
+ query: action,
23
+ variables: {
24
+ id
25
+ }
26
+ },
27
+ result: {
28
+ data: {
29
+ [actionKey]: {
30
+ id,
31
+ name: 'record name'
32
+ }
33
+ }
34
+ }
35
+ };
36
+
37
+ const getRecordParentsMock = {
38
+ request: {
39
+ query: getRecordParents(actionKey),
40
+ variables: { id: 'id' },
41
+ skip: false
42
+ },
43
+ result: {
44
+ data: {
45
+ recordParents: {
46
+ parents: [
47
+ {
48
+ name: 'parent page',
49
+ url: '/top-parent/parent'
50
+ }
51
+ ]
52
+ }
53
+ }
54
+ }
55
+ };
56
+
57
+ const breadcrumbMock = {
58
+ router: {
59
+ asPath: 'test-url'
60
+ },
61
+ client: {},
62
+ type: 'breadcrumb',
63
+ id: 'id',
64
+ pageName: 'page',
65
+ slug: 'page',
66
+ parent: {
67
+ itemEntity: 'page',
68
+ tags: [],
69
+ category: ''
70
+ }
71
+ };
72
+
73
+ const mocks = [getEntityDataMock, getRecordParentsMock];
74
+
75
+ const setup = (props = breadcrumbMock) =>
76
+ RenderComponent(
77
+ <MockedProvider mocks={mocks}>
78
+ <Breadcrumb {...props} />
79
+ </MockedProvider>
80
+ );
81
+
82
+ describe('Breadcrumb component', () => {
83
+ it('should not render if loading, err or no data exists', () => {
84
+ const { asFragment } = render(Breadcrumb, {
85
+ ...breadcrumbMock,
86
+ action: { data: null, loading: true, error: null }
87
+ });
88
+ expect(asFragment()).toMatchSnapshot();
89
+ });
90
+
91
+ it('should match snapshot', () => {
92
+ const { asFragment } = render(Breadcrumb, {
93
+ ...breadcrumbMock,
94
+ action: { data: {}, loading: false, error: null }
95
+ });
96
+ expect(asFragment()).toMatchSnapshot();
97
+ });
98
+
99
+ it('should render', () => {
100
+ const { asFragment } = setup();
101
+ expect(asFragment()).toMatchSnapshot();
102
+ });
103
+ });
@@ -0,0 +1,82 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Breadcrumb component should match snapshot 1`] = `
4
+ <DocumentFragment>
5
+ <div
6
+ class="breadcrumb "
7
+ >
8
+ <ul
9
+ class="breadcrumb"
10
+ >
11
+ <li
12
+ class="breadcrumb__item"
13
+ >
14
+ <a
15
+ href="/"
16
+ >
17
+ Home
18
+ </a>
19
+ </li>
20
+ <li
21
+ class="breadcrumb__item"
22
+ >
23
+ <a />
24
+ </li>
25
+ </ul>
26
+ </div>
27
+ </DocumentFragment>
28
+ `;
29
+
30
+ exports[`Breadcrumb component should not render if loading, err or no data exists 1`] = `
31
+ <DocumentFragment>
32
+ <div
33
+ class="breadcrumb "
34
+ >
35
+ <ul
36
+ class="breadcrumb"
37
+ >
38
+ <li
39
+ class="breadcrumb__item"
40
+ >
41
+ <a
42
+ href="/"
43
+ >
44
+ Home
45
+ </a>
46
+ </li>
47
+ <li
48
+ class="breadcrumb__item"
49
+ >
50
+ <a />
51
+ </li>
52
+ </ul>
53
+ </div>
54
+ </DocumentFragment>
55
+ `;
56
+
57
+ exports[`Breadcrumb component should render 1`] = `
58
+ <DocumentFragment>
59
+ <div
60
+ class="breadcrumb "
61
+ >
62
+ <ul
63
+ class="breadcrumb"
64
+ >
65
+ <li
66
+ class="breadcrumb__item"
67
+ >
68
+ <a
69
+ href="/"
70
+ >
71
+ Home
72
+ </a>
73
+ </li>
74
+ <li
75
+ class="breadcrumb__item"
76
+ >
77
+ <a />
78
+ </li>
79
+ </ul>
80
+ </div>
81
+ </DocumentFragment>
82
+ `;
@@ -6,6 +6,10 @@ Object {
6
6
  "$$typeof": Symbol(react.forward_ref),
7
7
  "render": [Function],
8
8
  },
9
+ "breadcrumb": Object {
10
+ "$$typeof": Symbol(react.forward_ref),
11
+ "render": [Function],
12
+ },
9
13
  "button": Object {
10
14
  "$$typeof": Symbol(react.forward_ref),
11
15
  "render": [Function],
@@ -4,17 +4,18 @@ import { getImageData } from '../../../../src/utils';
4
4
  describe('get image data', () => {
5
5
  const altText = 'altText-test-prop';
6
6
  const caption = 'caption-test-prop';
7
- const imageCredits = 'credits-test-prop';
7
+ const credits = 'credits-test-prop';
8
8
  const mockedProps = {
9
9
  alt: altText,
10
10
  caption,
11
- imageCredits
11
+ credits
12
12
  };
13
13
 
14
14
  const mockedData = {
15
15
  altText: 'altText-test-data',
16
16
  caption: 'caption-test-data',
17
- hrefUrl: 'hrefUrl-test-data'
17
+ hrefUrl: 'hrefUrl-test-data',
18
+ credits: 'credits-test-data'
18
19
  };
19
20
 
20
21
  it('should be a function', () => {
@@ -28,6 +29,7 @@ describe('get image data', () => {
28
29
  it('should return expected value if has props', () => {
29
30
  const imageData = getImageData(mockedProps, {});
30
31
  const expected = {
32
+ credits,
31
33
  altText,
32
34
  caption,
33
35
  hrefUrl: ''
@@ -45,7 +47,8 @@ describe('get image data', () => {
45
47
  const expected = {
46
48
  altText,
47
49
  caption,
48
- hrefUrl: 'hrefUrl-test-data'
50
+ hrefUrl: 'hrefUrl-test-data',
51
+ credits
49
52
  };
50
53
  expect(imageData).toEqual(expected);
51
54
  });