Skip to content

Commit 71ca2cd

Browse files
committed
Internal: Updated blocks:
1 parent bb41bb5 commit 71ca2cd

15 files changed

Lines changed: 452 additions & 77 deletions

File tree

packages/volto-code-block/src/components/Blocks/Code/DefaultView.jsx

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,30 @@ const CodeView = (props) => {
1414
wrapLongLines,
1515
caption_title,
1616
caption_description,
17+
styles = {},
1718
} = props;
19+
const align = styles?.align || 'center';
20+
const size = styles?.size || 'l';
1821
const styleWrap = wrapLongLines ? 'wrapLongLines' : '';
1922
const codeClassName = `code-block-wrapper ${codeStyle} ${styleWrap}`;
2023

2124
return (
2225
<>
2326
{code && (
24-
<div className={cx('block code', className)}>
25-
<div className={codeClassName}>
26-
<SyntaxHighlighter
27-
code={code}
28-
language={language}
29-
showLineNumbers={showLineNumbers}
30-
lineNbr={lineNbr}
31-
/>
27+
<div className={cx('block code', className, `align-${align}`)}>
28+
<div className={`code-content-wrapper block-${size}`}>
29+
<div className={codeClassName}>
30+
<SyntaxHighlighter
31+
code={code}
32+
language={language}
33+
showLineNumbers={showLineNumbers}
34+
lineNbr={lineNbr}
35+
/>
36+
</div>
37+
{caption_title && (
38+
<Caption title={caption_title} description={caption_description} />
39+
)}
3240
</div>
33-
{caption_title && (
34-
<Caption title={caption_title} description={caption_description} />
35-
)}
3641
</div>
3742
)}
3843
</>

packages/volto-code-block/src/components/Blocks/Code/Edit.jsx

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import { highlight } from 'prismjs/components/prism-core';
1010
const CodeBlockEdit = (props) => {
1111
const { data, selected, block, onChangeBlock } = props;
1212
const [code, setCode] = React.useState(data.code || '');
13+
const styles = data.styles || {};
14+
const align = styles?.align || 'center';
15+
const size = styles?.size || 'l';
1316
const className = `code-block-wrapper edit ${data.style}`;
1417
const codeBlockConfig = config.blocks?.blocksConfig?.codeBlock;
1518
const defaultLanguage = codeBlockConfig?.defaultLanguage;
@@ -27,22 +30,24 @@ const CodeBlockEdit = (props) => {
2730
};
2831

2932
return (
30-
<div className="block code">
31-
<div className={className}>
32-
<Editor
33-
value={code}
34-
onValueChange={(code) => handleChange(code)}
35-
highlight={(code) => highlight(code, language)}
36-
padding={10}
37-
preClassName={`code-block-wrapper ${data.style} language-${data.language}`}
38-
/>
33+
<div className={`block code align-${align}`}>
34+
<div className={`code-content-wrapper block-${size}`}>
35+
<div className={className}>
36+
<Editor
37+
value={code}
38+
onValueChange={(code) => handleChange(code)}
39+
highlight={(code) => highlight(code, language)}
40+
padding={10}
41+
preClassName={`code-block-wrapper ${data.style} language-${data.language}`}
42+
/>
43+
</div>
3944
{caption_title && (
4045
<Caption title={caption_title} description={caption_description} />
4146
)}
42-
<SidebarPortal selected={selected}>
43-
<CodeBlockData {...props} />
44-
</SidebarPortal>
4547
</div>
48+
<SidebarPortal selected={selected}>
49+
<CodeBlockData {...props} />
50+
</SidebarPortal>
4651
</div>
4752
);
4853
};

packages/volto-code-block/src/components/Blocks/Code/schema.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { defineMessages } from 'react-intl';
2+
import { addStyling } from '@plone/volto/helpers/Extensions/withBlockSchemaEnhancer';
23
import STYLES from '../../SyntaxHighlighter/Styles';
34
import config from '@plone/volto/registry';
45

@@ -39,6 +40,10 @@ const messages = defineMessages({
3940
id: 'Caption',
4041
defaultMessage: 'Caption',
4142
},
43+
size: {
44+
id: 'Size',
45+
defaultMessage: 'Size',
46+
},
4247
});
4348

