diff --git a/src/helpers/index.js b/src/helpers/index.js index 612efda42..8a66b4164 100644 --- a/src/helpers/index.js +++ b/src/helpers/index.js @@ -15,7 +15,7 @@ export { contentFolderHasItems, renderPDCItemValue, } from 'design-comuni-plone-theme/helpers/contentHelper'; -export { checkRedraftHasContent } from 'design-comuni-plone-theme/helpers/redraftHelper'; +export { checkRichTextHasContent } from 'design-comuni-plone-theme/helpers/richTextHelper'; export { getTableRowData } from 'design-comuni-plone-theme/helpers/amministrazioneTrasparenteHelper'; export { getItemsByPath } from 'design-comuni-plone-theme/helpers/getItemsByPath'; export { diff --git a/src/helpers/redraftHelper.js b/src/helpers/redraftHelper.js deleted file mode 100644 index 5e0850a94..000000000 --- a/src/helpers/redraftHelper.js +++ /dev/null @@ -1,9 +0,0 @@ -/* - Used to verify that redraft text blocks are empty -*/ -export const checkRedraftHasContent = (text) => { - if (text) { - let blocks = text.blocks.filter((block) => block?.text !== ''); - return blocks.length > 0 ? true : false; - } -}; diff --git a/src/helpers/richTextHelper.js b/src/helpers/richTextHelper.js new file mode 100644 index 000000000..09f4c9a50 --- /dev/null +++ b/src/helpers/richTextHelper.js @@ -0,0 +1,12 @@ +import { serializeNodesToText } from '@plone/volto-slate/editor/render'; +/* + Used to verify if slate text blocks are empty +*/ +export const checkRichTextHasContent = (text) => { + if (text?.[0]?.children) { + return serializeNodesToText(text?.[0]?.children || [])?.length > 0 + ? true + : false; + } + return false; +};