We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
My code is as below, but I want to try using the image control library I'd like to ask for advice on what to do if possible
import { Dispatch, LegacyRef, memo, SetStateAction, useMemo, useRef, } from 'react'; import dynamic from 'next/dynamic'; import ReactQuill, { ReactQuillProps } from 'react-quill'; import Swal from 'sweetalert2'; import { quillDefaultModule } from '@constants/quill.constant'; import { getMetaData } from '@http/commons.http'; import { uploadFile } from '@http/file.http'; interface IQuillEditor extends ReactQuillProps { forwardedRef: LegacyRef<ReactQuill>; } const QuillNoSSRWrapper = dynamic( async () => { const { default: RQ } = await import('react-quill'); // eslint-disable-next-line react/display-name return function editor({ forwardedRef, ...props }: IQuillEditor) { return <RQ ref={forwardedRef} {...props} />; }; }, { ssr: false } ); function Editor({ setContent, content, }: { setContent: Dispatch<SetStateAction<string>>; content: string; }) { const quill = useRef<ReactQuill>(null); const modules = useMemo( () => ({ ...quillDefaultModule, toolbar: { ...quillDefaultModule.toolbar, handlers: { image: async () => imageHandler(), }, onPaste() { console.log('asdfasdf'); }, }, }), [] ); const imageHandler = () => { const input = document.createElement('input'); input.setAttribute('type', 'file'); input.setAttribute('accept', 'image/png, image/jpeg, .gif'); document.body.appendChild(input); input.click(); input.onchange = async () => { try { const file = input.files && input.files[0]; const data = await uploadFile({ file }); if (quill.current) { const range = quill.current.getEditorSelection(); if (range) { quill.current .getEditor() .insertEmbed(range.index, 'image', data.data.Location); quill.current.getEditor().insertText(range.index + 1, ' '); quill.current .getEditor() .setSelection({ index: range.index + 1, length: 0 }); } } } catch (error) { alert('error'); } }; }; return ( <QuillNoSSRWrapper forwardedRef={quill} modules={modules} onChange={setContent} theme="snow" defaultValue={content} scrollingContainer="html" /> ); } export default memo(Editor);
The text was updated successfully, but these errors were encountered:
No branches or pull requests
My code is as below, but I want to try using the image control library I'd like to ask for advice on what to do if possible
The text was updated successfully, but these errors were encountered: