From 6180f79a798afa6fff3789673c03ebd5df9bca26 Mon Sep 17 00:00:00 2001 From: Giulia Ghisini Date: Tue, 10 Oct 2023 13:36:19 +0200 Subject: [PATCH] fix: Slate in blocks --- .../ItaliaTheme/Blocks/CTABlock/Block.jsx | 2 +- .../Blocks/IconBlocks/Block/EditBlock.jsx | 50 +++++++++++++------ .../Blocks/IconBlocks/Block/ViewBlock.jsx | 20 ++------ .../ItaliaTheme/Blocks/IconBlocks/Edit.jsx | 43 +++++++++------- .../ItaliaTheme/Blocks/IconBlocks/View.jsx | 19 ++----- src/config/Blocks/blocks.js | 1 + 6 files changed, 70 insertions(+), 65 deletions(-) diff --git a/src/components/ItaliaTheme/Blocks/CTABlock/Block.jsx b/src/components/ItaliaTheme/Blocks/CTABlock/Block.jsx index 1f0f046b0..581bbcf81 100644 --- a/src/components/ItaliaTheme/Blocks/CTABlock/Block.jsx +++ b/src/components/ItaliaTheme/Blocks/CTABlock/Block.jsx @@ -44,7 +44,7 @@ const Block = ({ data, block, inEditMode, selected, ...otherProps }) => { }, [selected]); useEffect(() => { - if (!selected && selectedField) { + if (!selected && selectedField && otherProps?.onSelectBlock) { otherProps.onSelectBlock(block); } }, [selectedField]); diff --git a/src/components/ItaliaTheme/Blocks/IconBlocks/Block/EditBlock.jsx b/src/components/ItaliaTheme/Blocks/IconBlocks/Block/EditBlock.jsx index 6426a26b8..3bd3b07dd 100644 --- a/src/components/ItaliaTheme/Blocks/IconBlocks/Block/EditBlock.jsx +++ b/src/components/ItaliaTheme/Blocks/IconBlocks/Block/EditBlock.jsx @@ -71,7 +71,7 @@ class EditBlock extends SubblockEdit { if (__SERVER__) { return
; } - + console.log(this.props); return ( this.setState({ focusOn: 'title' })} block={this.props.block} - onChangeBlock={this.onChange} + onChangeBlock={(block, _data) => { + this.props.onChangeBlock(this.props.index, _data); + }} placeholder={this.props.intl.formatMessage( messages.titlePlaceholder, )} - prevFocus="text" - nextFocus="text" - disableMoveToNearest={true} - setFocus={(f) => { - this.setState({ focusOn: f }); + focusPrevField={() => { + this.props.isFirst + ? this.props.onFocusPreviousBlock + : () => { + this.props.onSubblockChangeFocus( + this.props.index - 1, + ); + }; + }} + focusNextField={() => { + this.setState({ focusOn: 'text' }); }} - showToolbar={false} key="title" />
@@ -130,21 +140,29 @@ class EditBlock extends SubblockEdit { }} > this.setState({ focusOn: 'text' })} + onChangeBlock={(block, _data) => { + this.props.onChangeBlock(this.props.index, _data); + }} placeholder={this.props.intl.formatMessage( messages.textPlaceholder, )} - disableMoveToNearest={true} - prevFocus="title" - nextFocus="title" - setFocus={(f) => { - this.setState({ focusOn: f }); + focusNextField={ + !this.props.isLast + ? () => { + this.setState({ focusOn: null }); + this.props.onSubblockChangeFocus(this.props.index + 1); + } + : null //default go to next block + } + focusPrevField={() => { + this.setState({ focusOn: 'title' }); }} - key="text" /> diff --git a/src/components/ItaliaTheme/Blocks/IconBlocks/Block/ViewBlock.jsx b/src/components/ItaliaTheme/Blocks/IconBlocks/Block/ViewBlock.jsx index 6af951579..38eaea037 100644 --- a/src/components/ItaliaTheme/Blocks/IconBlocks/Block/ViewBlock.jsx +++ b/src/components/ItaliaTheme/Blocks/IconBlocks/Block/ViewBlock.jsx @@ -12,6 +12,7 @@ import { UniversalLink } from '@plone/volto/components'; import { Icon } from 'design-comuni-plone-theme/components/ItaliaTheme'; import { Card, CardBody, CardReadMore } from 'design-react-kit'; import config from '@plone/volto/registry'; +import { TextBlockView } from '@plone/volto-slate/blocks/Text'; const messages = defineMessages({ vedi: { @@ -25,8 +26,9 @@ const messages = defineMessages({ * @class ViewBlock * @extends Component */ -const ViewBlock = ({ data, isOpen, toggle, id, index }) => { +const ViewBlock = ({ data }) => { const intl = useIntl(); + console.log(data); return ( { )} - {data.title && ( -
- {redraft( - data.title, - config.settings.richtextViewSettings.ToHTMLRenderers, - config.settings.richtextViewSettings.ToHTMLOptions, - )} -
- )} + {data.title &&
{data.title}
} {data.text && (
- {redraft( - data.text, - config.settings.richtextViewSettings.ToHTMLRenderers, - config.settings.richtextViewSettings.ToHTMLOptions, - )} +
)} {data.href && ( diff --git a/src/components/ItaliaTheme/Blocks/IconBlocks/Edit.jsx b/src/components/ItaliaTheme/Blocks/IconBlocks/Edit.jsx index 685266b06..74d6a94b6 100644 --- a/src/components/ItaliaTheme/Blocks/IconBlocks/Edit.jsx +++ b/src/components/ItaliaTheme/Blocks/IconBlocks/Edit.jsx @@ -77,19 +77,18 @@ class Edit extends SubblocksEdit {
{ - this.props.onChangeBlock(this.props.block, { - ...data, - }); + setSelected={() => { + this.setState({ selectedField: 'title' }); + this.onSubblockChangeFocus(-1); }} placeholder={this.props.intl.formatMessage(messages.title)} - showToolbar={false} - onSelectBlock={() => {}} - onAddBlock={() => { + focusNextField={() => { this.setState({ selectedField: 'description' }); }} /> @@ -97,21 +96,25 @@ class Edit extends SubblocksEdit {
- this.props.onChangeBlock(this.props.block, { - ...data, - }) - } + setSelected={() => { + this.setState({ selectedField: 'description' }); + this.onSubblockChangeFocus(-1); + }} placeholder={this.props.intl.formatMessage( messages.description, )} - showToolbar={true} - onSelectBlock={() => {}} - onAddBlock={() => {}} + focusPrevField={() => { + this.setState({ selectedField: 'title' }); + }} + focusNextField={() => { + this.onSubblockChangeFocus(0); + this.setState({ selectedField: null }); + }} />
@@ -121,11 +124,17 @@ class Edit extends SubblocksEdit { {this.state.subblocks.map((subblock, subindex) => ( { + this.setState({ selectedField: 'description' }); + }} /> ))} diff --git a/src/components/ItaliaTheme/Blocks/IconBlocks/View.jsx b/src/components/ItaliaTheme/Blocks/IconBlocks/View.jsx index d2a985e2c..5d079dc88 100644 --- a/src/components/ItaliaTheme/Blocks/IconBlocks/View.jsx +++ b/src/components/ItaliaTheme/Blocks/IconBlocks/View.jsx @@ -5,12 +5,11 @@ import React from 'react'; import PropTypes from 'prop-types'; -import redraft from 'redraft'; import ViewBlock from './Block/ViewBlock'; import { Container, Row, Col } from 'design-react-kit'; import { flattenToAppURL, addAppURL } from '@plone/volto/helpers'; import { UniversalLink } from '@plone/volto/components'; -import config from '@plone/volto/registry'; +import { TextBlockView } from '@plone/volto-slate/blocks/Text'; /** * View Accordion block class. @@ -39,22 +38,10 @@ const AccordionView = ({ data, block }) => { )}
- {data.title && ( -
- {redraft( - data.title, - config.settings.richtextViewSettings.ToHTMLRenderers, - config.settings.richtextViewSettings.ToHTMLOptions, - )} -
- )} + {data.title &&
{data.title}
} {data.description && (
- {redraft( - data.description, - config.settings.richtextViewSettings.ToHTMLRenderers, - config.settings.richtextViewSettings.ToHTMLOptions, - )} +
)}
diff --git a/src/config/Blocks/blocks.js b/src/config/Blocks/blocks.js index 2d83c6288..817fe6c85 100644 --- a/src/config/Blocks/blocks.js +++ b/src/config/Blocks/blocks.js @@ -297,6 +297,7 @@ const italiaBlocks = { view: [], }, sidebarTab: 1, + blockHasOwnFocusManagement: true, }, contacts: { id: 'contacts',