Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Next.js #211

Closed
zzossig opened this issue Nov 4, 2019 · 26 comments
Closed

Support Next.js #211

zzossig opened this issue Nov 4, 2019 · 26 comments

Comments

@zzossig
Copy link

zzossig commented Nov 4, 2019

I'm using [email protected] and [email protected],
When I used react-froala-wysiwyg v2, all worked fine.
But after upgrade to v3, It seems that import is not working.
For example, in v2, the following import code works well. but in v3, this code not importing plugins.pkgd.min.js file

dynamic(import('froala-editor/js/plugins.pkgd.min'), { ssr: false });

As a result, toolbar buttons are not showing up correctly.

@edsora-coder
Copy link

edsora-coder commented Jan 23, 2020

const Editor: React.ComponentType<any> = dynamic(
  () => {
    return new Promise(resolve =>
      import("froala-editor/js/plugins.pkgd.min.js").then(e => {
        import("react-froala-wysiwyg").then(resolve);
      })
    );
  },
  {
    loading: () => null,
    ssr: false
  }
);

@muyiwaoyeniyi
Copy link

muyiwaoyeniyi commented Jun 20, 2020

@zzossig @edsora-coder I also was searching for an answer to this... You probably don't need this anymore... just for anyone out there... here's my solution -- allows you to (independently) load any number of files.

const FroalaEditor = dynamic(
  async () => {
    const values = await Promise.all([
      import("react-froala-wysiwyg"), // must be first import since we are doing values[0] in return
      import("froala-editor/js/plugins/image.min.js")
    ]);
    return values[0];
  },
  {
    loading: () => <p>LOADING!!!</p>,
    ssr: false
  }
);

@ashokkumarsand
Copy link

+1

@muyiwaoyeniyi
Copy link

@ashokkumarsand can you paste your code here?

@ashokkumarsand
Copy link

importing with import statement is not working
import FroalaEditorComponent from 'react-froala-wysiwyg';
I imported via
const FroalaEditor = dynamic(import('react-froala-wysiwyg'), { ssr: false, });
The not basic editor is working but without plugins, When I add
import 'froala-editor/js/plugins.pkgd.min.js';
import statement for the plugins then it will be broken,

I got the below error

Element is not defined
ReferenceError: Element is not defined
    at /Users/ashoksand/workspace/truvoice/VTX/truvoice/node_modules/froala-editor/js/froala_editor.min.js:7:414
    at /Users/ashoksand/workspace/truvoice/VTX/truvoice/node_modules/froala-editor/js/froala_editor.min.js:7:84
    at Object.<anonymous> (/Users/ashoksand/workspace/truvoice/VTX/truvoice/node_modules/froala-editor/js/froala_editor.min.js:7:155)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at /Users/ashoksand/workspace/truvoice/VTX/truvoice/node_modules/froala-editor/js/plugins.pkgd.min.js:7:71
    at Object.<anonymous> (/Users/ashoksand/workspace/truvoice/VTX/truvoice/node_modules/froala-editor/js/plugins.pkgd.min.js:7:181)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)

@muyiwaoyeniyi
Copy link

@ashokkumarsand Can you paste the entire code here? It would be easier to help you that way.

@ashokkumarsand
Copy link

ashokkumarsand commented Jan 25, 2021

I am using nextjs. when I uncomment any import to use the plugin got the above error. It's very hard to use and things are not straight forward

import React from 'react';
import dynamic from 'next/dynamic';
import { last } from 'lodash';
import config from '../../config';
import { generateId } from '../../utils/utils';

// Import all Froala Editor plugins;
// import 'froala-editor/js/plugins.pkgd.min.js';

// Import a single Froala Editor plugin.
// import 'froala-editor/js/plugins/align.min.js';

// Import a language file.
// import 'froala-editor/js/languages/de.js';

// Import a third-party plugin.
// import 'froala-editor/js/third_party/image_tui.min.js';
// import 'froala-editor/js/third_party/embedly.min.js';
// import 'froala-editor/js/third_party/spell_checker.min.js';

// Include font-awesome css if required.
// install using "npm install font-awesome --save"
// import 'font-awesome/css/font-awesome.css';
// import 'froala-editor/js/third_party/font_awesome.min.js';

const FroalaEditor = dynamic(import('react-froala-wysiwyg'), {
  ssr: false,
});

const froalaConfig = {
  key: config.froalaKey,
  events: {},
  colorsBackground: [
    '#61BD6D',
    '#1ABC9C',
    '#54ACD2',
    '#2C82C9',
    '#9365B8',
    '#475577',
    '#CCCCCC',
    '#41A85F',
    '#00A885',
    '#3D8EB9',
    '#2969B0',
    '#553982',
    '#28324E',
    '#000000',
    '#F7DA64',
    '#FBA026',
    '#EB6B56',
    '#E25041',
    '#A38F84',
    '#EFEFEF',
    '#FFFFFF',
    '#FAC51C',
    '#F37934',
    '#D14841',
    '#B8312F',
    '#7C706B',
    '#D1D5D8',
    'REMOVE',
  ],
  emoticonsSet: [
    {
      code: '1f600',
      desc: 'Grinning face',
    },
    {
      code: '1f601',
      desc: 'Grinning face with smiling eyes',
    },
    {
      code: '1f602',
      desc: 'Face with tears of joy',
    },
    {
      code: '1f603',
      desc: 'Smiling face with open mouth',
    },
    {
      code: '1f604',
      desc: 'Smiling face with open mouth and smiling eyes',
    },
    {
      code: '1f605',
      desc: 'Smiling face with open mouth and cold sweat',
    },
    {
      code: '1f606',
      desc: 'Smiling face with open mouth and tightly-closed eyes',
    },
    {
      code: '1f607',
      desc: 'Smiling face with halo',
    },
    {
      code: '1f608',
      desc: 'Smiling face with horns',
    },
    {
      code: '1f609',
      desc: 'Winking face',
    },
    {
      code: '1f60a',
      desc: 'Smiling face with smiling eyes',
    },
    {
      code: '1f60b',
      desc: 'Face savoring delicious food',
    },
    {
      code: '1f60c',
      desc: 'Relieved face',
    },
    {
      code: '1f60d',
      desc: 'Smiling face with heart-shaped eyes',
    },
    {
      code: '1f60e',
      desc: 'Smiling face with sunglasses',
    },
    {
      code: '1f60f',
      desc: 'Smirking face',
    },
    {
      code: '1f610',
      desc: 'Neutral face',
    },
    {
      code: '1f611',
      desc: 'Expressionless face',
    },
    {
      code: '1f612',
      desc: 'Unamused face',
    },
    {
      code: '1f613',
      desc: 'Face with cold sweat',
    },
    {
      code: '1f614',
      desc: 'Pensive face',
    },
    {
      code: '1f615',
      desc: 'Confused face',
    },
    {
      code: '1f616',
      desc: 'Confounded face',
    },
    {
      code: '1f617',
      desc: 'Kissing face',
    },
    {
      code: '1f618',
      desc: 'Face throwing a kiss',
    },
    {
      code: '1f619',
      desc: 'Kissing face with smiling eyes',
    },
    {
      code: '1f61a',
      desc: 'Kissing face with closed eyes',
    },
    {
      code: '1f61b',
      desc: 'Face with stuck out tongue',
    },
    {
      code: '1f61c',
      desc: 'Face with stuck out tongue and winking eye',
    },
    {
      code: '1f61d',
      desc: 'Face with stuck out tongue and tightly-closed eyes',
    },
    {
      code: '1f61e',
      desc: 'Disappointed face',
    },
    {
      code: '1f61f',
      desc: 'Worried face',
    },
    {
      code: '1f620',
      desc: 'Angry face',
    },
    {
      code: '1f621',
      desc: 'Pouting face',
    },
    {
      code: '1f622',
      desc: 'Crying face',
    },
    {
      code: '1f623',
      desc: 'Persevering face',
    },
    {
      code: '1f624',
      desc: 'Face with look of triumph',
    },
    {
      code: '1f625',
      desc: 'Disappointed but relieved face',
    },
    {
      code: '1f626',
      desc: 'Frowning face with open mouth',
    },
    {
      code: '1f627',
      desc: 'Anguished face',
    },
    {
      code: '1f628',
      desc: 'Fearful face',
    },
    {
      code: '1f629',
      desc: 'Weary face',
    },
    {
      code: '1f62a',
      desc: 'Sleepy face',
    },
    {
      code: '1f62b',
      desc: 'Tired face',
    },
    {
      code: '1f62c',
      desc: 'Grimacing face',
    },
    {
      code: '1f62d',
      desc: 'Loudly crying face',
    },
    {
      code: '1f62e',
      desc: 'Face with open mouth',
    },
    {
      code: '1f62f',
      desc: 'Hushed face',
    },
    {
      code: '1f630',
      desc: 'Face with open mouth and cold sweat',
    },
    {
      code: '1f631',
      desc: 'Face screaming in fear',
    },
    {
      code: '1f632',
      desc: 'Astonished face',
    },
    {
      code: '1f633',
      desc: 'Flushed face',
    },
    {
      code: '1f634',
      desc: 'Sleeping face',
    },
    {
      code: '1f635',
      desc: 'Dizzy face',
    },
    {
      code: '1f636',
      desc: 'Face without mouth',
    },
    {
      code: '1f637',
      desc: 'Face with medical mask',
    },
  ],
  embedlyEditButtons: ['embedlyRemove'],
  fontSizeSelection: true,
  fontFamily: {
    'Arial,Helvetica,sans-serif': 'Arial',
    'Georgia,serif': 'Georgia',
    'Impact,Charcoal,sans-serif': 'Impact',
    'Tahoma,Geneva,sans-serif': 'Tahoma',
    'Times New Roman,Times,serif': 'Times New Roman',
    'Verdana,Geneva,sans-serif': 'Verdana',
  },
  fileAllowedTypes: ['*'],
  fileInsertButtons: ['fileBack', '|'],
  fileMaxSize: 1024,
  fileUpload: false,
  fileUploadMethod: 'POST',
  fileUploadParam: 'file',
  fileUploadToS3: false,
  fileUploadParams: {},
  fileUploadURL: 'http://i.froala.com/upload',
  fileUseSelectedText: true,
  lineBreakerHorizontalOffset: 10,
  lineBreakerOffset: 15,
  lineBreakerTags: [
    'table',
    'hr',
    'form',
    'dl',
    'span.fr-video',
    '.fr-embedly',
    '.fr-img-caption',
  ],
  imageManagerDeleteMethod: 'POST',
  imageManagerDeleteParams: {},
  imageManagerLoadMethod: 'GET',
  imageManagerDeleteURL: '',
  imageManagerLoadParams: {},
  imageManagerLoadURL: 'http://i.froala.com/load-files',
  imageManagerPageSize: 12,
  imageManagerPreloader: '',
  imageAllowedTypes: ['jpeg', 'jpg', 'png', 'gif', 'webp'],
  imageAltButtons: ['imageBack', '|'],
  imageDefaultAlign: 'center',
  imageCORSProxy: 'https://cors-anywhere.froala.com',
  imageDefaultDisplay: 'block',
  imageDefaultMargin: 5,
  imageDefaultWidth: 300,
  imageEditButtons: [
    'imageReplace',
    'imageAlign',
    'imageCaption',
    'imageRemove',
    '|',
    'imageLink',
    'linkOpen',
    'linkEdit',
    'linkRemove',
    '-',
    'imageDisplay',
    'imageStyle',
    'imageAlt',
    'imageSize',
  ],
  imageMaxSize: 1024,
  imageInsertButtons: [
    'imageBack',
    '|',
    'imageUpload',
    'imageByURL',
    'imageManager',
  ],
  imageMinWidth: 16,
  imageMove: false,
  imageMultipleStyles: false,
  imagePaste: false,
  imageResize: false,
  imagePasteProcess: true,
  imageResizeWithPercent: true,
  imageRoundPercent: true,
  imageSizeButtons: ['imageBack', '|'],
  imageOutputSize: true,
  imageSplitHTML: true,
  imageStyles: {
    'fr-rounded': 'Rounded',
    'fr-bordered': 'Bordered',
  },
  imageTextNear: false,
  imageTUIOptions: {
    includeUI: {
      initMenu: 'filter',
      menuBarPosition: 'left',
      theme: {
        'menu.activeIcon.path':
          'https://cdn.jsdelivr.net/npm/[email protected]/dist/svg/icon-b.svg',
        'menu.disabledIcon.path':
          'https://cdn.jsdelivr.net/npm/[email protected]/dist/svg/icon-a.svg',
        'menu.hoverIcon.path':
          'https://cdn.jsdelivr.net/npm/[email protected]/dist/svg/icon-c.svg',
        'menu.normalIcon.path':
          'https://cdn.jsdelivr.net/npm/[email protected]/dist/svg/icon-d.svg',
        'submenu.activeIcon.name': 'icon-c',
        'submenu.activeIcon.path':
          'https://cdn.jsdelivr.net/npm/[email protected]/dist/svg/icon-c.svg',
        'submenu.normalIcon.name': 'icon-d',
        'submenu.normalIcon.path':
          'https://cdn.jsdelivr.net/npm/[email protected]/dist/svg/icon-d.svg',
      },
    },
  },
  imageUpload: false,
  imageAddNewLine: true,
  imageUploadParam: 'file',
  imageUploadMethod: 'POST',
  imageUploadParams: {},
  imageUploadRemoteUrls: false,
  imageUploadToS3: false,
  imageUploadURL: null,
  specialCharButtons: ['specialCharBack', '|'],
  specialCharactersSets: {},
  quickInsertButtons: ['image', 'video', 'embedly', 'table', 'ul', 'ol', 'hr'],
  quickInsertEnabled: false,
  quickInsertTags: [
    'p',
    'div',
    'h1',
    'h2',
    'h3',
    'h4',
    'h5',
    'h6',
    'pre',
    'blockquote',
  ],
  paragraphDefaultSelection: 'Paragraph Format',
  paragraphFormat: {
    N: 'Normal',
    H1: 'Heading 1',
    H2: 'Heading 2',
    H3: 'Heading 3',
    H4: 'Heading 4',
    PRE: 'Code',
  },
  paragraphFormatSelection: true,
  paragraphMultipleStyles: false,
  lineHeights: {
    Default: '',
    Single: '1',
    1.15: '1.15',
    1.5: '1.5',
    Double: '2',
  },
  paragraphStyles: {
    'fr-text-gray': 'Gray',
    'fr-text-bordered': 'Bordered',
    'fr-text-spaced': 'Spaced',
    'fr-text-uppercase': 'Uppercase',
  },
  linkAlwaysBlank: true,
  linkAlwaysNoFollow: false,
  linkAutoPrefix: 'http://',
  linkAttributes: {},
  linkConvertEmailAddress: false,
  linkEditButtons: ['linkOpen', 'linkStyle', 'linkEdit', 'linkRemove'],
  linkInsertButtons: ['linkBack', '|', 'linkList'],
  linkList: [],
  linkMultipleStyles: false,
  linkNoOpener: false,
  linkNoReferrer: false,
  linkStyles: {
    'fr-green': 'Green',
    'fr-strong': 'Thick',
  },
  linkText: true,
  listAdvancedTypes: false,
  faButtons: ['fontAwesomeBack', '|'],
  fontAwesomeSets: {},
  saveInterval: 10000,
  saveMethod: 'POST',
  saveParam: 'body',
  saveParams: {},
  saveURL: null,
  videoAllowedProviders: ['.*'],
  videoAllowedTypes: ['mp4', 'webm', 'ogg'],
  videoDefaultAlign: 'center',
  videoDefaultDisplay: 'block',
  tableCellMultipleStyles: false,
  tableColorsButtons: ['tableBack', '|'],
  tableColors: [
    '#61BD6D',
    '#1ABC9C',
    '#54ACD2',
    '#2C82C9',
    '#9365B8',
    '#475577',
    '#CCCCCC',
    '#41A85F',
    '#00A885',
    '#3D8EB9',
    '#2969B0',
    '#553982',
    '#28324E',
    '#000000',
    '#F7DA64',
    '#FBA026',
    '#EB6B56',
    '#E25041',
    '#A38F84',
    '#EFEFEF',
    '#FFFFFF',
    '#FAC51C',
    '#F37934',
    '#D14841',
    '#B8312F',
    '#7C706B',
    '#D1D5D8',
    'REMOVE',
  ],
  tableColorsStep: 7,
  tableDefaultWidth: '100%',
  tableEditButtons: [
    'tableHeader',
    'tableRemove',
    '|',
    'tableRows',
    'tableColumns',
    'tableStyle',
    '-',
    'tableCells',
    'tableCellBackground',
    'tableCellVerticalAlign',
    'tableCellHorizontalAlign',
    'tableCellStyle',
  ],
  tableInsertButtons: ['tableBack', '|'],
  tableInsertHelper: false,
  tableInsertHelperOffset: 15,
  tableInsertMaxSize: 10,
  tableMultipleStyles: false,
  tableResizer: false,
  tableResizerOffset: 5,
  tableResizingLimit: 30,
  tableStyles: {
    'fr-dashed-borders': 'Dashed Borders',
    'fr-alternate-rows': 'Alternate Rows',
  },
  videoDefaultWidth: 600,
  videoEditButtons: [
    'videoReplace',
    'videoRemove',
    '|',
    'videoDisplay',
    'videoAlign',
    'videoSize',
  ],
  videoMaxSize: 1024,
  videoInsertButtons: [
    'videoBack',
    '|',
    'videoByURL',
    'videoEmbed',
    'videoUpload',
  ],
  videoMove: false,
  videoResize: false,
  videoResponsive: true,
  videoSizeButtons: ['videoBack', '|'],
  videoTextNear: false,
  videoSplitHTML: true,
  videoUpload: false,
  videoUploadMethod: 'POST',
  videoUploadParams: {},
  videoUploadParam: 'file',
  videoUploadToS3: false,
  videoUploadURL: null,
  wordAllowedStyleProps: [
    'font-family',
    'font-size',
    'background',
    'color',
    'width',
    'text-align',
    'vertical-align',
    'background-color',
    'padding',
    'margin',
    'height',
    'margin-top',
    'margin-left',
    'margin-right',
    'margin-bottom',
    'text-decoration',
    'font-weight',
    'font-style',
    'text-indent',
    'border',
    'border-.*',
  ],
  wordDeniedAttrs: [],
  wordPasteModal: false,
  wordDeniedTags: [],
  wordPasteKeepFormatting: false,
  filesManagerAllowedTypes: ['*'],
  filesManagerMaxSize: 1024,
  filesManagerUploadParams: {},
  filesManagerUploadToS3: false,
  filesManagerUploadURL: 'http://i.froala.com/upload',
  language: 'en_ca',
};

