import { h } from 'preact'; import PropTypes from 'prop-types'; import { useLayoutEffect, useRef } from 'preact/hooks'; import { Toolbar } from './Toolbar'; import { handleImagePasted } from './pasteImageHelpers'; import { handleImageUploadSuccess, handleImageUploading, handleImageUploadFailure, } from './imageUploadHelpers'; import { handleImageDrop, onDragOver, onDragExit } from './dragAndDropHelpers'; import { usePasteImage } from '@utilities/pasteImage'; import { useDragAndDrop } from '@utilities/dragAndDrop'; import { fetchSearch } from '@utilities/search'; import { AutocompleteTriggerTextArea } from '@crayons/AutocompleteTriggerTextArea'; export const EditorBody = ({ onChange, defaultValue, switchHelpContext, version, }) => { const textAreaRef = useRef(null); const { setElement } = useDragAndDrop({ onDrop: handleImageDrop( handleImageUploading(textAreaRef), handleImageUploadSuccess(textAreaRef), handleImageUploadFailure(textAreaRef), ), onDragOver, onDragExit, }); const setPasteElement = usePasteImage({ onPaste: handleImagePasted( handleImageUploading(textAreaRef), handleImageUploadSuccess(textAreaRef), handleImageUploadFailure(textAreaRef), ), }); useLayoutEffect(() => { if (textAreaRef.current) { setElement(textAreaRef.current); setPasteElement(textAreaRef.current); } }); return (
fetchSearch('usernames', { username }).then(({ result }) => result.map((user) => ({ ...user, value: user.username })), ) } autoResize onChange={onChange} onFocus={switchHelpContext} aria-label="Post Content" name="body_markdown" id="article_body_markdown" defaultValue={defaultValue} placeholder="Write your post content here..." className="crayons-textfield crayons-textfield--ghost crayons-article-form__body__field ff-monospace fs-l h-100" />
); }; EditorBody.propTypes = { onChange: PropTypes.func.isRequired, defaultValue: PropTypes.string.isRequired, switchHelpContext: PropTypes.func.isRequired, version: PropTypes.string.isRequired, }; EditorBody.displayName = 'EditorBody';