@eeacms/volto-hero-block 4.0.0 → 5.1.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.
package/CHANGELOG.md CHANGED
@@ -4,7 +4,36 @@ All notable changes to this project will be documented in this file. Dates are d
4
4
 
5
5
  Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
6
6
 
7
- ### [4.0.0](https://github.com/eea/volto-hero-block/compare/3.0.1...4.0.0) - 7 February 2023
7
+ ### [5.1.0](https://github.com/eea/volto-hero-block/compare/5.0.0...5.1.0) - 24 March 2023
8
+
9
+ #### :rocket: New Features
10
+
11
+ - feat: add 'with-hero-block' class to body [Miu Razvan - [`12e60a3`](https://github.com/eea/volto-hero-block/commit/12e60a352e60f647346fa00ba3aa8f54f2b8623c)]
12
+
13
+ #### :hammer_and_wrench: Others
14
+
15
+ - Release 5.1.0 [Alin Voinea - [`7cd1d6c`](https://github.com/eea/volto-hero-block/commit/7cd1d6c3194b59f9645a716be8364b39136ac6fc)]
16
+ - use stable volto in jenkins [Miu Razvan - [`5459e18`](https://github.com/eea/volto-hero-block/commit/5459e18001486ff05b1e7535685926ef41a233e3)]
17
+ ## [5.0.0](https://github.com/eea/volto-hero-block/compare/4.0.0...5.0.0) - 7 March 2023
18
+
19
+ #### :nail_care: Enhancements
20
+
21
+ - change(hero): Performance improvement by lazy loading image #15 from eea/performance_lazy_image [ichim-david - [`2c61703`](https://github.com/eea/volto-hero-block/commit/2c617034158a0c6bd7fb7a12f71d13f2664021d2)]
22
+
23
+ #### :house: Internal changes
24
+
25
+ - chore(import): Use absolute import [Alin Voinea - [`317feb0`](https://github.com/eea/volto-hero-block/commit/317feb0341c1b2d16fdee61f3dcb3d661d973820)]
26
+
27
+ #### :hammer_and_wrench: Others
28
+
29
+ - Release 5.0.0 [Alin Voinea - [`fb56e6c`](https://github.com/eea/volto-hero-block/commit/fb56e6c3b68d1bec5e346bf156e1408df4a567fe)]
30
+ - fix onScreen hook error #16 from eea/fix-onscreen-hook [ichim-david - [`9123541`](https://github.com/eea/volto-hero-block/commit/91235413f423d7e6c4788d70b687b3ed5d4884b4)]
31
+ - no need for comments [andreiggr - [`a14f9c3`](https://github.com/eea/volto-hero-block/commit/a14f9c3bdddfa22e6b4bbc8318f0ca5bdc9c2d38)]
32
+ - fix hook [andreiggr - [`f7fae73`](https://github.com/eea/volto-hero-block/commit/f7fae73007f79af2f06da1d9b72a53ad86fef4ac)]
33
+ - eslint [andreiggr - [`68451b7`](https://github.com/eea/volto-hero-block/commit/68451b725420015fbd5b695e97b8742988d49913)]
34
+ - lazy load huge img on first 10px [andreiggr - [`67dc7d3`](https://github.com/eea/volto-hero-block/commit/67dc7d3475188d692e053032c2639dd1a585c029)]
35
+ - lazy load huge bgimage wip [andreiggr - [`86e45ec`](https://github.com/eea/volto-hero-block/commit/86e45ece842f1cd7452920dffa3a9b4aea945f56)]
36
+ ## [4.0.0](https://github.com/eea/volto-hero-block/compare/3.0.1...4.0.0) - 7 February 2023
8
37
 
9
38
  #### :nail_care: Enhancements
10
39
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-hero-block",
3
- "version": "4.0.0",
3
+ "version": "5.1.0",
4
4
  "description": "@eeacms/volto-hero-block: Volto add-on",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: IDM2 A-Team",
@@ -8,6 +8,7 @@ import {
8
8
  SidebarPortal,
9
9
  UniversalLink,
10
10
  } from '@plone/volto/components';
11
+ import { BodyClass } from '@plone/volto/helpers';
11
12
  import SlateEditor from '@plone/volto-slate/editor/SlateEditor';
12
13
  import { handleKey } from '@plone/volto-slate/blocks/Text/keyboard';
13
14
  import {
@@ -66,6 +67,7 @@ const Edit = (props) => {
66
67
 
67
68
  return (
68
69
  <>
70
+ <BodyClass className="with-hero-block" />
69
71
  <Hero {...data}>
70
72
  <Hero.Text {...data}>
71
73
  <SlateEditor
@@ -3,6 +3,7 @@ import cx from 'classnames';
3
3
  import PropTypes from 'prop-types';
4
4
  import { isInternalURL } from '@plone/volto/helpers/Url/Url';
5
5
  import { isImageGif } from '@eeacms/volto-hero-block/helpers';
6
+ import { useOnScreen } from '@eeacms/volto-hero-block/hooks';
6
7
 
7
8
  Hero.propTypes = {
8
9
  image: PropTypes.string,
@@ -30,6 +31,9 @@ function Hero({
30
31
  const isExternal = !isInternalURL(image);
31
32
  const { alignContent = 'center', backgroundVariant = 'primary' } =
32
33
  styles || {};
34
+
35
+ const bgImgRef = React.useRef();
36
+ const onScreen = useOnScreen(bgImgRef);
33
37
  return (
34
38
  <div
35
39
  className={cx(
@@ -59,8 +63,9 @@ function Hero({
59
63
  >
60
64
  <div
61
65
  className={cx('hero-block-image', styles?.bg)}
66
+ ref={bgImgRef}
62
67
  style={
63
- image
68
+ image && onScreen
64
69
  ? {
65
70
  backgroundImage: isExternal
66
71
  ? `url(${image})`
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import cx from 'classnames';
3
3
  import { Icon } from 'semantic-ui-react';
4
4
  import { UniversalLink } from '@plone/volto/components';
5
+ import { BodyClass } from '@plone/volto/helpers';
5
6
  import Hero from './Hero';
6
7
  import Copyright from './Copyright';
7
8
  import { serializeText } from '@eeacms/volto-hero-block/helpers';
@@ -25,22 +26,25 @@ const View = (props) => {
25
26
  const { data = {} } = props;
26
27
  const { text, copyright, copyrightIcon, copyrightPosition } = data;
27
28
  return (
28
- <Hero {...data}>
29
- <Hero.Text {...data}>{serializeText(text)}</Hero.Text>
30
- <Hero.Meta {...data}>
31
- <Metadata {...data} />
32
- </Hero.Meta>
33
- {copyright ? (
34
- <Copyright copyrightPosition={copyrightPosition}>
35
- <Copyright.Icon>
36
- <Icon className={copyrightIcon} />
37
- </Copyright.Icon>
38
- <Copyright.Text>{copyright}</Copyright.Text>
39
- </Copyright>
40
- ) : (
41
- ''
42
- )}
43
- </Hero>
29
+ <React.Fragment>
30
+ <BodyClass className="with-hero-block" />
31
+ <Hero {...data}>
32
+ <Hero.Text {...data}>{serializeText(text)}</Hero.Text>
33
+ <Hero.Meta {...data}>
34
+ <Metadata {...data} />
35
+ </Hero.Meta>
36
+ {copyright ? (
37
+ <Copyright copyrightPosition={copyrightPosition}>
38
+ <Copyright.Icon>
39
+ <Icon className={copyrightIcon} />
40
+ </Copyright.Icon>
41
+ <Copyright.Text>{copyright}</Copyright.Text>
42
+ </Copyright>
43
+ ) : (
44
+ ''
45
+ )}
46
+ </Hero>
47
+ </React.Fragment>
44
48
  );
45
49
  };
46
50
 
package/src/hooks.js ADDED
@@ -0,0 +1,31 @@
1
+ /* eslint-disable react-hooks/exhaustive-deps */
2
+ import React from 'react';
3
+
4
+ function useOnScreen(ref, rootMargin = '0px') {
5
+ const [isIntersecting, setIntersecting] = React.useState(false);
6
+
7
+ React.useEffect(() => {
8
+ const observer = new IntersectionObserver(
9
+ ([entry]) => {
10
+ setIntersecting(entry.isIntersecting);
11
+ },
12
+ {
13
+ rootMargin,
14
+ threshold: 0,
15
+ root: null,
16
+ },
17
+ );
18
+ if (ref?.current) {
19
+ observer.observe(ref.current);
20
+ }
21
+ return () => {
22
+ if (ref?.current) {
23
+ observer.unobserve(ref.current);
24
+ }
25
+ observer.disconnect();
26
+ };
27
+ }, [ref, rootMargin]);
28
+ return isIntersecting;
29
+ }
30
+
31
+ export { useOnScreen };