@blaze-cms/react-page-builder 0.141.0-core-styles.10 → 0.141.0-core-styles.20

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 (58) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/lib/components/List/ListRender.js +3 -1
  3. package/lib/components/List/ListRender.js.map +1 -1
  4. package/lib/components/List/helpers/build-query-booster.js +57 -0
  5. package/lib/components/List/helpers/build-query-booster.js.map +1 -0
  6. package/lib/components/List/helpers/index.js +7 -0
  7. package/lib/components/List/helpers/index.js.map +1 -1
  8. package/lib/variants/ThumbnailCarousel/ThumbnailCarousel.js +65 -0
  9. package/lib/variants/ThumbnailCarousel/ThumbnailCarousel.js.map +1 -0
  10. package/lib/variants/ThumbnailCarousel/ThumbnailImage/ThumbnailImage.js +41 -0
  11. package/lib/variants/ThumbnailCarousel/ThumbnailImage/ThumbnailImage.js.map +1 -0
  12. package/lib/variants/ThumbnailCarousel/ThumbnailImage/index.js +11 -0
  13. package/lib/variants/ThumbnailCarousel/ThumbnailImage/index.js.map +1 -0
  14. package/lib/variants/ThumbnailCarousel/ThumbnailImage/useThumbnailImage.js +82 -0
  15. package/lib/variants/ThumbnailCarousel/ThumbnailImage/useThumbnailImage.js.map +1 -0
  16. package/lib/variants/ThumbnailCarousel/index.js +29 -0
  17. package/lib/variants/ThumbnailCarousel/index.js.map +1 -0
  18. package/lib/variants/ThumbnailCarousel/useThumbnailCarousel.js +62 -0
  19. package/lib/variants/ThumbnailCarousel/useThumbnailCarousel.js.map +1 -0
  20. package/lib/variants/index.js +5 -1
  21. package/lib/variants/index.js.map +1 -1
  22. package/lib-es/components/List/ListRender.js +3 -1
  23. package/lib-es/components/List/ListRender.js.map +1 -1
  24. package/lib-es/components/List/helpers/build-query-booster.js +41 -0
  25. package/lib-es/components/List/helpers/build-query-booster.js.map +1 -0
  26. package/lib-es/components/List/helpers/index.js +1 -0
  27. package/lib-es/components/List/helpers/index.js.map +1 -1
  28. package/lib-es/variants/ThumbnailCarousel/ThumbnailCarousel.js +51 -0
  29. package/lib-es/variants/ThumbnailCarousel/ThumbnailCarousel.js.map +1 -0
  30. package/lib-es/variants/ThumbnailCarousel/ThumbnailImage/ThumbnailImage.js +34 -0
  31. package/lib-es/variants/ThumbnailCarousel/ThumbnailImage/ThumbnailImage.js.map +1 -0
  32. package/lib-es/variants/ThumbnailCarousel/ThumbnailImage/index.js +3 -0
  33. package/lib-es/variants/ThumbnailCarousel/ThumbnailImage/index.js.map +1 -0
  34. package/lib-es/variants/ThumbnailCarousel/ThumbnailImage/useThumbnailImage.js +75 -0
  35. package/lib-es/variants/ThumbnailCarousel/ThumbnailImage/useThumbnailImage.js.map +1 -0
  36. package/lib-es/variants/ThumbnailCarousel/index.js +10 -0
  37. package/lib-es/variants/ThumbnailCarousel/index.js.map +1 -0
  38. package/lib-es/variants/ThumbnailCarousel/useThumbnailCarousel.js +42 -0
  39. package/lib-es/variants/ThumbnailCarousel/useThumbnailCarousel.js.map +1 -0
  40. package/lib-es/variants/index.js +4 -1
  41. package/lib-es/variants/index.js.map +1 -1
  42. package/package.json +3 -3
  43. package/src/components/List/ListRender.js +3 -1
  44. package/src/components/List/helpers/build-query-booster.js +35 -0
  45. package/src/components/List/helpers/index.js +1 -0
  46. package/src/variants/ThumbnailCarousel/ThumbnailCarousel.js +55 -0
  47. package/src/variants/ThumbnailCarousel/ThumbnailImage/ThumbnailImage.js +40 -0
  48. package/src/variants/ThumbnailCarousel/ThumbnailImage/index.js +3 -0
  49. package/src/variants/ThumbnailCarousel/ThumbnailImage/useThumbnailImage.js +75 -0
  50. package/src/variants/ThumbnailCarousel/index.js +10 -0
  51. package/src/variants/ThumbnailCarousel/useThumbnailCarousel.js +37 -0
  52. package/src/variants/index.js +5 -1
  53. package/tests/unit/src/components/List/helpers/build-query-booster.test.js +33 -0
  54. package/tests/unit/src/variants/ThumbnailCarousel/ThumbnailCarousel.test.js +29 -0
  55. package/tests/unit/src/variants/ThumbnailCarousel/ThumbnailImage.test.js +45 -0
  56. package/tests/unit/src/variants/ThumbnailCarousel/__snapshots__/ThumbnailCarousel.test.js.snap +76 -0
  57. package/tests/unit/src/variants/ThumbnailCarousel/__snapshots__/ThumbnailImage.test.js.snap +19 -0
  58. package/tests/unit/src/variants/ThumbnailCarousel/mocks.js +64 -0
@@ -0,0 +1,75 @@
1
+ import { useEffect, useRef } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { useGetImages } from '../../../hooks';
4
+ import { getImageData } from '../../../utils';
5
+
6
+ const useThumbnailImage = ({
7
+ imageId,
8
+ enableLightbox,
9
+ toggleModal,
10
+ handleSelectedImage,
11
+ priority,
12
+ selectedImageId,
13
+ handleOnClick
14
+ }) => {
15
+ const imageRef = useRef(null);
16
+ const isSelected = selectedImageId === imageId;
17
+ const { data = {}, loading, error } = useGetImages(imageId);
18
+
19
+ useEffect(
20
+ () => {
21
+ if (imageRef.current && isSelected) {
22
+ imageRef.current.scrollIntoView({ behavior: 'smooth', block: 'start' });
23
+ }
24
+ },
25
+ [isSelected]
26
+ );
27
+
28
+ const handleEnableLightbox = () => {
29
+ if (!enableLightbox) return;
30
+ toggleModal();
31
+ handleSelectedImage(imageId);
32
+ };
33
+
34
+ const handleClick = () => {
35
+ handleOnClick(imageId);
36
+ };
37
+
38
+ const { url: imageUrl = '', data: imageData = {} } = data.getFile || {
39
+ getFile: { url: '', data: {} }
40
+ };
41
+ const { altText } = getImageData({}, imageData);
42
+
43
+ const className =
44
+ selectedImageId === imageId
45
+ ? 'thumbnail-carousel-image thumbnail-carousel-image--selected'
46
+ : 'thumbnail-carousel-image';
47
+
48
+ return {
49
+ loading,
50
+ error,
51
+ className,
52
+ imageRef,
53
+ imageUrl,
54
+ altText,
55
+ priority,
56
+ handleClick,
57
+ handleEnableLightbox
58
+ };
59
+ };
60
+
61
+ useThumbnailImage.propTypes = {
62
+ imageId: PropTypes.string.isRequired,
63
+ selectedImageId: PropTypes.string.isRequired,
64
+ enableLightbox: PropTypes.bool.isRequired,
65
+ toggleModal: PropTypes.func.isRequired,
66
+ handleSelectedImage: PropTypes.func.isRequired,
67
+ priority: PropTypes.bool.isRequired,
68
+ handleOnClick: PropTypes.func
69
+ };
70
+
71
+ useThumbnailImage.defaultProps = {
72
+ handleOnClick: () => {}
73
+ };
74
+
75
+ export default useThumbnailImage;
@@ -0,0 +1,10 @@
1
+ import ThumbnailCarouselComponent from './ThumbnailCarousel';
2
+
3
+ const ThumbnailCarousel = {
4
+ getSettings: componentSettings => ({
5
+ ...componentSettings
6
+ }),
7
+ VariantComponent: ThumbnailCarouselComponent
8
+ };
9
+
10
+ export default ThumbnailCarousel;
@@ -0,0 +1,37 @@
1
+ import { useState, useRef } from 'react';
2
+
3
+ const useThumbnailCarousel = ({ imageIds, priorityLimit, ...props }) => {
4
+ const [selectedImageIndex, setSelectedImageIndex] = useState(0);
5
+ const thumbnailsListRef = useRef(null);
6
+ const selectedImageId = imageIds[selectedImageIndex];
7
+
8
+ const mainImageButtonClick = next => {
9
+ if (next) {
10
+ const isLast = imageIds.length - 1 === selectedImageIndex;
11
+ const newIndex = isLast ? 0 : selectedImageIndex + 1;
12
+ setSelectedImageIndex(newIndex);
13
+ } else {
14
+ const isFirst = selectedImageIndex === 0;
15
+ const newIndex = isFirst ? imageIds.length - 1 : selectedImageIndex - 1;
16
+ setSelectedImageIndex(newIndex);
17
+ }
18
+ };
19
+
20
+ const thumbnailImageClick = id => {
21
+ const newIndex = imageIds.indexOf(id);
22
+ if (newIndex !== -1) setSelectedImageIndex(newIndex);
23
+ };
24
+
25
+ return {
26
+ ...props,
27
+ imageIds,
28
+ selectedImageId,
29
+ selectedImageIndex,
30
+ thumbnailsListRef,
31
+ priorityLimit,
32
+ thumbnailImageClick,
33
+ mainImageButtonClick
34
+ };
35
+ };
36
+
37
+ export default useThumbnailCarousel;
@@ -1 +1,5 @@
1
- export default {};
1
+ import thumbnailCarousel from './ThumbnailCarousel';
2
+
3
+ export default {
4
+ thumbnailCarousel
5
+ };
@@ -0,0 +1,33 @@
1
+ import buildQueryBooster from '../../../../../../src/components/List/helpers/build-query-booster';
2
+
3
+ describe('buildQueryBooster helper function', () => {
4
+ it('should return unmodified variables if no recencyBoostProperty is present in props', () => {
5
+ const noRecencyBoostProperty = buildQueryBooster({}, { rawQueryStringified: `{"test":"t"}` });
6
+ expect(noRecencyBoostProperty).toEqual({ rawQueryStringified: '{"test":"t"}' });
7
+ });
8
+
9
+ it('should return update rawQueryStringified with recency boosted props', () => {
10
+ const noRecencyBoostProperty = buildQueryBooster(
11
+ { recencyBoostProperty: ['date'] },
12
+ { rawQueryStringified: `{"test":"t"}` }
13
+ );
14
+ expect(noRecencyBoostProperty).toEqual({
15
+ rawQueryStringified:
16
+ '{"function_score":{"query":{"test":"t"},"functions":[{"gauss":{"date":{"origin":"now","scale":"30d","offset":"7d","decay":0.5}}}],"boost_mode":"multiply"}}'
17
+ });
18
+ });
19
+
20
+ it('should return update rawQueryStringified with recency boosted props and existing functions if present', () => {
21
+ const noRecencyBoostProperty = buildQueryBooster(
22
+ { recencyBoostProperty: ['date'] },
23
+ {
24
+ rawQueryStringified:
25
+ '{"function_score":{"query":{"test":"t"},"functions":[{"gauss":{"test":{"origin":"now","scale":"30d","offset":"7d","decay":0.5}}}],"boost_mode":"multiply"}}'
26
+ }
27
+ );
28
+ expect(noRecencyBoostProperty).toEqual({
29
+ rawQueryStringified:
30
+ '{"function_score":{"query":{"test":"t"},"functions":[{"gauss":{"test":{"origin":"now","scale":"30d","offset":"7d","decay":0.5}}},{"gauss":{"date":{"origin":"now","scale":"30d","offset":"7d","decay":0.5}}}],"boost_mode":"multiply"}}'
31
+ });
32
+ });
33
+ });
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+ import React from 'react';
5
+ import '@testing-library/jest-dom/extend-expect';
6
+ import { render, screen, waitFor } from '@testing-library/react';
7
+ import { MockedProvider } from '@apollo/client/testing';
8
+ import ThumbnailCarousel from '../../../../../src/variants/ThumbnailCarousel/ThumbnailCarousel';
9
+ import IMAGE_MOCKS from './mocks';
10
+
11
+ const mockedProps = {
12
+ imageIds: ['1', '2', '3'],
13
+ priorityLimit: 0
14
+ };
15
+
16
+ describe('ThumbnailCarousel component', () => {
17
+ it('renders ThumbnailCarousel without error', async () => {
18
+ const { asFragment } = render(
19
+ <MockedProvider mocks={IMAGE_MOCKS}>
20
+ <ThumbnailCarousel {...mockedProps} />
21
+ </MockedProvider>
22
+ );
23
+ await waitFor(() => {
24
+ expect(screen.getAllByTestId('thumbnail-image')[0]).toBeInTheDocument();
25
+ });
26
+ expect(asFragment()).toMatchSnapshot();
27
+ expect(screen.getByTestId('thumbnail-carousel')).toBeInTheDocument();
28
+ });
29
+ });
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+ import React from 'react';
5
+ import '@testing-library/jest-dom/extend-expect';
6
+ import { render, screen, waitFor } from '@testing-library/react';
7
+ import { MockedProvider } from '@apollo/client/testing';
8
+ import ThumbnailImage from '../../../../../src/variants/ThumbnailCarousel/ThumbnailImage';
9
+ import IMAGE_MOCKS from './mocks';
10
+
11
+ describe('ThumbnailImage component', () => {
12
+ const mockedProps = {
13
+ imageId: '1',
14
+ enableLightbox: false,
15
+ toggleModal: () => {},
16
+ handleSelectedImage: () => {},
17
+ priority: 0,
18
+ selectedImageId: '1',
19
+ handleOnClick: () => {}
20
+ };
21
+
22
+ it('renders ThumbnailImage without error', async () => {
23
+ const { asFragment } = render(
24
+ <MockedProvider mocks={IMAGE_MOCKS}>
25
+ <ThumbnailImage {...mockedProps} />
26
+ </MockedProvider>
27
+ );
28
+ await waitFor(() => {
29
+ expect(screen.getByTestId('thumbnail-image')).toBeInTheDocument();
30
+ });
31
+ expect(asFragment()).toMatchSnapshot();
32
+ });
33
+
34
+ it('should render error message if query fails', async () => {
35
+ const { asFragment } = render(
36
+ <MockedProvider mocks={IMAGE_MOCKS}>
37
+ <ThumbnailImage {...mockedProps} imageId="6" />
38
+ </MockedProvider>
39
+ );
40
+ await waitFor(() => {
41
+ expect(screen.getByText('Oops something went wrong')).toBeInTheDocument();
42
+ });
43
+ expect(asFragment()).toMatchSnapshot();
44
+ });
45
+ });
@@ -0,0 +1,76 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`ThumbnailCarousel component renders ThumbnailCarousel without error 1`] = `
4
+ <DocumentFragment>
5
+ <div
6
+ class="thumbnail-carousel"
7
+ data-testid="thumbnail-carousel"
8
+ >
9
+ <div
10
+ class="thumbnail-carousel__main_image_container"
11
+ >
12
+ <div
13
+ class="thumbnail-carousel__main_image_container__button"
14
+ id="previous-button"
15
+ role="button"
16
+ >
17
+ <div
18
+ class="arrow arrow--left"
19
+ />
20
+ </div>
21
+ <div
22
+ class="thumbnail-carousel__main_image_container__main-image"
23
+ data-testid="thumbnail-main-image"
24
+ >
25
+ <div
26
+ class="thumbnail-carousel-image"
27
+ data-testid="thumbnail-image"
28
+ role="button"
29
+ >
30
+ <span>
31
+ <img
32
+ alt=""
33
+ role="button"
34
+ src="image1.jpg"
35
+ />
36
+ </span>
37
+ </div>
38
+ </div>
39
+ <div
40
+ class="thumbnail-carousel__main_image_container__button next"
41
+ id="next-button"
42
+ role="button"
43
+ >
44
+ <div
45
+ class="arrow arrow--right"
46
+ />
47
+ </div>
48
+ </div>
49
+ <div
50
+ class="thumbnail-carousel__list"
51
+ >
52
+ <div
53
+ class="thumbnail-carousel-image thumbnail-carousel-image--selected"
54
+ data-testid="thumbnail-image"
55
+ role="button"
56
+ >
57
+ <span />
58
+ </div>
59
+ <div
60
+ class="thumbnail-carousel-image"
61
+ data-testid="thumbnail-image"
62
+ role="button"
63
+ >
64
+ <span />
65
+ </div>
66
+ <div
67
+ class="thumbnail-carousel-image"
68
+ data-testid="thumbnail-image"
69
+ role="button"
70
+ >
71
+ <span />
72
+ </div>
73
+ </div>
74
+ </div>
75
+ </DocumentFragment>
76
+ `;
@@ -0,0 +1,19 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`ThumbnailImage component renders ThumbnailImage without error 1`] = `
4
+ <DocumentFragment>
5
+ <div
6
+ class="thumbnail-carousel-image thumbnail-carousel-image--selected"
7
+ data-testid="thumbnail-image"
8
+ role="button"
9
+ >
10
+ <span />
11
+ </div>
12
+ </DocumentFragment>
13
+ `;
14
+
15
+ exports[`ThumbnailImage component should render error message if query fails 1`] = `
16
+ <DocumentFragment>
17
+ Oops something went wrong
18
+ </DocumentFragment>
19
+ `;
@@ -0,0 +1,64 @@
1
+ import { getFileById } from '../../../../../src/application/query';
2
+
3
+ const IMAGE_MOCKS = [
4
+ {
5
+ request: {
6
+ query: getFileById,
7
+ variables: { id: '1' }
8
+ },
9
+ result: {
10
+ data: {
11
+ getFile: { id: '1', url: 'image1.jpg', caption: 'Caption 1', data: {} }
12
+ }
13
+ }
14
+ },
15
+ {
16
+ request: {
17
+ query: getFileById,
18
+ variables: { id: '2' }
19
+ },
20
+ result: {
21
+ data: {
22
+ getFile: { id: '2', url: 'image2.jpg', caption: 'Caption 2', data: {} }
23
+ }
24
+ }
25
+ },
26
+ {
27
+ request: {
28
+ query: getFileById,
29
+ variables: { id: '3' }
30
+ },
31
+ result: {
32
+ data: {
33
+ getFile: { id: '3', url: 'image3.jpg', caption: 'Caption 3', data: {} }
34
+ }
35
+ }
36
+ },
37
+ {
38
+ request: {
39
+ query: getFileById,
40
+ variables: { id: '6' }
41
+ },
42
+ error: {
43
+ message: 'Oops something went wrong'
44
+ }
45
+ }
46
+ // {
47
+ // request: {
48
+ // query: getFiles,
49
+ // variables: { where: { id: { _in: ['1', '2', '3', '4'] } } }
50
+ // },
51
+ // result: {
52
+ // data: {
53
+ // getImages: [
54
+ // { id: '1', url: 'image1.jpg', caption: 'Caption 1', data: {} },
55
+ // { id: '2', url: 'image2.jpg', caption: 'Caption 2', data: {} },
56
+ // { id: '3', url: 'image3.jpg', caption: 'Caption 3', data: {} },
57
+ // { id: '4', url: 'image4.jpg', caption: 'Caption 4', data: {} }
58
+ // ]
59
+ // }
60
+ // }
61
+ // }
62
+ ];
63
+
64
+ export default IMAGE_MOCKS;