const InsightEditor = ({ model, onModelChange }) => {
  return (
    <FroalaEditor
      config={froalaConfig}
      model={model}
      onModelChange={onModelChange}
    />
  );
};

export default InsightEditor;

@muyiwaoyeniyi
Copy link

muyiwaoyeniyi commented Jan 25, 2021

@ashokkumarsand I think you're saying you are having an issue importing the plugins while importing the main editor works. In any case, you can't import most (maybe all) of the froala files directly. They need to wrapped with dynamic since they require the window object. So try this based on my previous code #211 (comment)

const FroalaEditor = dynamic(
  async () => {
    const values = await Promise.all([
      import("react-froala-wysiwyg"), // must be first import since we are doing values[0] in return
      import("froala-editor/js/plugins.pkgd.min.js")
    ]);
    return values[0];
  },
  {
    loading: () => <p>LOADING!!!</p>,
    ssr: false
  }
);

@ashokkumarsand
Copy link

it's working thank you.

@muyiwaoyeniyi
Copy link

My pleasure

@ilyaskarim
Copy link

Closing due to inactivity on this issue

@nitin-kumar-bs
Copy link

my import("froala-editor/js/plugins.pkgd.min.js") is not correctly working i am using the same approach

@muyiwaoyeniyi
Copy link

@nitin-kumar-bs can you share a bit more code?

@nitin-kumar-bs
Copy link

yes @muyiwaoyeniyi below is my code
const Editor = dynamic(
async () => {
try {
const values = await Promise.all([
import("react-froala-wysiwyg"),
import("froala-editor/js/plugins.pkgd.min.js"),
]);
return values[0];
} catch (err) {
console.log(err);
}
},
{
loading: () => ,
ssr: false,
}
);
and the issue is my plugins buttons are visible

@muyiwaoyeniyi
Copy link

@nitin-kumar-bs do you have a loading view? I see that it's blank.

@nitin-kumar-bs
Copy link

@muyiwaoyeniyi , yes after adding the loading icon still all plugins buttons are not visible. below is my latest code
import React from "react";
import { Head } from "next/Head";
import "froala-editor/css/froala_editor.pkgd.min.css";
import "froala-editor/css/froala_style.min.css";
import "froala-editor/css/plugins.pkgd.min.css";

// import Tribute from "tributejs";
import "tributejs/dist/tribute.css";

import dynamic from "next/dynamic";
import { Loading } from "@/src/lib/util/common.js";

const ENTER_KEY = 13;
// Dynamic import for the Editor component
const Editor = dynamic(
async () => {
try {
const values = await Promise.all([
import("react-froala-wysiwyg"),
import("froala-editor/js/plugins.pkgd.min.js"),
]);
return values[0];
} catch (err) {
console.log(err);
}
},
{
loading: () => ,
ssr: false,
}
);

class FroalaEditor extends React.Component {
constructor(props) {
super(props);
this.state = {
content: props.initialContent,
onChange: props.onChange,
renderEditor: false,
config: {
toolbarButtons: {
moreText: {
buttons: [
"bold",
"italic",
"underline",
"strikeThrough",
"subscript",
"superscript",
"fontFamily",
"fontSize",
"textColor",
"backgroundColor",
"inlineClass",
"inlineStyle",
"clearFormatting",
],
align: "left",
buttonsVisible: 3,
},
moreParagraph: {
buttons: [
"alignLeft",
"alignCenter",
"formatOLSimple",
"alignRight",
"alignJustify",
"formatOL",
"formatUL",
"paragraphFormat",
"paragraphStyle",
"lineHeight",
"outdent",
"indent",
"quote",
],
align: "left",
buttonsVisible: 3,
},
moreRich: {
buttons: [
"insertLink",
"insertImage",
"insertVideo",
"insertTable",
"emoticons",
"fontAwesome",
"specialCharacters",
"embedly",
"insertFile",
"insertHR",
],
align: "left",
buttonsVisible: 3,
},
moreMisc: {
buttons: [
"undo",
"redo",
"fullscreen",
"print",
"getPDF",
"spellChecker",
"selectAll",
"html",
"help",
],
align: "right",
buttonsVisible: 2,
},
},
placeholderText: "Edit Your Content Here!",
charCounterCount: false,
reactIgnoreAttrs: ["class", "id"],
events: {
initialized: function () {
const editor = this;

        if (props?.shortcuts?.length > 0 && typeof window !== "undefined") {
          // Load and initialize tributejs only in the browser context
          const Tribute = require("tributejs");
          require("tributejs/dist/tribute.css");

          const shortcuts = props?.shortcuts?.map((item) => {
            return {
              key: item.shortcut,
              value: item.ltext,
            };
          });

          const tribute = new Tribute({
            values: shortcuts,
            selectTemplate: function (item) {
              return (
                '<span class="fr-deletable fr-tribute">' +
                item.original.value +
                "</span>"
              );
            },
          });

          tribute.attach(editor.el);
          editor.events.on(
            "keydown",
            function (e) {
              if (e.which == ENTER_KEY && tribute.isActive) {
                return false;
              }
            },
            true
          );
        }
      },
    },
  },
};

}

componentDidMount() {
this.setState({ renderEditor: true });
}

handleModelChange = (model) => {
this.setState({ content: model });
this.state.onChange(model);
};

componentDidUpdate(prevProps) {
if (prevProps.initialContent !== this.props.initialContent) {
this.setState({ content: this.props.initialContent });
}
}

render() {
const { renderEditor } = this.state;

return (
  <div>
    {renderEditor && (
      <Editor
        tag="textarea"
        config={this.state.config}
        model={this.state.content}
        onModelChange={this.handleModelChange}
      />
    )}
  </div>
);

}
}

