@eeacms/volto-eea-website-policy 0.2.2 → 0.2.3

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,24 @@ 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
+ #### [0.2.3](https://github.com/eea/volto-eea-website-policy/compare/0.2.2...0.2.3)
8
+
9
+ - prettier fix [`c2a6d2d`](https://github.com/eea/volto-eea-website-policy/commit/c2a6d2d3b12ce771b9b4413c5a6db157ccd9d1fc)
10
+ - Update index.js [`fb73895`](https://github.com/eea/volto-eea-website-policy/commit/fb7389509bc7e207942762c5e02a93d0168a6fba)
11
+ - removed change from commit 719e3778 [`29e636b`](https://github.com/eea/volto-eea-website-policy/commit/29e636b34ab02992c67cc5960f4dc6b21b1b4e71)
12
+ - added navDepth to level 4 in order to fill mega menu [`719e377`](https://github.com/eea/volto-eea-website-policy/commit/719e37785cfa2ed37568c82a34dc470b52483d04)
13
+ - Rearrange Block Chooser [`9a5c118`](https://github.com/eea/volto-eea-website-policy/commit/9a5c1187ba21fa1898394a4b6cf6dd68bd68f258)
14
+ - Move Item block un components folder [`9fb6ab2`](https://github.com/eea/volto-eea-website-policy/commit/9fb6ab2fb02cc5c1a7e25367de5ebe7109bd3dc4)
15
+ - Set default sizes for image & icon in Item block [`af22ec7`](https://github.com/eea/volto-eea-website-policy/commit/af22ec78b2c6fd1d033dc1acfec5e64f8926cd77)
16
+ - Add helpers functions [`353581c`](https://github.com/eea/volto-eea-website-policy/commit/353581cc6602b5e573eee93c74a67656203c0968)
17
+ - Add Item block [`617bfe2`](https://github.com/eea/volto-eea-website-policy/commit/617bfe2b827708ddb2c5eecd8fe1cc6fee37f60a)
18
+ - Add Teaser block folder's structure [`9457dd4`](https://github.com/eea/volto-eea-website-policy/commit/9457dd4ffaa2631eceb46bfd1ec2d201e8b3d7a8)
19
+
7
20
  #### [0.2.2](https://github.com/eea/volto-eea-website-policy/compare/0.2.1...0.2.2)
8
21
 
9
- - Install callout and remove blockquote - refs #148688 [`53ba5a7`](https://github.com/eea/volto-eea-website-policy/commit/53ba5a7153e30f4f41221323393e41d53132fdae)
22
+ > 24 May 2022
23
+
24
+ - Install callout and remove blockquote - refs #148688 [`#8`](https://github.com/eea/volto-eea-website-policy/pull/8)
10
25
 
11
26
  #### [0.2.1](https://github.com/eea/volto-eea-website-policy/compare/0.2.0...0.2.1)
12
27
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-eea-website-policy",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "@eeacms/volto-eea-website-policy: Volto add-on",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: IDM2 A-Team",
@@ -0,0 +1,98 @@
1
+ import React from 'react';
2
+ import { connect } from 'react-redux';
3
+ import config from '@plone/volto/registry';
4
+ import { BlockDataForm, SidebarPortal } from '@plone/volto/components';
5
+ import SlateEditor from 'volto-slate/editor/SlateEditor';
6
+ import { handleKey } from 'volto-slate/blocks/Text/keyboard';
7
+ import { uploadContent, saveSlateBlockSelection } from 'volto-slate/actions';
8
+
9
+ import { createSlateParagraph } from '@eeacms/volto-eea-website-policy/helpers';
10
+
11
+ import Item from './Item';
12
+ import getSchema from './schema';
13
+
14
+ const Edit = (props) => {
15
+ const { slate } = config.settings;
16
+ const {
17
+ data = {},
18
+ block = null,
19
+ selected = false,
20
+ index,
21
+ properties,
22
+ onChangeBlock,
23
+ onSelectBlock,
24
+ } = props;
25
+ const { description } = data;
26
+ const schema = React.useMemo(() => getSchema(props), [props]);
27
+
28
+ const withBlockProperties = React.useCallback(
29
+ (editor) => {
30
+ editor.getBlockProps = () => props;
31
+ return editor;
32
+ },
33
+ [props],
34
+ );
35
+
36
+ const handleFocus = React.useCallback(() => {
37
+ if (!selected) {
38
+ onSelectBlock(block);
39
+ }
40
+ }, [onSelectBlock, selected, block]);
41
+
42
+ return (
43
+ <>
44
+ <Item {...data} mode="edit">
45
+ <SlateEditor
46
+ index={index}
47
+ properties={properties}
48
+ extensions={slate.textblockExtensions}
49
+ renderExtensions={[withBlockProperties]}
50
+ value={createSlateParagraph(description)}
51
+ onChange={(description) => {
52
+ onChangeBlock(block, {
53
+ ...data,
54
+ description,
55
+ });
56
+ }}
57
+ block={block}
58
+ onFocus={handleFocus}
59
+ onKeyDown={handleKey}
60
+ selected={selected}
61
+ placeholder="Add item description..."
62
+ slateSettings={slate}
63
+ />
64
+ </Item>
65
+ <SidebarPortal selected={selected}>
66
+ <BlockDataForm
67
+ block={block}
68
+ schema={schema}
69
+ title={schema.title}
70
+ onChangeField={(id, value) => {
71
+ onChangeBlock(block, {
72
+ ...data,
73
+ [id]: value,
74
+ });
75
+ }}
76
+ formData={data}
77
+ />
78
+ </SidebarPortal>
79
+ </>
80
+ );
81
+ };
82
+
83
+ export default connect(
84
+ (state, props) => {
85
+ const blockId = props.block;
86
+ return {
87
+ defaultSelection: blockId
88
+ ? state.slate_block_selections?.[blockId]
89
+ : null,
90
+ uploadRequest: state.upload_content?.[props.block]?.upload || {},
91
+ uploadedContent: state.upload_content?.[props.block]?.data || {},
92
+ };
93
+ },
94
+ {
95
+ uploadContent,
96
+ saveSlateBlockSelection, // needed as editor blockProps
97
+ },
98
+ )(Edit);
@@ -0,0 +1,50 @@
1
+ import cx from 'classnames';
2
+ import { Item as UiItem, Icon } from 'semantic-ui-react';
3
+ import { serializeText } from '@eeacms/volto-eea-website-policy/helpers';
4
+
5
+ function Item({
6
+ assetType,
7
+ children,
8
+ description,
9
+ extra,
10
+ header,
11
+ icon,
12
+ iconSize = 'huge',
13
+ iconTheme,
14
+ image,
15
+ imageSize = 'tile',
16
+ meta,
17
+ mode = 'view',
18
+ styles = {},
19
+ }) {
20
+ const { verticalAlign } = styles;
21
+ return (
22
+ <UiItem.Group unstackable className="row">
23
+ <UiItem className={cx(styles?.theme)}>
24
+ {assetType === 'image' && image && (
25
+ <UiItem.Image
26
+ src={`${image}/@@images/image/preview`}
27
+ className={cx('ui', imageSize)}
28
+ alt={header || 'Item image'}
29
+ />
30
+ )}
31
+ {assetType === 'icon' && icon && (
32
+ <Icon className={cx(icon, iconTheme)} size={iconSize} />
33
+ )}
34
+ <UiItem.Content verticalAlign={verticalAlign}>
35
+ {header && <UiItem.Header>{header}</UiItem.Header>}
36
+ {meta && <UiItem.Meta>{meta}</UiItem.Meta>}
37
+ {description && mode === 'view' && (
38
+ <UiItem.Description>
39
+ {serializeText(description)}
40
+ </UiItem.Description>
41
+ )}
42
+ {mode === 'edit' && children}
43
+ {extra && <UiItem.Extra>{extra}</UiItem.Extra>}
44
+ </UiItem.Content>
45
+ </UiItem>
46
+ </UiItem.Group>
47
+ );
48
+ }
49
+
50
+ export default Item;
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ import Item from './Item';
3
+
4
+ const View = (props) => {
5
+ const { data = {} } = props;
6
+ return <Item {...data} />;
7
+ };
8
+
9
+ export default View;
@@ -0,0 +1,32 @@
1
+ import codeSVG from '@plone/volto/icons/code.svg';
2
+ import ItemEdit from './Edit';
3
+ import ItemView from './View';
4
+ import { stylingSchema } from './schema';
5
+
6
+ export default (config) => {
7
+ config.blocks.blocksConfig.item = {
8
+ id: 'item',
9
+ title: 'Item',
10
+ icon: codeSVG,
11
+ group: 'common',
12
+ edit: ItemEdit,
13
+ view: ItemView,
14
+ blockHasOwnFocusManagement: true,
15
+ stylesSchema: stylingSchema,
16
+ enableStyling: true,
17
+ restricted: false,
18
+ mostUsed: false,
19
+ sidebarTab: 1,
20
+ security: {
21
+ addPermission: [],
22
+ view: [],
23
+ },
24
+ };
25
+
26
+ config.settings.blocksWithFootnotesSupport = {
27
+ ...(config.settings.blocksWithFootnotesSupport || {}),
28
+ item: ['description'],
29
+ };
30
+
31
+ return config;
32
+ };
@@ -0,0 +1,101 @@
1
+ export default ({ data }) => {
2
+ const { assetType = 'image' } = data;
3
+ return {
4
+ title: 'Item',
5
+ fieldsets: [
6
+ {
7
+ id: 'default',
8
+ title: 'Default',
9
+ fields: ['assetType'],
10
+ },
11
+ ...(assetType === 'image'
12
+ ? [{ id: 'image', title: 'Image', fields: ['image', 'imageSize'] }]
13
+ : []),
14
+ ...(assetType === 'icon'
15
+ ? [{ id: 'icon', title: 'Icon', fields: ['icon', 'iconSize'] }]
16
+ : []),
17
+ ],
18
+ properties: {
19
+ assetType: {
20
+ title: 'Asset type',
21
+ choices: [
22
+ ['image', 'Image'],
23
+ ['icon', 'Icon'],
24
+ ],
25
+ default: 'image',
26
+ },
27
+ image: {
28
+ title: 'Image',
29
+ widget: 'attachedimage',
30
+ },
31
+ imageSize: {
32
+ title: 'Image size',
33
+ choices: [
34
+ ['mini', 'Mini'],
35
+ ['tile', 'Tile'],
36
+ ['tiny', 'Tiny'],
37
+ ['small', 'Small'],
38
+ ['large', 'Large'],
39
+ ['big', 'Big'],
40
+ ['huge', 'Huge'],
41
+ ['massive', 'Massive'],
42
+ ],
43
+ default: 'tile',
44
+ },
45
+ icon: {
46
+ title: 'Icon name',
47
+ },
48
+ iconSize: {
49
+ title: 'Icon size',
50
+ choices: [
51
+ ['mini', 'Mini'],
52
+ ['tiny', 'Tiny'],
53
+ ['small', 'Small'],
54
+ ['large', 'Large'],
55
+ ['big', 'Big'],
56
+ ['huge', 'Huge'],
57
+ ['massive', 'Massive'],
58
+ ],
59
+ default: 'huge',
60
+ },
61
+ iconTheme: {
62
+ title: 'Icon theme',
63
+ choices: [
64
+ ['primary', 'Primary'],
65
+ ['secondary', 'Secondary'],
66
+ ],
67
+ },
68
+ },
69
+ required: [],
70
+ };
71
+ };
72
+
73
+ export const stylingSchema = ({ intl }) => ({
74
+ title: 'Item style',
75
+ block: 'item',
76
+ fieldsets: [
77
+ {
78
+ id: 'default',
79
+ title: 'Default',
80
+ fields: ['theme', 'verticalAlign'],
81
+ },
82
+ ],
83
+ properties: {
84
+ theme: {
85
+ title: 'Theme',
86
+ choices: [
87
+ ['primary', 'Primary'],
88
+ ['secondary', 'Secondary'],
89
+ ],
90
+ },
91
+ verticalAlign: {
92
+ title: 'Vertical align',
93
+ choices: [
94
+ ['top', 'Top'],
95
+ ['middle', 'Middle'],
96
+ ['bottom', 'Bottom'],
97
+ ],
98
+ },
99
+ },
100
+ required: [],
101
+ });
File without changes
File without changes
File without changes
File without changes
File without changes
package/src/helpers.js ADDED
@@ -0,0 +1,11 @@
1
+ import { isArray } from 'lodash';
2
+ import config from '@plone/volto/registry';
3
+ import { serializeNodes } from 'volto-slate/editor/render';
4
+
5
+ export const createSlateParagraph = (text) => {
6
+ return isArray(text) ? text : config.settings.slate.defaultValue();
7
+ };
8
+
9
+ export const serializeText = (text) => {
10
+ return isArray(text) ? serializeNodes(text) : text;
11
+ };
package/src/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { runtimeConfig } from '@plone/volto/runtime_config';
2
2
  import installCallout from 'volto-slate/editor/plugins/Callout';
3
+ import installItemBlock from '@eeacms/volto-eea-website-policy/components/Blocks/Item';
3
4
 
4
5
  const applyConfig = (config) => {
5
6
  // if (process.env.NODE_ENV === 'production') {
@@ -8,7 +9,6 @@ const applyConfig = (config) => {
8
9
  // // Restrict slate metadata mentions to Layout only
9
10
  // config.settings.layoutOnlySlateMetadataMentions = true;
10
11
  // }
11
-
12
12
  // Callout slate button
13
13
  config = installCallout(config);
14
14
 
@@ -62,6 +62,43 @@ const applyConfig = (config) => {
62
62
  (item) => item.code,
63
63
  ) || ['en'];
64
64
 
65
+ // Block chooser
66
+ config.blocks.blocksConfig.image.mostUsed = false;
67
+ config.blocks.blocksConfig.video.mostUsed = false;
68
+
69
+ // Grid/Teaser block (kitconcept)
70
+ if (config.blocks.blocksConfig.__grid) {
71
+ config.blocks.blocksConfig.__grid.restricted = true;
72
+ }
73
+ if (config.blocks.blocksConfig.imagesGrid) {
74
+ config.blocks.blocksConfig.imagesGrid.restricted = true;
75
+ }
76
+ if (config.blocks.blocksConfig.teaser) {
77
+ config.blocks.blocksConfig.teaser.restricted = true;
78
+ }
79
+ if (config.blocks.blocksConfig.teaserGrid) {
80
+ config.blocks.blocksConfig.teaserGrid.title = 'Teaser (Cards)';
81
+ }
82
+
83
+ // Divider
84
+ if (config.blocks.blocksConfig.dividerBlock) {
85
+ config.blocks.blocksConfig.dividerBlock.mostUsed = true;
86
+ }
87
+
88
+ // Call to Action
89
+ if (config.blocks.blocksConfig.callToActionBlock) {
90
+ config.blocks.blocksConfig.callToActionBlock.mostUsed = true;
91
+ }
92
+
93
+ // Columns
94
+ if (config.blocks.blocksConfig.columnsBlock) {
95
+ config.blocks.blocksConfig.columnsBlock.mostUsed = true;
96
+ }
97
+
98
+ // Custom blocks
99
+ config = [installItemBlock].reduce((acc, apply) => apply(acc), config);
100
+ config.blocks.blocksConfig.item.mostUsed = true;
101
+
65
102
  // Done
66
103
  return config;
67
104
  };