mirror of
				https://github.com/strapi/strapi.git
				synced 2025-11-03 19:36:20 +00:00 
			
		
		
		
	Fix wysiwyg update
Signed-off-by: soupette <cyril@strapi.io>
This commit is contained in:
		
							parent
							
								
									a63441757e
								
							
						
					
					
						commit
						491cbb27dd
					
				@ -15,11 +15,9 @@ const Editor = ({
 | 
			
		||||
  name,
 | 
			
		||||
  onChange,
 | 
			
		||||
  placeholder,
 | 
			
		||||
  shouldSetValueAfterExpand,
 | 
			
		||||
  textareaRef,
 | 
			
		||||
  value,
 | 
			
		||||
}) => {
 | 
			
		||||
  const initialValueRef = useRef(value);
 | 
			
		||||
  const onChangeRef = useRef(onChange);
 | 
			
		||||
 | 
			
		||||
  useEffect(() => {
 | 
			
		||||
@ -33,10 +31,6 @@ const Editor = ({
 | 
			
		||||
      readOnly: false,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    if (initialValueRef.current) {
 | 
			
		||||
      editorRef.current.setValue(initialValueRef.current);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    CodeMirror.commands.newlineAndIndentContinueMarkdownList = newlineAndIndentContinueMarkdownList;
 | 
			
		||||
    editorRef.current.on('change', doc => {
 | 
			
		||||
      onChangeRef.current({ target: { name, value: doc.getValue(), type: 'wysiwyg' } });
 | 
			
		||||
@ -44,10 +38,10 @@ const Editor = ({
 | 
			
		||||
  }, [editorRef, textareaRef, name]);
 | 
			
		||||
 | 
			
		||||
  useEffect(() => {
 | 
			
		||||
    if (shouldSetValueAfterExpand && value) {
 | 
			
		||||
    if (value && !editorRef.current.state.focused) {
 | 
			
		||||
      editorRef.current.setValue(value);
 | 
			
		||||
    }
 | 
			
		||||
  }, [editorRef, shouldSetValueAfterExpand, value]);
 | 
			
		||||
  }, [editorRef, value]);
 | 
			
		||||
 | 
			
		||||
  useEffect(() => {
 | 
			
		||||
    if (isPreviewMode || disabled) {
 | 
			
		||||
@ -81,7 +75,6 @@ Editor.defaultProps = {
 | 
			
		||||
  error: undefined,
 | 
			
		||||
  isPreviewMode: false,
 | 
			
		||||
  placeholder: '',
 | 
			
		||||
  shouldSetValueAfterExpand: false,
 | 
			
		||||
  value: '',
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -93,7 +86,6 @@ Editor.propTypes = {
 | 
			
		||||
  name: PropTypes.string.isRequired,
 | 
			
		||||
  onChange: PropTypes.func.isRequired,
 | 
			
		||||
  placeholder: PropTypes.string,
 | 
			
		||||
  shouldSetValueAfterExpand: PropTypes.bool,
 | 
			
		||||
  textareaRef: PropTypes.shape({ current: PropTypes.any }).isRequired,
 | 
			
		||||
  value: PropTypes.string,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -67,7 +67,6 @@ const Wysiwyg = ({
 | 
			
		||||
  const [isPreviewMode, setIsPreviewMode] = useState(false);
 | 
			
		||||
  const [mediaLibVisible, setMediaLibVisible] = useState(false);
 | 
			
		||||
  const [isExpandMode, setIsExpandMode] = useState(false);
 | 
			
		||||
  const [shouldSetValueAfterExpand, setShouldSetValueAfterExpand] = useState(false);
 | 
			
		||||
 | 
			
		||||
  const handleToggleMediaLib = () => setMediaLibVisible(prev => !prev);
 | 
			
		||||
  const handleTogglePopover = () => setVisiblePopover(prev => !prev);
 | 
			
		||||
@ -120,13 +119,8 @@ const Wysiwyg = ({
 | 
			
		||||
    insertImage(currentEditorRef, files);
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  const handleToggleExpand = collapse => {
 | 
			
		||||
  const handleToggleExpand = () => {
 | 
			
		||||
    setIsExpandMode(prev => !prev);
 | 
			
		||||
    setShouldSetValueAfterExpand(false);
 | 
			
		||||
 | 
			
		||||
    if (collapse === 'collapse' && value) {
 | 
			
		||||
      setShouldSetValueAfterExpand(true);
 | 
			
		||||
    }
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  return (
 | 
			
		||||
@ -153,7 +147,6 @@ const Wysiwyg = ({
 | 
			
		||||
          name={name}
 | 
			
		||||
          onChange={onChange}
 | 
			
		||||
          placeholder={formattedPlaceholder}
 | 
			
		||||
          shouldSetValueAfterExpand={shouldSetValueAfterExpand}
 | 
			
		||||
          textareaRef={textareaRef}
 | 
			
		||||
          value={value}
 | 
			
		||||
        />
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user