export default FroalaEditor;
image

@muyiwaoyeniyi
Copy link

muyiwaoyeniyi commented Aug 24, 2023

@nitin-kumar-bs I ran your code. It does have some errors as the Loading icon is missing and the next/Head import is incorrect. Also, I turned off all the tribute code since I don't have that on my end. Here's what I got
image

@nitin-kumar-bs
Copy link

nitin-kumar-bs commented Aug 25, 2023

@nitin-kumar-bs I ran your code. It does have some errors as the Loading icon is missing and the next/Head import is incorrect. Also, I turned off all the tribute code since I don't have that on my end. Here's what I got image

@muyiwaoyeniyi thanks for the reply now i have removed the loading, next/Head and tribute.js but still I am not able to see the plugins buttons and one thing I noticed that when I hover over on "import("froala-editor/js/plugins.pkgd.min.js")" in VSCODE it's giving some error please find the attached file. Below is the latest code please let me know where am I doing wrong.
import React from "react";
import "froala-editor/css/froala_editor.pkgd.min.css";
import "froala-editor/css/froala_style.min.css";
import "froala-editor/css/plugins.pkgd.min.css";

import dynamic from "next/dynamic";
import { Loading } from "@/src/lib/util/common.js";

const ENTER_KEY = 13;
// Dynamic import for the Editor component
const Editor = dynamic(
async () => {
try {
const values = await Promise.all([
import("react-froala-wysiwyg"),
import("froala-editor/js/plugins.pkgd.min.js"),
]);
return values[0];
} catch (err) {
console.log(err);
}
},
{
ssr: false,
}
);

class FroalaEditor extends React.Component {
constructor(props) {
super(props);
this.state = {
content: props.initialContent,
onChange: props.onChange,
renderEditor: false,
config: {
toolbarButtons: {
moreText: {
buttons: [
"bold",
"italic",
"underline",
"strikeThrough",
"subscript",
"superscript",
"fontFamily",
"fontSize",
"textColor",
"backgroundColor",
"inlineClass",
"inlineStyle",
"clearFormatting",
],
align: "left",
buttonsVisible: 3,
},
moreParagraph: {
buttons: [
"alignLeft",
"alignCenter",
"formatOLSimple",
"alignRight",
"alignJustify",
"formatOL",
"formatUL",
"paragraphFormat",
"paragraphStyle",
"lineHeight",
"outdent",
"indent",
"quote",
],
align: "left",
buttonsVisible: 3,
},
moreRich: {
buttons: [
"insertLink",
"insertImage",
"insertVideo",
"insertTable",
"emoticons",
"fontAwesome",
"specialCharacters",
"embedly",
"insertFile",
"insertHR",
],
align: "left",
buttonsVisible: 3,
},
moreMisc: {
buttons: [
"undo",
"redo",
"fullscreen",
"print",
"getPDF",
"spellChecker",
"selectAll",
"html",
"help",
],
align: "right",
buttonsVisible: 2,
},
},
placeholderText: "Edit Your Content Here!",
charCounterCount: false,
reactIgnoreAttrs: ["class", "id"],
},
};
}

componentDidMount() {
this.setState({ renderEditor: true });
}

handleModelChange = (model) => {
this.setState({ content: model });
this.state.onChange(model);
};

componentDidUpdate(prevProps) {
if (prevProps.initialContent !== this.props.initialContent) {
this.setState({ content: this.props.initialContent });
}
}

render() {
const { renderEditor } = this.state;

return (
  <div>
    {renderEditor && (
      <Editor
        tag="textarea"
        config={this.state.config}
        model={this.state.content}
        onModelChange={this.handleModelChange}
      />
    )}
  </div>
);

}
}

