Skip to content
Snippets Groups Projects

MEP: removed Meilisearch

Merged Rémi PAILHAREY requested to merge dev into master
6 files
+ 74
49
Compare changes
  • Side-by-side
  • Inline
Files
6
import { stateToHTML } from 'draft-js-export-html'
import React, { useCallback, useMemo, useState } from 'react'
import { convertToRaw } from 'draft-js'
import draftToHtml from 'draftjs-to-html'
import React, { useCallback, useState } from 'react'
import { Editor, EditorState } from 'react-draft-wysiwyg'
import './customEditor.scss'
import CustomLink from './CustomLink'
@@ -20,36 +21,38 @@ const CustomEditor: React.FC<CustomEditorProps> = ({
}: CustomEditorProps) => {
const [editorState, setEditorState] = useState<EditorState>(baseState)
const entityStyleFn = useMemo(
() => (entity: any) => {
const entityType = entity.get('type').toLowerCase()
if (entityType === 'link') {
const data = entity.getData()
return {
element: 'a',
attributes: {
title: data.title,
href: data.href ? data.href : data.url,
},
}
const convertStateToHTML = (state: EditorState) => {
const parseElements = ({ type, data }: { type: string; data: any }) => {
// properly align images (see: https://github.com/jpuri/draftjs-to-html/issues/28#issuecomment-607344551)
if (type === 'IMAGE') {
const alignment = data.alignment || 'none'
const textAlign = alignment === 'none' ? 'center' : alignment
const alt = data.alt ? data.alt : ''
return `<p style="text-align:${textAlign};"><img src="${data.src}" alt="${alt}" style="height: ${data.height};width: ${data.width}"/></p>`
}
},
[]
)
if (type === 'LINK') {
return `<a href=${data.href ? data.href : data.url} title=${
data.title
}>${data.title}</a>`
}
}
return state.getCurrentContent().hasText()
? draftToHtml(
convertToRaw(state.getCurrentContent()),
{},
false,
parseElements
)
: ''
}
const handleStateChange = useCallback(
(state: EditorState) => {
setEditorState(state)
if (state.getCurrentContent().hasText()) {
handleChange(
stateToHTML(state.getCurrentContent(), { entityStyleFn }),
editorType
)
} else {
handleChange('', editorType)
}
const htmlState = convertStateToHTML(state)
handleChange(htmlState, editorType)
},
[editorType, handleChange, entityStyleFn]
[editorType, handleChange]
)
return (
Loading