4449
export const codeSchema = (props) => {
@@ -61,7 +66,7 @@ export const codeSchema = (props) => {
6166
return STYLES.map((item) => [item[0], props.intl.formatMessage(item[1])]);
6267
};
6368

64-
return {
69+
const schema = {
6570
title: props.intl.formatMessage(messages.codeBlock),
6671
fieldsets: [
6772
{
@@ -120,4 +125,20 @@ export const codeSchema = (props) => {
120125
},
121126
required: ['language'],
122127
};
128+
// Add styling with alignment
129+
addStyling({ schema, intl: props.intl });
130+
schema.properties.styles.schema.properties.align = {
131+
widget: 'align',
132+
title: 'Alignment',
133+
actions: ['left', 'center', 'right'],
134+
default: 'center',
135+
};
136+
schema.properties.styles.schema.properties.size = {
137+
title: props.intl.formatMessage(messages.size),
138+
widget: 'image_size',
139+
default: 'l',
140+
};
141+
schema.properties.styles.schema.fieldsets[0].fields.push('align');
142+
schema.properties.styles.schema.fieldsets[0].fields.push('size');
143+
return schema;
123144
};

packages/volto-code-block/src/components/Blocks/Gist/DefaultView.jsx

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
11
import React from 'react';
22
import Gist from 'react-gist';
33
import Caption from '../../Caption/Caption';
4+
import cx from 'classnames';
45

56
const GistView = (props) => {
6-
const { file, gistId, caption_title, caption_description } = props;
7+
const {
8+
file,
9+
gistId,
10+
caption_title,
11+
caption_description,
12+
className,
13+
styles = {},
14+
} = props;
15+
const align = styles?.align || 'center';
16+
const size = styles?.size || 'l';
17+
718
return (
8-
<>
9-
{gistId && <Gist id={gistId} file={file} />}
10-
{caption_title && (
11-
<Caption title={caption_title} description={caption_description} />
12-
)}
13-
</>
19+
<div className={cx('block gist', className, `align-${align}`)}>
20+
<div className={`gist-content-wrapper block-${size}`}>
21+
<div className="gistWrapper">
22+
{gistId && <Gist id={gistId} file={file} />}
23+
</div>
24+
{caption_title && (
25+
<Caption title={caption_title} description={caption_description} />
26+
)}
27+
</div>
28+
</div>
1429
);
1530
};
1631

packages/volto-code-block/src/components/Blocks/Gist/Edit.jsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import GistBlockData from './Data';
55
import View from './DefaultView';
66

77
const GistBlockEdit = (props) => {
8-
const { data, selected, block } = props;
9-
const { gistId, file } = data;
10-
const { caption_title, caption_description } = data;
8+
const { data, selected, block, className } = props;
9+
const { gistId, file, styles, caption_title, caption_description } = data;
10+
1111
return (
1212
<div className="block gist edit" id={`gistBlock-${block}`}>
1313
{data && (
@@ -18,6 +18,8 @@ const GistBlockEdit = (props) => {
1818
file={file}
1919
caption_title={caption_title}
2020
caption_description={caption_description}
21+
className={className}
22+
styles={styles}
2123
/>
2224
</>
2325
)}

packages/volto-code-block/src/components/Blocks/Gist/View.jsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@ import { withBlockExtensions } from '@plone/volto/helpers/Extensions';
33
import GistView from './DefaultView';
44

55
const GistBlockView = (props) => {
6-
const { data, block } = props;
7-
const { gistId, file, caption_title, caption_description } = data;
6+
const { data, block, className } = props;
7+
const { gistId, file, caption_title, caption_description, styles } = data;
8+
89
return (
9-
<div className="block gist view" id={`gistBlock-${block}`}>
10+
<div id={`gistBlock-${block}`}>
1011
{data && (
1112
<GistView
1213
caption_title={caption_title}
1314
caption_description={caption_description}
1415
gistId={gistId}
1516
file={file}
1617
block={block}
18+
className={className}
19+
styles={styles}
1720
/>
1821
)}
1922
</div>

packages/volto-code-block/src/components/Blocks/Gist/schema.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { defineMessages } from 'react-intl';
2+
import { addStyling } from '@plone/volto/helpers/Extensions/withBlockSchemaEnhancer';
23

34
const messages = defineMessages({
45
gistBlock: {
@@ -21,10 +22,18 @@ const messages = defineMessages({
2122
id: 'Description',
2223
defaultMessage: 'Description',
2324
},
25+
align: {
26+
id: 'Alignment',
27+
defaultMessage: 'Alignment',
28+
},
29+
size: {
30+
id: 'Size',
31+
defaultMessage: 'Size',
32+
},
2433
});
2534

2635
export const gistSchema = (props) => {
27-
return {
36+
const schema = {
2837
title: props.intl.formatMessage(messages.gistBlock),
2938
fieldsets: [
3039
{
@@ -56,4 +65,20 @@ export const gistSchema = (props) => {
5665
},
5766
required: ['gistId'],
5867
};
68+
// Add styling with alignment and size
69+
addStyling({ schema, intl: props.intl });
70+
schema.properties.styles.schema.properties.align = {
71+
widget: 'align',
72+
title: props.intl.formatMessage(messages.align),
73+
actions: ['left', 'center', 'right'],
74+
default: 'center',
75+
};
76+
schema.properties.styles.schema.properties.size = {
77+
title: props.intl.formatMessage(messages.size),
78+
widget: 'image_size',
79+
default: 'l',
80+
};
81+
schema.properties.styles.schema.fieldsets[0].fields.push('align');
82+
schema.properties.styles.schema.fieldsets[0].fields.push('size');
83+
return schema;
5984
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react';
2+
import { BlockDataForm } from '@plone/volto/components/manage/Form';
3+
import { mermaidSchema } from './schema';
4+
import { useIntl } from 'react-intl';
5+
6+
const MermaidBlockData = (props) => {
7+
const { block, blocksConfig, data, onChangeBlock, navRoot, contentType } =
8+
props;
9+
const intl = useIntl();
10+
const schema = mermaidSchema({ ...props, intl });
11+
12+
return (
13+
<BlockDataForm
14+
schema={schema}
15+
title={schema.title}
16+
onChangeField={(id, value) => {
17+
onChangeBlock(block, {
18+
...data,
19+
[id]: value,
20+
});
21+
}}
22+
onChangeBlock={onChangeBlock}
23+
formData={data}
24+
block={block}
25+
blocksConfig={blocksConfig}
26+
navRoot={navRoot}
27+
contentType={contentType}
28+
/>
29+
);
30+
};
31+
32+
export default MermaidBlockData;

packages/volto-code-block/src/components/Blocks/Mermaid/DefaultView.jsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import React, { useEffect, useState } from 'react';
2+
import Caption from '../../Caption/Caption';
3+
import cx from 'classnames';
24

35
const MermaidView = (props) => {
4-
const { code, block } = props;
6+
const { code, block, styles = {}, caption_title, caption_description, className } = props;
7+
const align = styles?.align || 'center';
58
const elementId = `mermaid-${block}`;
69
const [mermaid, setMermaid] = useState(null);
710
const [svg, setSVG] = useState('');
@@ -34,9 +37,18 @@ const MermaidView = (props) => {
3437
}, [mermaid, elementId, code]);
3538

3639
return (
37-
<div className={'mermaidWrapper'}>
38-
{svg && <div dangerouslySetInnerHTML={{ __html: svg }} />}
39-
</div>
40+
<>
41+
{code && (
42+
<div className={cx('block mermaid', className, `align-${align}`)}>
43+
<div className="mermaidWrapper">
44+
{svg && <div dangerouslySetInnerHTML={{ __html: svg }} />}
45+
{caption_title && (
46+
<Caption title={caption_title} description={caption_description} />
47+
)}
48+
</div>
49+
</div>
50+
)}
51+
</>
4052
);
4153
};
4254

packages/volto-code-block/src/components/Blocks/Mermaid/Edit.jsx

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import React from 'react';
22
import { withBlockExtensions } from '@plone/volto/helpers/Extensions';
3+
import SidebarPortal from '@plone/volto/components/manage/Sidebar/SidebarPortal';
34
import config from '@plone/volto/registry';
45
import Editor from '../../Editor/Editor.tsx';
56
import { highlight } from 'prismjs/components/prism-core';
7+
import MermaidBlockData from './Data';
68

79
const MermaidBlockEdit = (props) => {
8-
const { data, block, onChangeBlock } = props;
10+
const { data, block, onChangeBlock, selected } = props;
911
const [code, setCode] = React.useState(data.code || '');
1012
const className = `code-block-wrapper edit light`;
1113
const allLanguages = config.settings.codeBlock.languages;
@@ -17,17 +19,22 @@ const MermaidBlockEdit = (props) => {
1719
};
1820

1921
return (
20-
<div className="block code">
21-
<div className={className}>
22-
<Editor
23-
value={code}
24-
onValueChange={(code) => handleChange(code)}
25-
highlight={(code) => highlight(code, language)}
26-
padding={10}
27-
preClassName={`code-block-wrapper ${data.style} language-mermaid`}
28-
/>
22+
<>
23+
<div className="block code">
24+
<div className={className}>
25+
<Editor
26+
value={code}
27+
onValueChange={(code) => handleChange(code)}
28+
highlight={(code) => highlight(code, language)}
29+
padding={10}
30+
preClassName={`code-block-wrapper ${data.style} language-mermaid`}
31+
/>
32+
</div>
2933
</div>
30-
</div>
34+
<SidebarPortal selected={selected}>
35+
<MermaidBlockData {...props} />
36+
</SidebarPortal>
37+
</>
3138
);
3239
};
3340

0 commit comments

Comments
 (0)