export default FroalaEditor;
image

@nitin-kumar-bs
Copy link

Hi @muyiwaoyeniyi , Issue is fixed now by updating the version earlier I was using 4.0.9 thanks for the help

@muyiwaoyeniyi
Copy link

@nitin-kumar-bs My pleasure!

@RamGupta07
Copy link

@muyiwaoyeniyi I'm having issue in uploading image to s3 in froala-editor using imageUploadToS3 config, can you help me fix that?

@muyiwaoyeniyi
Copy link

@RamGupta07 Sure. Are you getting an error? Can you post a screenshot?

@RamGupta07
Copy link

@muyiwaoyeniyi Please check this once : #376

@muyiwaoyeniyi
Copy link

OK I will respond on that issue

@RohanSamad
Copy link

RohanSamad commented Nov 6, 2023

I am Using Froala in Nextjs With Dynamic Import
But I am getting Output like this I don't why it's happening
Screenshot 2023-11-07 020008

While that's my simple code!

import dynamic from "next/dynamic";
import { useRef, useEffect, useState } from "react";

const FroalaEditor = dynamic(
async () => {
const values = await Promise.all([
import("react-froala-wysiwyg"), // must be first import since we are doing values[0] in return
import("froala-editor/js/plugins.pkgd.min.js")
]);
return values[0];
},
{
loading: () =>

LOADING!!!

,
ssr: false
}
);
const FroalaEditorComp = () => {
return (




)
};

export default FroalaEditorComp;

I need help if anyone knows about this!

@dutchsociety
Copy link

I am Using Froala in Nextjs With Dynamic Import But I am getting Output like this I don't why it's happening Screenshot 2023-11-07 020008

While that's my simple code!

import dynamic from "next/dynamic"; import { useRef, useEffect, useState } from "react";

const FroalaEditor = dynamic( async () => { const values = await Promise.all([ import("react-froala-wysiwyg"), // must be first import since we are doing values[0] in return import("froala-editor/js/plugins.pkgd.min.js") ]); return values[0]; }, { loading: () =>

LOADING!!!

,
ssr: false
}
);
const FroalaEditorComp = () => {
return (

)
};
export default FroalaEditorComp;

I need help if anyone knows about this!

You need to add the css

// import "froala-editor/css/froala_style.min.css";
// import "froala-editor/css/froala_editor.pkgd.min.css";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants