diff --git a/.env b/.env index 57e6441..e49f527 100644 --- a/.env +++ b/.env @@ -1,4 +1,4 @@ VITE_TOKEN_NAME = 'admin_token' VITE_REFRESH_TOKEN_NAME = 'admin_refresh_token' VITE_BASE_URL = 'https://api.danakcorp.com' -# VITE_BASE_URL = 'http://192.168.1.112:4001' \ No newline at end of file +# VITE_BASE_URL = 'http://192.168.1.100:4001' \ No newline at end of file diff --git a/src/components/QuillEditor.tsx b/src/components/QuillEditor.tsx new file mode 100644 index 0000000..dee959f --- /dev/null +++ b/src/components/QuillEditor.tsx @@ -0,0 +1,157 @@ +import { FC, useEffect, useRef } from 'react' +import Quill from 'quill' +import VideoBlot, { getEmbedUrl } from './VideoBlot' +import 'quill/dist/quill.snow.css' + +// ثبت VideoBlot در Quill +Quill.register('formats/video', VideoBlot) + +interface QuillEditorProps { + value?: string + onChange?: (content: string) => void + placeholder?: string + className?: string + minHeight?: string + id?: string +} + +const QuillEditor: FC = ({ + value = '', + onChange, + placeholder = '', + className = '', + minHeight = '200px', + id = 'quill-editor' +}) => { + const editorRef = useRef(null) + const quillRef = useRef(null) + + useEffect(() => { + if (!editorRef.current) return + + // پیکربندی toolbar سفارشی + const toolbarOptions = [ + ['bold', 'italic', 'underline'], + [{ 'header': 1 }, { 'header': 2 }], + [{ 'list': 'ordered' }, { 'list': 'bullet' }], + [{ 'direction': 'rtl' }], + [{ 'color': [] }, { 'background': [] }], + [{ 'align': [] }], + ['link', 'image'], + ['clean'] + ] + + const quill = new Quill(editorRef.current, { + theme: 'snow', + placeholder, + modules: { + toolbar: toolbarOptions + } + }) + + // تنظیم محتوای اولیه + if (value) { + quill.root.innerHTML = value + } + + // مدیریت تغییرات + quill.on('text-change', () => { + const html = quill.root.innerHTML + onChange?.(html) + }) + + quillRef.current = quill + + return () => { + quillRef.current = null + } + }, [placeholder]) + + // بروزرسانی محتوا از خارج + useEffect(() => { + if (quillRef.current && value !== quillRef.current.root.innerHTML) { + quillRef.current.root.innerHTML = value + } + }, [value]) + + const handleYouTubeClick = () => { + const url = prompt('لینک ویدیو یوتیوب را وارد کنید:') + if (url && quillRef.current) { + const embedUrl = getEmbedUrl(url) + if (embedUrl) { + const range = quillRef.current.getSelection() || { index: 0, length: 0 } + quillRef.current.insertEmbed(range.index, 'video', { + url: embedUrl, + width: '100%', + height: '315' + }) + quillRef.current.setSelection(range.index + 1) + } else { + alert('لینک ویدیو معتبر نیست') + } + } + } + + const handleAparatClick = () => { + const url = prompt('لینک ویدیو آپارات را وارد کنید:') + if (url && quillRef.current) { + const embedUrl = getEmbedUrl(url) + if (embedUrl) { + const range = quillRef.current.getSelection() || { index: 0, length: 0 } + quillRef.current.insertEmbed(range.index, 'video', { + url: embedUrl, + width: '100%', + height: '315' + }) + quillRef.current.setSelection(range.index + 1) + } else { + alert('لینک ویدیو معتبر نیست') + } + } + } + + return ( +
+ {/* دکمه‌های ویدیو بالای ادیتور */} +
+ + +
+ +
+