-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: removed imports from volto barrel files
- Loading branch information
1 parent
73da1d7
commit 27db7f0
Showing
5 changed files
with
76 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* CustomRichTextWidget, a slate widget variant that saves its data as HTML | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
import { makeEditor } from '@plone/volto-slate/utils'; | ||
import deserialize from '@plone/volto-slate/editor/deserialize'; | ||
|
||
import { | ||
createEmptyParagraph, | ||
normalizeExternalData, | ||
} from '@plone/volto-slate/utils'; | ||
|
||
import config from '@plone/volto/registry'; | ||
|
||
const CustomRichTextWidget = (props) => { | ||
const { | ||
id, | ||
onChange, | ||
value, | ||
focus, | ||
className, | ||
block, | ||
placeholder, | ||
properties, | ||
intl, | ||
} = props; | ||
const editor = React.useMemo(() => makeEditor(), []); | ||
|
||
const fromHtml = React.useCallback( | ||
(value) => { | ||
const html = value?.data || ''; | ||
|
||
const parsed = new DOMParser().parseFromString(html, 'text/html'); | ||
const body = | ||
parsed.getElementsByTagName('google-sheets-html-origin').length > 0 | ||
? parsed.querySelector('google-sheets-html-origin > table') | ||
: parsed.body; | ||
let data = deserialize(editor, body, { collapseWhitespace: false }); | ||
data = normalizeExternalData(editor, data); | ||
|
||
// editor.children = data; | ||
// Editor.normalize(editor); | ||
// TODO: need to add {text: ""} placeholders between elements | ||
const res = data.length ? data : [createEmptyParagraph()]; | ||
// console.log('from html', { html: value?.data, res }); | ||
return res; | ||
}, | ||
[editor], | ||
); | ||
|
||
const _value = React.useMemo(() => { | ||
return config.widgets.widget.slate && typeof value === 'string' | ||
? fromHtml(value) | ||
: value; | ||
}, [value, fromHtml]); | ||
let RichTextWidget = config.widgets.widget.richtext; | ||
if (config.widgets.widget.slate) { | ||
//there's slate in this site. Don't use widget.richtext because is html widget and cannot handle intl provider. So convert value to slate object and use config.widgets.widget.slate | ||
RichTextWidget = config.widgets.widget.slate; | ||
} | ||
|
||
const editor = React.useMemo(() => makeEditor(), []); | ||
|
||
return <RichTextWidget />; | ||
}; | ||
|
||
export default CustomRichTextWidget; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters