1- /**
2- * External dependencies.
3- */
4- import { useEffect , useState } from "react" ;
5- import ReactQuill , {
6- Quill ,
7- type DeltaStatic ,
8- type EmitterSource ,
9- } from "react-quill-new" ;
10- import "react-quill-new/dist/quill.snow.css" ;
11- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
12- // @ts -ignore
13- import ImageResize from "quill-resize-module/dist/resize.js" ;
14- import "quill-resize-module/dist/resize.css" ;
15- import "quill-paste-smart" ;
16-
17- /**
18- * Internal dependencies.
19- */
20- import { preProcessLink } from "./utils" ;
21- export interface TextEditorProps extends ReactQuill . ReactQuillProps {
1+ export interface TextEditorProps {
222 allowImageUpload ?: boolean ;
233 allowVideoUpload ?: boolean ;
244 className ?: string ;
@@ -28,96 +8,11 @@ export interface TextEditorProps extends ReactQuill.ReactQuillProps {
288 placeholder ?: string ;
299}
3010
31- Quill . register ( "modules/imageResize" , ImageResize ) ;
32-
33- const TextEditor = ( {
34- allowImageUpload = false ,
35- allowVideoUpload = false ,
36- className,
37- onChange,
38- hideToolbar = false ,
39- ...props
40- } : TextEditorProps ) => {
41- const [ editorValue , setEditorValue ] = useState ( props . value || "" ) ;
42-
43- useEffect ( ( ) => {
44- if ( props ?. value ) {
45- setEditorValue ( props . value ) ;
46- }
47- } , [ props ?. value ] ) ;
48-
49- const toolbarOptions = [
50- [ "bold" , "italic" ] ,
51- [ { color : [ ] } ] ,
52- [
53- { list : "ordered" } ,
54- { list : "bullet" } ,
55- { indent : "-1" } ,
56- { indent : "+1" } ,
57- ] ,
58- [ { align : [ ] } ] ,
59- [ "link" ] ,
60- ] ;
61-
62- if ( allowImageUpload ) {
63- toolbarOptions . push ( [ "image" ] ) ;
64- }
65-
66- if ( allowVideoUpload ) {
67- toolbarOptions . push ( [ "video" ] ) ;
68- }
69-
70- const modules = {
71- toolbar : hideToolbar ? false : toolbarOptions ,
72- } ;
73-
74- if ( allowImageUpload ) {
75- // @ts -expect-error expected
76- modules . imageResize = {
77- modules : [ "Resize" , "DisplaySize" , "Toolbar" ] ,
78- } ;
79- }
80-
81- const formatHtml = ( html : string ) => {
82- return preProcessLink ( html ) ;
83- } ;
84-
85- const handleChange = (
86- value : string ,
87- _ : DeltaStatic ,
88- __ : EmitterSource ,
89- editor : ReactQuill . UnprivilegedEditor
90- ) => {
91- const formattedValue = formatHtml ( value ) ;
92- setEditorValue ( formattedValue ) ;
93- if ( editor . getText ( ) ?. trim ( ) ) {
94- onChange ( formattedValue ) ;
95- } else {
96- onChange ( "" ) ;
97- }
98- } ;
99-
100- return (
101- < >
102- < ReactQuill
103- { ...props }
104- style = { { resize : "vertical" , overflow : "auto" } }
105- className = { `
106- border rounded-md border-input [&>div:first-child]:border-t-0 [&>div:first-child]:border-r-0 [&>div:first-child]:border-l-0 [&>div:first-child]:border-input [&>div:first-child]:border-bottom [&>div:last-child]:border-none text-foreground bg-background whitespace-normal
107- ${
108- hideToolbar &&
109- "border-none !resize-none [&_.ql-editor]:min-h-0 [&_.ql-editor]:p-2"
110- }
111- ${ ! hideToolbar && "break-all" }
112- ${ className }
113- ` }
114- theme = "snow"
115- modules = { modules }
116- onChange = { handleChange }
117- value = { editorValue }
118- />
119- </ >
120- ) ;
121- } ;
11+ /* eslint-disable @typescript-eslint/no-unused-vars */
12+ const TextEditor = ( _props : TextEditorProps ) => {
13+ return (
14+ < div > </ div >
15+ ) ;
16+ }
12217
12318export default TextEditor ;
0 commit comments