From 13cf384e5c41cb9f5741473b0ac6bda250e0ba7d Mon Sep 17 00:00:00 2001 From: Giulia Ghisini Date: Thu, 5 Oct 2023 11:10:09 +0200 Subject: [PATCH] breaking: removed draftjs in TextEditorWidget and used Slate, added SimpleTextEditorWidget for editing simple strings in blocks --- .../manage/Widgets/SimpleTextEditorWidget.jsx | 102 ++++++ .../Widgets/TextEditorDraftJSWidget.jsx | 299 ------------------ .../manage/Widgets/TextEditorWidget.jsx | 133 ++++++-- src/config/Blocks/blocks.js | 1 + src/config/Slate/config.js | 4 +- src/config/Slate/handlers.js | 58 ++++ 6 files changed, 277 insertions(+), 320 deletions(-) create mode 100644 src/components/ItaliaTheme/manage/Widgets/SimpleTextEditorWidget.jsx delete mode 100644 src/components/ItaliaTheme/manage/Widgets/TextEditorDraftJSWidget.jsx create mode 100644 src/config/Slate/handlers.js diff --git a/src/components/ItaliaTheme/manage/Widgets/SimpleTextEditorWidget.jsx b/src/components/ItaliaTheme/manage/Widgets/SimpleTextEditorWidget.jsx new file mode 100644 index 000000000..10b8e98b1 --- /dev/null +++ b/src/components/ItaliaTheme/manage/Widgets/SimpleTextEditorWidget.jsx @@ -0,0 +1,102 @@ +/** + * Edit simple text block. + * @module components/Widgets/SimpleTextEditorWidget/SimpleTextEditorWidget + * + * E' un editor di testo da mettere nei blocchi, senza formattazione. + */ + +import React from 'react'; +import { connect } from 'react-redux'; +import PropTypes from 'prop-types'; +import { defineMessages, useIntl } from 'react-intl'; +import { useInView } from 'react-intersection-observer'; + +import { handleKeyDetached } from '@plone/volto-slate/blocks/Text/keyboard'; +import { + uploadContent, + saveSlateBlockSelection, +} from '@plone/volto-slate/actions'; +import { commonSearchBlockMessages } from '../../../../helpers'; +import config from '@plone/volto/registry'; + +const messages = defineMessages({ + text: { + id: 'Type text…', + defaultMessage: 'Type text…', + }, +}); + +const SimpleTextEditorWidget = (props) => { + const intl = useIntl(); + const { + data, + setSelected, + onSelectBlock, + onChangeBlock, + block, + value, + selected, + placeholder, + } = props; + const { ref, inView } = useInView({ + threshold: 0, + rootMargin: '0px 0px 200px 0px', + }); + + const handleKey = (event) => { + const { slate } = config.settings; + + const handlers = slate.textblockDetachedKeyboardHandlers[event.key]; + + if (handlers) { + // a handler can return `true` to signify it has handled the event in this + // case, the execution flow is stopped + const handlerProps = { getBlockProps: () => props }; + return handlers.find((handler) => + handler({ editor: handlerProps, event }), + ); + } + }; + + return ( +
+