; }; -export default View; +export default withBlockExtensions(View); diff --git a/src/Blocks/Quote/index.js b/src/Blocks/Quote/index.js index cd9c8e8..c0bef8f 100644 --- a/src/Blocks/Quote/index.js +++ b/src/Blocks/Quote/index.js @@ -1,7 +1,7 @@ import quoteSVG from '@plone/volto/icons/quote.svg'; import QuoteEdit from './Edit'; import QuoteView from './View'; -import PullquoteView from './templates/Pullquote/Pullquote'; +import QuoteVariations from './variations'; export default (config) => { config.blocks.blocksConfig.quote = { @@ -11,16 +11,7 @@ export default (config) => { group: 'text', edit: QuoteEdit, view: QuoteView, - templates: { - default: { - title: 'Quote', - view: PullquoteView, - icons: { - openQuote: 'quote left', - closeQuote: 'quote right', - }, - }, - }, + variations: QuoteVariations, blockHasOwnFocusManagement: true, restricted: false, mostUsed: false, @@ -30,5 +21,12 @@ export default (config) => { view: [], }, }; + + // Footnotes + config.settings.blocksWithFootnotesSupport = { + ...(config.settings.blocksWithFootnotesSupport || {}), + quote: ['value', 'source', 'extra', 'title'], + }; + return config; }; diff --git a/src/Blocks/Quote/schema.js b/src/Blocks/Quote/schema.js index d373936..b81f4cb 100644 --- a/src/Blocks/Quote/schema.js +++ b/src/Blocks/Quote/schema.js @@ -2,67 +2,43 @@ import config from '@plone/volto/registry'; export default (props) => { const { position } = props.data; - const templatesConfig = config.blocks.blocksConfig.quote?.templates; - const templates = Object.keys(templatesConfig).map((template) => [ - template, - templatesConfig[template].title || template, - ]); - const schema = - templatesConfig[props.data?.template || 'default']?.schema || []; - const templateSchema = typeof schema === 'function' ? schema(props) : schema; - const defaultFieldset = - templateSchema.fieldsets?.filter( - (fieldset) => fieldset.id === 'default', - )[0] || {}; + const variations = config.blocks.blocksConfig.quote.variations; + return { - title: templateSchema.title || 'Quote', + title: 'Quote', fieldsets: [ { id: 'default', title: 'Default', fields: [ - 'template', + 'variation', ...(position && ['left', 'right'].includes(position) - ? ['quote'] + ? ['value'] : []), - 'reversed', - 'position', 'source', - 'metadata', - ...(defaultFieldset?.fields || []), + 'extra', ], }, - ...(templateSchema.fieldsets?.filter( - (fieldset) => fieldset.id !== 'default', - ) || []), ], properties: { - template: { - title: 'Template', - choices: templates, - }, - reversed: { - title: 'Reversed', - type: 'boolean', - }, - position: { - title: 'Alignment', - widget: 'align', + variation: { + title: 'Variation', + choices: variations.map((extension) => [extension.id, extension.title]), + defaultValue: 'default', }, - quote: { + value: { title: 'Quote', - widget: 'slate_richtext', + widget: 'slate', }, source: { title: 'Source', - widget: 'slate_richtext', + widget: 'slate', }, - metadata: { + extra: { title: 'Extra info', - widget: 'slate_richtext', + widget: 'slate', }, - ...(templateSchema.properties || {}), }, - required: [...(templateSchema.required || [])], + required: [], }; }; diff --git a/src/Blocks/Quote/styles.less b/src/Blocks/Quote/styles.less index edbaf13..5608425 100644 --- a/src/Blocks/Quote/styles.less +++ b/src/Blocks/Quote/styles.less @@ -1,7 +1,7 @@ -.eea.blockquote .quote > *:not(.meta) { - margin-bottom: 0; +.quote { + width: 100%; } -.eea.pullquote .quotes { - flex-flow: column; +div.quote { + margin-bottom: 1em; } diff --git a/src/Blocks/Quote/templates/Blockquote/Blockquote.jsx b/src/Blocks/Quote/templates/Blockquote/Blockquote.jsx deleted file mode 100644 index 650cb3c..0000000 --- a/src/Blocks/Quote/templates/Blockquote/Blockquote.jsx +++ /dev/null @@ -1,157 +0,0 @@ -import React from 'react'; -import { connect } from 'react-redux'; -import cx from 'classnames'; -import { Message } from 'semantic-ui-react'; -import config from '@plone/volto/registry'; -import SlateEditor from 'volto-slate/editor/SlateEditor'; -import { handleKey } from 'volto-slate/blocks/Text/keyboard'; -import { saveSlateBlockSelection } from 'volto-slate/actions'; -import { - createSlateParagraph, - isFloated, - serializeText, - textNotEmpty, -} from '@eeacms/volto-quote-block/helpers'; - -import '@eeacms/volto-quote-block/less/blockquote.less'; - -const BlockquoteWrapper = (props) => { - const { children, index, block, mode, handleKeyDown } = props; - return mode === 'edit' ? ( -
--- {mode === 'edit' && !floated ? ( -
- {withInfo && ( -{ - onChangeBlock(block, { - ...data, - quote, - }); - }} - block={block} - onFocus={handleFocus} - onKeyDown={handleKey} - selected={selected} - placeholder="Add quote" - slateSettings={slate} - /> - ) : ( - serializeText(quote) - )} - - {source &&- )} -{serializeText(source)}
} - {metadata &&{serializeText(metadata)}
} -
- {mode === 'edit' && !floated ? ( --- - ) : ( -{ - onChangeBlock(block, { - ...data, - quote, - }); - }} - block={block} - onFocus={handleFocus} - onKeyDown={handleKey} - selected={selected} - placeholder="Add quote" - slateSettings={slate} - /> - - {serializeText(quote)} - - )} - {withInfo && ( -- {source &&- )} +{serializeText(source)}
} - {metadata &&{serializeText(metadata)}
} -+ {reversed && source && ( +{serializeText(source)} + )} + {reversed && extra && ( +{serializeText(extra)} + )} + {mode === 'edit' && !floated ? ( ++ + ) : ( +{ + onChangeBlock(block, { + ...data, + value, + }); + }} + block={block} + onFocus={handleFocus} + onKeyDown={handleKey} + selected={selected} + placeholder="Add quote" + slateSettings={slate} + /> + {serializeText(value)} + )} + {!reversed && source && ( +{serializeText(source)} + )} + {!reversed && extra && ( +{serializeText(extra)} + )} +
{children}
+++); + +export default Testimonial; diff --git a/src/Blocks/Quote/variations/index.js b/src/Blocks/Quote/variations/index.js new file mode 100644 index 0000000..15bfc4d --- /dev/null +++ b/src/Blocks/Quote/variations/index.js @@ -0,0 +1,65 @@ +import DefaultQuote from './DefaultQuote'; +import TestimonialQuote from './TestimonialQuote'; + +export default [ + { + id: 'default', + title: 'Quote (default)', + view: DefaultQuote, + isDefault: true, + schemaEnhancer: (props) => { + const { schema } = props; + return { + ...schema, + fieldsets: [ + ...schema.fieldsets, + { id: 'layout', title: 'Layout', fields: ['position', 'reversed'] }, + ], + properties: { + ...schema.properties, + position: { + title: 'Alignment', + widget: 'align', + }, + reversed: { + title: 'Reversed', + type: 'boolean', + }, + }, + }; + }, + }, + { + id: 'testimonial', + title: 'Testimonial quote', + view: TestimonialQuote, + isDefault: true, + schemaEnhancer: (props) => { + const { schema } = props; + return { + ...schema, + fieldsets: [ + ...schema.fieldsets, + { + id: 'testimonial', + title: 'Testimonial', + fields: ['title', 'image'], + }, + ], + properties: { + ...schema.properties, + title: { + title: 'Title', + widget: 'slate', + }, + image: { + title: 'Image', + widget: 'attachedimage', + mode: 'image', + return: 'single', + }, + }, + }; + }, + }, +]; diff --git a/src/SlatePlugins/Quote/Quote.jsx b/src/SlatePlugins/Quote/Quote.jsx deleted file mode 100644 index 1033cc7..0000000 --- a/src/SlatePlugins/Quote/Quote.jsx +++ /dev/null @@ -1,11 +0,0 @@ -import React from 'react'; -import templates from './templates'; - -function Quote(props) { - const data = props.element.data || {}; - const QuoteElement = templates[data.template || 'default'].view; - - return++{children} +
-- ); -}; - -Pullquote.Quote = ({ children, as: As, ...rest }) => ( -{children} - {(source || metadata) && ( -- {source &&- )} -{serializeText(source)}
} - {metadata &&{serializeText(metadata)}
} -
{children}
- )} -