tinymcestrapimedia-library

Strapi media library odd behavior


I've integrated strapi with TinyMCE editor in my project(React). But image insertion from media library is uploading image at end of content no matter where you cursor is. I've searched this for their forums and issues but have not found anything . Is there any valid reason for this behavior because in doc also mentioned . I need to correct this so any lead would be appreciated.


Solution

  • In case anyone got this try the below code in Handel change function in your Wysiwyg index.js

     const handleChange = data => {
        if (data.mime.includes('image') && typeof window !== 'undefined') {
          const imgTag = `<p><img src="${data.url}" caption="${data.caption}" alt="${data.alternativeText}"/></p>`;
          window.tinymce.activeEditor.insertContent(imgTag);
          const newValue = window.tinymce.activeEditor.getContent();
    
          onChange({ target: { name, value: newValue } });
        }
      };
    

    this will insert images from the media library on the curser