@eeacms/volto-embed 9.0.0 → 9.0.2
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 +17 -2
- package/cypress.config.js +6 -15
- package/jest-addon.config.js +3 -0
- package/jest.setup.js +77 -0
- package/locales/de/LC_MESSAGES/volto.po +9 -23
- package/locales/en/LC_MESSAGES/volto.po +9 -23
- package/locales/it/LC_MESSAGES/volto.po +9 -23
- package/locales/ro/LC_MESSAGES/volto.po +9 -23
- package/locales/volto.pot +10 -24
- package/package.json +5 -4
- package/src/Blocks/EmbedMaps/Edit.jsx +10 -6
- package/src/Blocks/EmbedMaps/Edit.test.js +2 -26
- package/src/Blocks/EmbedMaps/View.jsx +1 -0
- package/src/Blocks/EmbedMaps/View.test.js +1 -21
- package/src/Blocks/EmbedMaps/index.js +2 -2
- package/src/Blocks/EmbedMaps/schema.js +29 -9
- package/src/Blocks/Maps/Edit.jsx +1 -2
- package/src/Blocks/Maps/Edit.test.js +72 -68
- package/src/Blocks/Maps/MapsSidebar.jsx +1 -2
- package/src/Blocks/Maps/View.jsx +1 -1
- package/src/Blocks/Maps/View.test.js +60 -36
- package/src/Blocks/Maps/schema.js +25 -9
- package/src/Blocks/index.js +9 -0
- package/src/EmbedMap/EmbedMap.jsx +17 -4
- package/src/EmbedMap/EmbedMap.test.js +1 -21
- package/src/PrivacyProtection/PrivacyProtection.jsx +1 -1
- package/src/Toolbar/Toolbar.test.js +1 -49
- package/src/Views/MapView.jsx +16 -2
- package/src/Views/MapView.test.js +1 -21
- package/src/Widgets/MapsViewWidget.jsx +17 -2
- package/src/Widgets/MapsWidget.jsx +11 -2
|
@@ -1,19 +1,35 @@
|
|
|
1
1
|
import { defineMessages } from 'react-intl';
|
|
2
2
|
|
|
3
3
|
const messages = defineMessages({
|
|
4
|
+
Maps: {
|
|
5
|
+
id: 'Maps',
|
|
6
|
+
defaultMessage: 'Maps',
|
|
7
|
+
},
|
|
8
|
+
AltText: {
|
|
9
|
+
id: 'Alt text',
|
|
10
|
+
defaultMessage: 'Alt text',
|
|
11
|
+
},
|
|
12
|
+
MapsURL: {
|
|
13
|
+
id: 'Maps URL',
|
|
14
|
+
defaultMessage: 'Maps URL',
|
|
15
|
+
},
|
|
16
|
+
Alignment: {
|
|
17
|
+
id: 'Alignment',
|
|
18
|
+
defaultMessage: 'Alignment',
|
|
19
|
+
},
|
|
4
20
|
CSSHeight: {
|
|
5
21
|
id: 'CSS height',
|
|
6
|
-
|
|
22
|
+
defaultMessage: 'CSS height',
|
|
7
23
|
},
|
|
8
|
-
|
|
9
|
-
id: '
|
|
10
|
-
|
|
24
|
+
CSSMapHeightDescription: {
|
|
25
|
+
id: 'Map height',
|
|
26
|
+
defaultMessage: 'Map height',
|
|
11
27
|
},
|
|
12
28
|
});
|
|
13
29
|
|
|
14
30
|
export const MapsSchema = (props) => {
|
|
15
31
|
return {
|
|
16
|
-
title: props.intl.messages
|
|
32
|
+
title: props.intl.formatMessage(messages.Maps),
|
|
17
33
|
block: 'Maps',
|
|
18
34
|
fieldsets: [
|
|
19
35
|
{
|
|
@@ -25,14 +41,14 @@ export const MapsSchema = (props) => {
|
|
|
25
41
|
|
|
26
42
|
properties: {
|
|
27
43
|
url: {
|
|
28
|
-
title: props.intl.messages
|
|
44
|
+
title: props.intl.formatMessage(messages.MapsURL),
|
|
29
45
|
widget: 'url',
|
|
30
46
|
},
|
|
31
47
|
title: {
|
|
32
|
-
title: props.intl.messages
|
|
48
|
+
title: props.intl.formatMessage(messages.AltText),
|
|
33
49
|
},
|
|
34
50
|
align: {
|
|
35
|
-
title: props.intl.messages
|
|
51
|
+
title: props.intl.formatMessage(messages.Alignment),
|
|
36
52
|
widget: 'align',
|
|
37
53
|
},
|
|
38
54
|
height: {
|
|
@@ -45,7 +61,7 @@ export const MapsSchema = (props) => {
|
|
|
45
61
|
{props.intl.formatMessage(messages.CSSHeight)}
|
|
46
62
|
</a>
|
|
47
63
|
),
|
|
48
|
-
description: props.intl.formatMessage(messages.
|
|
64
|
+
description: props.intl.formatMessage(messages.CSSMapHeightDescription),
|
|
49
65
|
},
|
|
50
66
|
},
|
|
51
67
|
required: [],
|
package/src/Blocks/index.js
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
|
+
import { uniqBy } from 'lodash';
|
|
1
2
|
import installMaps from './Maps';
|
|
2
3
|
import installEmbedMaps from './EmbedMaps';
|
|
3
4
|
|
|
4
5
|
export default function installBlocks(config) {
|
|
6
|
+
config.blocks.groupBlocksOrder = uniqBy(
|
|
7
|
+
[
|
|
8
|
+
...config.blocks.groupBlocksOrder,
|
|
9
|
+
{ id: 'data_visualizations', title: 'Data Visualizations' },
|
|
10
|
+
],
|
|
11
|
+
'id',
|
|
12
|
+
);
|
|
13
|
+
|
|
5
14
|
return [installMaps, installEmbedMaps].reduce(
|
|
6
15
|
(acc, apply) => apply(acc),
|
|
7
16
|
config,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React, { useEffect, useState, useRef } from 'react';
|
|
2
|
+
import { isNaN, isNumber } from 'lodash';
|
|
2
3
|
import { compose } from 'redux';
|
|
3
4
|
import { connect } from 'react-redux';
|
|
4
5
|
import { defineMessages, injectIntl } from 'react-intl';
|
|
@@ -21,6 +22,14 @@ const messages = defineMessages({
|
|
|
21
22
|
},
|
|
22
23
|
});
|
|
23
24
|
|
|
25
|
+
function getHeight(height) {
|
|
26
|
+
const asNumber = isNumber(Number(height)) && !isNaN(Number(height));
|
|
27
|
+
if (asNumber) {
|
|
28
|
+
return `${height}px`;
|
|
29
|
+
}
|
|
30
|
+
return height;
|
|
31
|
+
}
|
|
32
|
+
|
|
24
33
|
function EmbedMap({ data, intl, id, screen }) {
|
|
25
34
|
const el = useRef();
|
|
26
35
|
const [mobile, setMobile] = useState(false);
|
|
@@ -37,6 +46,8 @@ function EmbedMap({ data, intl, id, screen }) {
|
|
|
37
46
|
}
|
|
38
47
|
}, [screen, mobile]);
|
|
39
48
|
|
|
49
|
+
if (!data.url) return null;
|
|
50
|
+
|
|
40
51
|
return (
|
|
41
52
|
<div
|
|
42
53
|
ref={el}
|
|
@@ -56,7 +67,7 @@ function EmbedMap({ data, intl, id, screen }) {
|
|
|
56
67
|
<PrivacyProtection
|
|
57
68
|
data={data}
|
|
58
69
|
id={id}
|
|
59
|
-
height={data.height}
|
|
70
|
+
height={getHeight(data.height)}
|
|
60
71
|
useVisibilitySensor={data.useVisibilitySensor ?? true}
|
|
61
72
|
>
|
|
62
73
|
<iframe
|
|
@@ -65,17 +76,20 @@ function EmbedMap({ data, intl, id, screen }) {
|
|
|
65
76
|
className="google-map"
|
|
66
77
|
frameBorder="0"
|
|
67
78
|
allowFullScreen
|
|
68
|
-
style={data.height ? { height: data.height } : {}}
|
|
79
|
+
style={data.height ? { height: getHeight(data.height) } : {}}
|
|
69
80
|
/>
|
|
70
81
|
</PrivacyProtection>
|
|
71
82
|
</div>
|
|
72
83
|
<div className={cx('visualization-toolbar', { mobile })}>
|
|
73
84
|
<div className="left-col">
|
|
74
85
|
{data.with_notes && <FigureNote notes={data.figure_note || []} />}
|
|
75
|
-
{data.with_sources &&
|
|
86
|
+
{data.with_sources && (
|
|
87
|
+
<Sources sources={data.data_provenance?.data} />
|
|
88
|
+
)}
|
|
76
89
|
{data.with_more_info && <MoreInfo href={data['@id']} />}
|
|
77
90
|
</div>
|
|
78
91
|
<div className="right-col">
|
|
92
|
+
{data.with_share && <Share href={data['@id']} />}
|
|
79
93
|
{data.with_enlarge && (
|
|
80
94
|
<Enlarge className="enlarge-embed-maps">
|
|
81
95
|
<EmbedMap
|
|
@@ -93,7 +107,6 @@ function EmbedMap({ data, intl, id, screen }) {
|
|
|
93
107
|
/>
|
|
94
108
|
</Enlarge>
|
|
95
109
|
)}
|
|
96
|
-
{data.with_share && <Share href={data['@id']} />}
|
|
97
110
|
</div>
|
|
98
111
|
</div>
|
|
99
112
|
</div>
|
|
@@ -1,20 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import renderer from 'react-test-renderer';
|
|
3
|
-
import configureStore from 'redux-mock-store';
|
|
4
3
|
import { Provider } from 'react-intl-redux';
|
|
5
4
|
import config from '@plone/volto/registry';
|
|
6
5
|
|
|
7
6
|
import EmbedMap from './EmbedMap';
|
|
8
7
|
|
|
9
|
-
const mockStore = configureStore();
|
|
10
|
-
|
|
11
|
-
jest.mock('@plone/volto/components', () => ({
|
|
12
|
-
__esModule: true,
|
|
13
|
-
UniversalLink: ({ children, href }) => {
|
|
14
|
-
return <a href={href}>{children}</a>;
|
|
15
|
-
},
|
|
16
|
-
}));
|
|
17
|
-
|
|
18
8
|
config.blocks.blocksConfig = {
|
|
19
9
|
...config.blocks.blocksConfig,
|
|
20
10
|
maps: {
|
|
@@ -34,18 +24,8 @@ config.blocks.blocksConfig = {
|
|
|
34
24
|
};
|
|
35
25
|
|
|
36
26
|
test('renders map component', () => {
|
|
37
|
-
const store = mockStore({
|
|
38
|
-
intl: {
|
|
39
|
-
locale: 'en',
|
|
40
|
-
messages: {},
|
|
41
|
-
},
|
|
42
|
-
content: {
|
|
43
|
-
create: {},
|
|
44
|
-
},
|
|
45
|
-
connected_data_parameters: {},
|
|
46
|
-
});
|
|
47
27
|
const component = renderer.create(
|
|
48
|
-
<Provider store={store}>
|
|
28
|
+
<Provider store={global.store}>
|
|
49
29
|
<EmbedMap
|
|
50
30
|
id="my-map"
|
|
51
31
|
data={{
|
|
@@ -1,48 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import renderer from 'react-test-renderer';
|
|
3
|
-
import configureStore from 'redux-mock-store';
|
|
4
3
|
import { Provider } from 'react-intl-redux';
|
|
5
4
|
import config from '@plone/volto/registry';
|
|
6
5
|
|
|
7
6
|
import { Enlarge, FigureNote, MoreInfo, Share, Sources } from '.';
|
|
8
7
|
|
|
9
|
-
const mockStore = configureStore();
|
|
10
|
-
|
|
11
|
-
jest.mock('@plone/volto/components', () => ({
|
|
12
|
-
__esModule: true,
|
|
13
|
-
UniversalLink: ({ children, href }) => {
|
|
14
|
-
return <a href={href}>{children}</a>;
|
|
15
|
-
},
|
|
16
|
-
}));
|
|
17
|
-
|
|
18
|
-
jest.mock('@plone/volto-slate/editor/render', () => ({
|
|
19
|
-
__esModule: true,
|
|
20
|
-
serializeNodes: (nodes) => {
|
|
21
|
-
return nodes.map((node, index) => {
|
|
22
|
-
const Tag = node.type;
|
|
23
|
-
return (
|
|
24
|
-
<Tag key={`node-${index}`}>
|
|
25
|
-
{node.children.map((item, index) => (
|
|
26
|
-
<span key={`item-${index}`}>{item.text}</span>
|
|
27
|
-
))}
|
|
28
|
-
</Tag>
|
|
29
|
-
);
|
|
30
|
-
});
|
|
31
|
-
},
|
|
32
|
-
serializeNodesToText: (nodes) => {
|
|
33
|
-
return nodes
|
|
34
|
-
.reduce((texts, node) => {
|
|
35
|
-
if (node.children) {
|
|
36
|
-
node.children.forEach((item) => {
|
|
37
|
-
texts.push(item.text);
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
return texts;
|
|
41
|
-
}, [])
|
|
42
|
-
.join('');
|
|
43
|
-
},
|
|
44
|
-
}));
|
|
45
|
-
|
|
46
8
|
config.blocks.blocksConfig = {
|
|
47
9
|
...config.blocks.blocksConfig,
|
|
48
10
|
maps: {
|
|
@@ -62,18 +24,8 @@ config.blocks.blocksConfig = {
|
|
|
62
24
|
};
|
|
63
25
|
|
|
64
26
|
test('renders toolbar components', () => {
|
|
65
|
-
const store = mockStore({
|
|
66
|
-
intl: {
|
|
67
|
-
locale: 'en',
|
|
68
|
-
messages: {},
|
|
69
|
-
},
|
|
70
|
-
content: {
|
|
71
|
-
create: {},
|
|
72
|
-
},
|
|
73
|
-
connected_data_parameters: {},
|
|
74
|
-
});
|
|
75
27
|
const component = renderer.create(
|
|
76
|
-
<Provider store={store}>
|
|
28
|
+
<Provider store={global.store}>
|
|
77
29
|
<div className="visualization-toolbar">
|
|
78
30
|
<div className="left-col">
|
|
79
31
|
<FigureNote
|
package/src/Views/MapView.jsx
CHANGED
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Container } from 'semantic-ui-react';
|
|
3
|
+
import { hasBlocksData } from '@plone/volto/helpers';
|
|
4
|
+
import RenderBlocks from '@plone/volto/components/theme/View/RenderBlocks';
|
|
3
5
|
import EmbedMap from '@eeacms/volto-embed/EmbedMap/EmbedMap';
|
|
6
|
+
import { pickMetadata } from '@eeacms/volto-embed/helpers';
|
|
4
7
|
|
|
5
8
|
const MapView = (props) => {
|
|
6
9
|
return (
|
|
7
|
-
<Container>
|
|
8
|
-
|
|
10
|
+
<Container id="page-document" className="view-wrapper visualization-view">
|
|
11
|
+
{hasBlocksData(props.content) ? (
|
|
12
|
+
<RenderBlocks {...props} />
|
|
13
|
+
) : (
|
|
14
|
+
<EmbedMap
|
|
15
|
+
data={{
|
|
16
|
+
...(props.content.maps || {}),
|
|
17
|
+
...pickMetadata(props.content),
|
|
18
|
+
with_share: true,
|
|
19
|
+
}}
|
|
20
|
+
id="map-view"
|
|
21
|
+
/>
|
|
22
|
+
)}
|
|
9
23
|
</Container>
|
|
10
24
|
);
|
|
11
25
|
};
|
|
@@ -1,20 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import renderer from 'react-test-renderer';
|
|
3
|
-
import configureStore from 'redux-mock-store';
|
|
4
3
|
import { Provider } from 'react-intl-redux';
|
|
5
4
|
import config from '@plone/volto/registry';
|
|
6
5
|
|
|
7
6
|
import MapView from './MapView';
|
|
8
7
|
|
|
9
|
-
const mockStore = configureStore();
|
|
10
|
-
|
|
11
|
-
jest.mock('@plone/volto/components', () => ({
|
|
12
|
-
__esModule: true,
|
|
13
|
-
UniversalLink: ({ children, href }) => {
|
|
14
|
-
return <a href={href}>{children}</a>;
|
|
15
|
-
},
|
|
16
|
-
}));
|
|
17
|
-
|
|
18
8
|
config.blocks.blocksConfig = {
|
|
19
9
|
...config.blocks.blocksConfig,
|
|
20
10
|
maps: {
|
|
@@ -34,18 +24,8 @@ config.blocks.blocksConfig = {
|
|
|
34
24
|
};
|
|
35
25
|
|
|
36
26
|
test('renders map component', () => {
|
|
37
|
-
const store = mockStore({
|
|
38
|
-
intl: {
|
|
39
|
-
locale: 'en',
|
|
40
|
-
messages: {},
|
|
41
|
-
},
|
|
42
|
-
content: {
|
|
43
|
-
create: {},
|
|
44
|
-
},
|
|
45
|
-
connected_data_parameters: {},
|
|
46
|
-
});
|
|
47
27
|
const component = renderer.create(
|
|
48
|
-
<Provider store={store}>
|
|
28
|
+
<Provider store={global.store}>
|
|
49
29
|
<MapView
|
|
50
30
|
content={{
|
|
51
31
|
maps: {
|
|
@@ -1,5 +1,20 @@
|
|
|
1
|
+
import { connect } from 'react-redux';
|
|
2
|
+
import { pickMetadata } from '@eeacms/volto-embed/helpers';
|
|
1
3
|
import EmbedMap from '@eeacms/volto-embed/EmbedMap/EmbedMap';
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
return
|
|
5
|
+
function MapsViewWidget({ id, value, content }) {
|
|
6
|
+
return (
|
|
7
|
+
<EmbedMap
|
|
8
|
+
data={{
|
|
9
|
+
...(value || {}),
|
|
10
|
+
...pickMetadata(content),
|
|
11
|
+
with_share: true,
|
|
12
|
+
}}
|
|
13
|
+
id={id}
|
|
14
|
+
/>
|
|
15
|
+
);
|
|
5
16
|
}
|
|
17
|
+
|
|
18
|
+
export default connect((state) => ({ content: state.content.data }))(
|
|
19
|
+
MapsViewWidget,
|
|
20
|
+
);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useMemo, useState } from 'react';
|
|
2
|
-
import { useIntl, FormattedMessage } from 'react-intl';
|
|
2
|
+
import { useIntl, FormattedMessage, defineMessages } from 'react-intl';
|
|
3
3
|
import { Icon } from '@plone/volto/components';
|
|
4
4
|
import { Button, Modal, Grid, Label, Input, Message } from 'semantic-ui-react';
|
|
5
5
|
import { map } from 'lodash';
|
|
@@ -12,6 +12,13 @@ import clearSVG from '@plone/volto/icons/clear.svg';
|
|
|
12
12
|
import aheadSVG from '@plone/volto/icons/ahead.svg';
|
|
13
13
|
import mapsBlockSVG from '@plone/volto/components/manage/Blocks/Maps/block-maps.svg';
|
|
14
14
|
|
|
15
|
+
const messages = defineMessages({
|
|
16
|
+
MapsBlockInputPlaceholder: {
|
|
17
|
+
id: 'Enter map Embed Code',
|
|
18
|
+
defaultMessage: 'Enter map Embed Code',
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
|
|
15
22
|
function MapEditorModal({ id, onClose, onChange, ...rest }) {
|
|
16
23
|
const intl = useIntl();
|
|
17
24
|
const [value, setValue] = useState(rest.value);
|
|
@@ -24,7 +31,9 @@ function MapEditorModal({ id, onClose, onChange, ...rest }) {
|
|
|
24
31
|
);
|
|
25
32
|
|
|
26
33
|
const placeholder = useMemo(
|
|
27
|
-
() =>
|
|
34
|
+
() =>
|
|
35
|
+
value.placeholder ||
|
|
36
|
+
intl.formatMessage(messages.MapsBlockInputPlaceholder),
|
|
28
37
|
[value.placeholder, intl],
|
|
29
38
|
);
|
|
30
39
|
|