Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc7c02ac

Browse files
committed
[Fix]:#1986 change event trigger
1 parent4747b25 commitc7c02ac

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

‎client/packages/lowcoder/src/comps/comps/richTextEditorComp.tsx‎

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ const toolbarOptions = [
171171
];
172172

173173
constchildrenMap={
174-
value:stringExposingStateControl("value"),
174+
value:stringExposingStateControl("value"),
175175
delta:stringExposingStateControl("delta"),
176176
hideToolbar:BoolControl,
177177
readOnly:BoolControl,
@@ -195,7 +195,7 @@ interface IProps {
195195
hideToolbar:boolean;
196196
readOnly:boolean;
197197
autoHeight:boolean;
198-
onChange:(html:string,deltaJSON:string,text:string)=>void;
198+
onChange:(html:string,deltaJSON:string,text:string)=>void;
199199
$style:RichTextEditorStyleType;
200200
contentScrollBar:boolean;
201201
tabIndex?:number;
@@ -209,6 +209,13 @@ function RichTextEditor(props: IProps) {
209209
constwrapperRef=useRef<HTMLDivElement>(null);
210210
consteditorRef=useRef<ReactQuill>(null);
211211

212+
// know exactly when the editor mounts
213+
const[editorReady,setEditorReady]=useState(false);
214+
constsetEditorRef=(node:ReactQuill|null)=>{
215+
(editorRefasany).current=nodeasany;
216+
setEditorReady(!!node);
217+
};
218+
212219
constgetQuill=()=>(editorRef.currentasany)?.getEditor?.();
213220

214221
consttryParseDelta=(v:unknown)=>{
@@ -251,7 +258,7 @@ function RichTextEditor(props: IProps) {
251258
(editor.scroll.domNodeasHTMLElement).tabIndex=props.tabIndex;
252259
}
253260
}
254-
},[props.tabIndex,key]);
261+
},[props.tabIndex,key]);
255262

256263
constcontains=(parent:HTMLElement,descendant:HTMLElement)=>{
257264
try{
@@ -267,11 +274,7 @@ function RichTextEditor(props: IProps) {
267274

268275
useEffect(()=>{
269276
constq=getQuill();
270-
271277
if(!q){
272-
constv=props.value??"";
273-
constlooksHtml=/<\/?[a-z][\s\S]*>/i.test(v);
274-
setContent(looksHtml ?v :`<p class="">${v}</p>`);
275278
return;
276279
}
277280

@@ -282,12 +285,11 @@ function RichTextEditor(props: IProps) {
282285
setContent(html);
283286
return;
284287
}
285-
286288
constv=props.value??"";
287289
constlooksHtml=/<\/?[a-z][\s\S]*>/i.test(v);
288290
consthtml=looksHtml ?v :`<p class="">${v}</p>`;
289291
setContent(html);
290-
},[props.value]);
292+
},[props.value,editorReady]);
291293

292294

293295
consthandleClickWrapper=(e:React.MouseEvent<HTMLDivElement>)=>{
@@ -316,7 +318,7 @@ function RichTextEditor(props: IProps) {
316318
<Suspensefallback={<Skeleton/>}>
317319
<ReactQuillEditor
318320
key={key}
319-
ref={editorRef}
321+
ref={setEditorRef}
320322
bounds={`#${id}`}
321323
modules={{
322324
toolbar:JSON.parse(props.toolbar),
@@ -339,17 +341,26 @@ function RichTextEditor(props: IProps) {
339341
}
340342

341343
constRichTextEditorCompBase=newUICompBuilder(childrenMap,(props)=>{
344+
constpropsRef=useRef(props);
345+
propsRef.current=props;
346+
342347
constdebouncedOnChangeRef=useRef(
343348
debounce((html:string,deltaJSON:string,text:string)=>{
344-
props.value.onChange(html);
345-
props.delta.onChange(deltaJSON);
346-
props.onEvent("change");
347-
},1000)
349+
propsRef.current.value.onChange(html);
350+
propsRef.current.delta.onChange(deltaJSON);
351+
propsRef.current.onEvent("change");
352+
},500)
348353
);
349354

350-
consthandleChange=(html:string,deltaJSON:string,text:string)=>{
351-
debouncedOnChangeRef.current?.(html,deltaJSON,text);
355+
useEffect(()=>{
356+
return()=>{
357+
debouncedOnChangeRef.current?.cancel();
352358
};
359+
},[]);
360+
361+
consthandleChange=(html:string,deltaJSON:string,text:string)=>{
362+
debouncedOnChangeRef.current?.(html,deltaJSON,text);
363+
};
353364

354365
return(
355366
<RichTextEditor

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp