@eeacms/volto-embed 3.0.1 → 4.0.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,9 +4,18 @@ 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-embed/compare/3.0.1...4.0.0)
8
+
9
+ - Prettier [`fffa1c9`](https://github.com/eea/volto-embed/commit/fffa1c9f42c9dacc7de1fed730e0a4494c04d2f8)
10
+ - Prettier [`f9ca05d`](https://github.com/eea/volto-embed/commit/f9ca05d3c55d204080f8769bd7d556b4d8f0ce21)
11
+ - Breaking changes. Bumped to version 4.0.0 [`eb78abf`](https://github.com/eea/volto-embed/commit/eb78abf98103ee8831814b3df4c441279c586da2)
12
+ - Volto 15.x compatibility: updated react-cookie library [`a480372`](https://github.com/eea/volto-embed/commit/a480372f47e6e34d6f3e14d7b54b345dc83fd328)
13
+
7
14
  #### [3.0.1](https://github.com/eea/volto-embed/compare/3.0.0...3.0.1)
8
15
 
9
- - fix query case [`a4dbd50`](https://github.com/eea/volto-embed/commit/a4dbd50ca703efe31dd8a9deb386f668581aa136)
16
+ > 11 February 2022
17
+
18
+ - fix query case [`#20`](https://github.com/eea/volto-embed/pull/20)
10
19
 
11
20
  #### [3.0.0](https://github.com/eea/volto-embed/compare/3.0.0-beta.0...3.0.0)
12
21
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-embed",
3
- "version": "3.0.1",
3
+ "version": "4.0.0",
4
4
  "description": "Embed external content",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: IDM2 A-Team",
@@ -16,6 +16,7 @@ import aheadSVG from '@plone/volto/icons/ahead.svg';
16
16
  import mapsBlockSVG from '@plone/volto/components/manage/Blocks/Maps/block-maps.svg';
17
17
  import schema from './schema';
18
18
  import { addPrivacyProtectionToSchema } from '../PrivacyProtection';
19
+ import { PrivacyProtection } from '../PrivacyProtection';
19
20
 
20
21
  const messages = defineMessages({
21
22
  MapsBlockInputPlaceholder: {
@@ -182,15 +183,20 @@ class Edit extends Component {
182
183
  'full-width': this.props.data.align === 'full',
183
184
  })}
184
185
  >
185
- <iframe
186
- title={this.props.intl.formatMessage(
187
- messages.GoogleMapsEmbeddedBlock,
188
- )}
189
- src={this.props.data.url}
190
- className="google-map"
191
- frameBorder="0"
192
- allowFullScreen
193
- />
186
+ <PrivacyProtection
187
+ data={this.props.data}
188
+ editable={this.props.editable}
189
+ >
190
+ <iframe
191
+ title={this.props.intl.formatMessage(
192
+ messages.GoogleMapsEmbeddedBlock,
193
+ )}
194
+ src={this.props.data.url}
195
+ className="google-map"
196
+ frameBorder="0"
197
+ allowFullScreen
198
+ />
199
+ </PrivacyProtection>
194
200
  </div>
195
201
  ) : (
196
202
  <Message>
@@ -22,7 +22,7 @@ const messages = defineMessages({
22
22
  * @extends Component
23
23
  */
24
24
 
25
- const View = ({ data, intl }) => {
25
+ const View = ({ data, intl, id }) => {
26
26
  return (
27
27
  <div
28
28
  className={cx(
@@ -42,7 +42,7 @@ const View = ({ data, intl }) => {
42
42
  })}
43
43
  style={{ height: '100%' }}
44
44
  >
45
- <PrivacyProtection data={data}>
45
+ <PrivacyProtection data={data} id={id}>
46
46
  <iframe
47
47
  title={intl.formatMessage(messages.EmbededGoogleMaps)}
48
48
  src={data.url}
@@ -1,9 +1,9 @@
1
1
  import React, { useState } from 'react';
2
+ import { compose } from 'redux';
2
3
  import { useSelector } from 'react-redux';
3
4
  import VisibilitySensor from 'react-visibility-sensor';
4
5
  import { Placeholder, Dimmer, Loader } from 'semantic-ui-react';
5
- import cookie from 'react-cookie';
6
-
6
+ import { withCookies } from 'react-cookie';
7
7
  //import { find, without } from 'lodash';
8
8
  import { serializeNodes } from 'volto-slate/editor/render';
9
9
  import { Button, Checkbox } from 'semantic-ui-react';
@@ -38,29 +38,29 @@ const getExpDays = () =>
38
38
  ? config.settings.embedCookieExpirationDays
39
39
  : 90;
40
40
 
41
- function saveCookie(domain_key) {
41
+ function saveCookie(domain_key, cookies) {
42
42
  const date = new Date();
43
43
  date.setDate(date.getDate() + getExpDays());
44
44
 
45
- cookie.save(key(domain_key), 'true', {
45
+ cookies.set(key(domain_key), 'true', {
46
46
  path: '/',
47
47
  expires: date,
48
48
  });
49
49
  }
50
50
 
51
- function canShow(domain_key) {
52
- return cookie.load(key(domain_key)) === 'true';
51
+ function canShow(domain_key, cookies) {
52
+ return cookies.get(key(domain_key)) === 'true';
53
53
  }
54
54
 
55
- const cookieExist = (domain_key) => cookie.load(key(domain_key));
55
+ const cookieExist = (domain_key, cookies) => cookies.get(key(domain_key));
56
56
 
57
- const CookieWatcher = (cookie, pollingRate = 250) => {
57
+ const CookieWatcher = (domain_key, cookies, pollingRate = 250) => {
58
58
  // state for cookie existence
59
- const [exist, setExist] = useState(cookieExist(cookie));
59
+ const [exist, setExist] = useState(cookieExist(domain_key, cookies));
60
60
 
61
61
  React.useEffect(() => {
62
62
  const interval = setInterval(
63
- () => setExist(cookieExist(cookie)),
63
+ () => setExist(cookieExist(domain_key, cookies)),
64
64
  pollingRate,
65
65
  );
66
66
  return () => clearInterval(interval);
@@ -90,175 +90,168 @@ const getFilteredURL = (url, connected_data_parameters = []) => {
90
90
  return decodedURL;
91
91
  };
92
92
 
93
- export default injectIntl(
94
- ({
95
- children,
96
- data = {},
97
- id,
98
- isEditMode,
99
- onChangeBlock,
100
- intl,
101
- path,
102
- properties,
103
- ...rest
104
- }) => {
105
- const { dataprotection = {}, height } = data;
106
- const { background_image: bgImg, enabled = false } = dataprotection;
107
- const [image, setImage] = React.useState(null);
108
- const [visible, setVisibility] = useState(false);
109
- const defaultShow = canShow(dataprotection.privacy_cookie_key);
110
- const [show, setShow] = useState(defaultShow);
111
- const [remember, setRemember] = useState(
112
- cookieExist(dataprotection.privacy_cookie_key) ? defaultShow : true,
93
+ const PrivacyProtection = (props) => {
94
+ const { children, data = {}, id, editable, intl, path, cookies } = props;
95
+ const {
96
+ enabled = false,
97
+ privacy_statement,
98
+ background_image: bgImg,
99
+ privacy_cookie_key = 'esri-maps',
100
+ } = data.dataprotection || {};
101
+
102
+ const [image, setImage] = React.useState(null);
103
+ const [visible, setVisibility] = useState(false);
104
+ const defaultShow = canShow(privacy_cookie_key, cookies);
105
+ const [show, setShow] = useState(defaultShow);
106
+ const [remember, setRemember] = useState(
107
+ cookieExist(privacy_cookie_key, cookies) ? defaultShow : true,
108
+ );
109
+ const dispatch = useDispatch();
110
+ const checkExistance = CookieWatcher(privacy_cookie_key, cookies);
111
+ const connected_data_parameters = useSelector((state) => {
112
+ return getConnectedDataParametersForContext(
113
+ state?.connected_data_parameters,
114
+ state.router?.location?.pathname,
113
115
  );
114
- const dispatch = useDispatch();
115
- const checkExistance = CookieWatcher(dataprotection.privacy_cookie_key);
116
- const connected_data_parameters = useSelector((state) => {
117
- return getConnectedDataParametersForContext(
118
- state?.connected_data_parameters,
119
- state.router?.location?.pathname,
120
- );
121
- });
116
+ });
117
+ const url = getFilteredURL(data.url, connected_data_parameters);
122
118
 
123
- const url = getFilteredURL(data.url, connected_data_parameters);
119
+ React.useEffect(() => {
120
+ if (bgImg) {
121
+ setImage(createImageUrl(bgImg)); //create imageUrl from uploaded image
122
+ }
123
+ }, [bgImg]);
124
124
 
125
- const styles = {
126
- minHeight: `${height || 200}px`,
127
- position: 'relative',
128
- };
129
- React.useEffect(() => {
130
- if (bgImg) {
131
- setImage(createImageUrl(bgImg)); //create imageUrl from uploaded image
125
+ //Effect hook for polling the cookie_key
126
+ React.useEffect(
127
+ () => {
128
+ if (!editable && defaultShow) {
129
+ setShow(true);
132
130
  }
133
- }, [bgImg]);
131
+ },
132
+ // eslint-disable-next-line react-hooks/exhaustive-deps
133
+ [checkExistance],
134
+ );
134
135
 
135
- //Effect hook for polling the cookie_key
136
- React.useEffect(
137
- () => {
138
- if (!isEditMode && defaultShow) {
139
- setShow(true);
140
- }
141
- },
142
- // eslint-disable-next-line react-hooks/exhaustive-deps
143
- [checkExistance],
144
- );
136
+ //screenshot api
137
+ React.useEffect(() => {
138
+ if (enabled && !bgImg && !show) {
139
+ fetch(
140
+ `${getBaseUrl(
141
+ '',
142
+ )}/cors-proxy/https://screenshot.eea.europa.eu/api/v1/retrieve_image_for_url?url=${encodeURIComponent(
143
+ url,
144
+ )}&w=1920&waitfor=4000`,
145
+ )
146
+ .then((e) => e.blob())
147
+ .then((blob) => {
148
+ setImage(URL.createObjectURL(blob));
149
+ if (editable) {
150
+ toast.success(
151
+ <Toast
152
+ success
153
+ title={intl.formatMessage(messages.success)}
154
+ content={intl.formatMessage(messages.image)}
155
+ />,
156
+ );
157
+ }
158
+ })
159
+ .catch(() => {
160
+ if (__DEVELOPMENT__) {
161
+ /* eslint-disable-next-line */
162
+ console.log('Please enable your VPN!');
163
+ }
164
+ });
165
+ }
166
+ }, [enabled, url, path, dispatch, bgImg, show, intl, editable]);
145
167
 
146
- //screenshot api
147
- React.useEffect(() => {
148
- if (enabled && !bgImg && !show) {
149
- fetch(
150
- `${getBaseUrl(
151
- '',
152
- )}/cors-proxy/https://screenshot.eea.europa.eu/api/v1/retrieve_image_for_url?url=${encodeURIComponent(
153
- url,
154
- )}&w=1920&waitfor=4000`,
155
- )
156
- .then((e) => e.blob())
157
- .then((blob) => {
158
- setImage(URL.createObjectURL(blob));
159
- if (isEditMode) {
160
- toast.success(
161
- <Toast
162
- success
163
- title={intl.formatMessage(messages.success)}
164
- content={intl.formatMessage(messages.image)}
165
- />,
166
- );
167
- }
168
- })
169
- .catch(() => {
170
- if (__DEVELOPMENT__) {
171
- /* eslint-disable-next-line */
172
- console.log('Please enable your VPN!');
173
- }
174
- });
175
- }
176
- }, [enabled, url, path, dispatch, bgImg, show, intl, isEditMode]);
168
+ return (
169
+ <VisibilitySensor
170
+ onChange={(isVisible) => {
171
+ !visible && isVisible && setVisibility(true);
172
+ }}
173
+ partialVisibility={true}
174
+ offset={{ bottom: 200 }}
175
+ >
176
+ {visible ? (
177
+ <div
178
+ className="privacy-protection-wrapper"
179
+ style={{ position: 'relative', minHeight: '200px' }}
180
+ >
181
+ {!enabled || show ? (
182
+ children
183
+ ) : !__DEVELOPMENT__ && !image ? (
184
+ <Dimmer active>
185
+ <Loader />
186
+ </Dimmer>
187
+ ) : (
188
+ <div
189
+ className="privacy-protection"
190
+ style={
191
+ image
192
+ ? {
193
+ backgroundImage: `url(${image})`,
194
+ backgroundRepeat: 'no-repeat',
195
+ backgroundSize: 'cover',
196
+ backgroundPosition: 'center -70px',
197
+ }
198
+ : {}
199
+ }
200
+ >
201
+ <div className="overlay">
202
+ <div className="wrapped">
203
+ <div className="privacy-button">
204
+ <Button
205
+ primary
206
+ onClick={() => {
207
+ setShow(true);
208
+ if (remember) {
209
+ saveCookie(privacy_cookie_key, cookies);
210
+ }
211
+ }}
212
+ >
213
+ Show external content
214
+ </Button>
215
+ </div>
177
216
 
178
- return (
179
- <VisibilitySensor
180
- onChange={(isVisible) => {
181
- !visible && isVisible && setVisibility(true);
182
- }}
183
- partialVisibility={true}
184
- offset={{ bottom: 200 }}
185
- >
186
- {visible ? (
187
- <div className="privacy-protection-wrapper" style={styles}>
188
- {!dataprotection.enabled || show ? (
189
- children
190
- ) : !__DEVELOPMENT__ && !image ? (
191
- <Dimmer active>
192
- <Loader />
193
- </Dimmer>
194
- ) : (
195
- <div
196
- className="privacy-protection"
197
- {...rest}
198
- style={
199
- image
200
- ? {
201
- backgroundImage: `url(${image})`,
202
- backgroundRepeat: 'no-repeat',
203
- backgroundSize: 'cover',
204
- backgroundPosition: 'center -70px',
205
- }
206
- : {}
207
- }
208
- >
209
- <div className="overlay">
210
- <div className="wrapped">
211
- <div className="privacy-button">
212
- <Button
213
- primary
214
- onClick={() => {
215
- setShow(true);
216
- if (remember) {
217
- saveCookie(dataprotection.privacy_cookie_key);
218
- }
217
+ {!editable && (
218
+ <div className="privacy-toggle">
219
+ <Checkbox
220
+ toggle
221
+ label="Remember my choice"
222
+ id={`remember-choice-${id}`}
223
+ onChange={(ev, { checked }) => {
224
+ setRemember(checked);
219
225
  }}
220
- >
221
- Show external content
222
- </Button>
226
+ checked={remember}
227
+ />
223
228
  </div>
229
+ )}
224
230
 
225
- {!isEditMode && (
226
- <div className="privacy-toggle">
227
- <Checkbox
228
- toggle
229
- label="Remember my choice"
230
- id={`remember-choice-${id}`}
231
- onChange={(ev, { checked }) => {
232
- setRemember(checked);
233
- }}
234
- checked={remember}
235
- />
236
- </div>
231
+ <p className="discreet">
232
+ Your choice will be saved in a cookie managed by{' '}
233
+ {config.settings.ownDomain || '.eea.europa.eu'} that will
234
+ expire in {getExpDays()} days.
235
+ </p>
236
+ <p className="discreet">
237
+ {serializeNodes(
238
+ privacy_statement ||
239
+ ProtectionSchema().properties.privacy_statement
240
+ .defaultValue,
237
241
  )}
238
-
239
- <p className="discreet">
240
- Your choice will be saved in a cookie managed by{' '}
241
- {config.settings.ownDomain || '.eea.europa.eu'} that will
242
- expire in {getExpDays()} days.
243
- </p>
244
- <p className="discreet">
245
- {serializeNodes(
246
- dataprotection.privacy_statement ||
247
- ProtectionSchema().properties.privacy_statement
248
- .defaultValue,
249
- )}
250
- </p>
251
- </div>
242
+ </p>
252
243
  </div>
253
244
  </div>
254
- )}
255
- </div>
256
- ) : (
257
- <Placeholder style={{ height: '100%', width: '100%' }}>
258
- <Placeholder.Image rectangular />
259
- </Placeholder>
260
- )}
261
- </VisibilitySensor>
262
- );
263
- },
264
- );
245
+ </div>
246
+ )}
247
+ </div>
248
+ ) : (
249
+ <Placeholder style={{ height: '100%', width: '100%' }}>
250
+ <Placeholder.Image rectangular />
251
+ </Placeholder>
252
+ )}
253
+ </VisibilitySensor>
254
+ );
255
+ };
256
+
257
+ export default compose(injectIntl, withCookies)(PrivacyProtection);
@@ -18,7 +18,7 @@
18
18
  }
19
19
 
20
20
  .privacy-button {
21
- margin-top: 2rem;
21
+ margin-top: 0.5rem;
22
22
  }
23
23
 
24
24
  .privacy-toggle {