-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #230 from oarepo/stojanovic/fe-248-rich-editor-bug
fixed issue with rich editor
- Loading branch information
Showing
3 changed files
with
41 additions
and
32 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
37 changes: 37 additions & 0 deletions
37
.../assets/semantic-ui/js/oarepo_ui/forms/components/I18nRichInputField/OarepoRichEditor.jsx
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,37 @@ | ||
import React from "react"; | ||
import { RichEditor } from "react-invenio-forms"; | ||
import { useFormikContext, getIn } from "formik"; | ||
import { useSanitizeInput } from "@js/oarepo_ui"; | ||
import PropTypes from "prop-types"; | ||
|
||
export const toolBar = | ||
"blocks | bold italic | bullist numlist | outdent indent | undo redo"; | ||
|
||
export const OarepoRichEditor = ({ fieldPath, editorConfig }) => { | ||
const { sanitizeInput, validEditorTags } = useSanitizeInput(); | ||
|
||
const { values, setFieldValue, setFieldTouched } = useFormikContext(); | ||
const fieldValue = getIn(values, fieldPath, ""); | ||
return ( | ||
<RichEditor | ||
initialValue={fieldValue} | ||
inputValue={() => fieldValue} | ||
optimized | ||
onBlur={(event, editor) => { | ||
const cleanedContent = sanitizeInput(editor.getContent()); | ||
setFieldValue(fieldPath, cleanedContent); | ||
setFieldTouched(fieldPath, true); | ||
}} | ||
editorConfig={{ | ||
valid_elements: validEditorTags, | ||
toolbar: toolBar, | ||
...editorConfig, | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
OarepoRichEditor.propTypes = { | ||
fieldPath: PropTypes.string.isRequired, | ||
editorConfig: PropTypes.object, | ||
}; |
1 change: 1 addition & 0 deletions
1
oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/I18nRichInputField/index.js
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./I18nRichInputField"; | ||
export * from "./OarepoRichEditor"; |