React component for Froala WYSIWYG HTML Rich Text Editor.
Installations
npm install react-froala-wysiwyg
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
14.21.3
NPM Version
6.14.18
Score
86.3
Supply Chain
84.1
Quality
83.9
Maintenance
100
Vulnerability
99.1
License
Releases
Contributors
Languages
JavaScript (51.41%)
Shell (46.5%)
Dockerfile (2.09%)
Developer
Download Statistics
Total Downloads
12,187,661
Last Day
8,477
Last Week
58,134
Last Month
258,388
Last Year
3,114,845
GitHub Statistics
565 Stars
211 Commits
132 Forks
16 Watching
11 Branches
26 Contributors
Bundle Size
478.90 kB
Minified
132.42 kB
Minified + Gzipped
Package Meta Information
Latest Version
4.3.1
Package Id
react-froala-wysiwyg@4.3.1
Unpacked Size
177.88 kB
Size
30.08 kB
File Count
49
NPM Version
6.14.18
Node Version
14.21.3
Publised On
18 Nov 2024
Total Downloads
Cumulative downloads
Total Downloads
12,187,661
Last day
-20.1%
8,477
Compared to previous day
Last week
-6.1%
58,134
Compared to previous week
Last month
-7%
258,388
Compared to previous month
Last year
20.4%
3,114,845
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
2
Dev Dependencies
38
React JS Froala WYSIWYG Editor
react-froala-wyswiyg provides React bindings to the Froala WYSIWYG editor VERSION 3.
Installation
1npm install react-froala-wysiwyg --save
Update editor version
1npm update froala-editor
Install font-awesome
1npm install font-awesome --save
Usage with Class Component
1. Require and use Froala Editor component inside your application.
1import React from 'react'; 2import ReactDOM from 'react-dom'; 3 4 5// Require Editor CSS files. 6import 'froala-editor/css/froala_style.min.css'; 7import 'froala-editor/css/froala_editor.pkgd.min.css'; 8 9import FroalaEditorComponent from 'react-froala-wysiwyg'; 10 11// Import all Froala Editor plugins; 12// import 'froala-editor/js/plugins.pkgd.min.js'; 13 14// Import a single Froala Editor plugin. 15// import 'froala-editor/js/plugins/align.min.js'; 16 17// Import a language file. 18// import 'froala-editor/js/languages/de.js'; 19 20// Import a third-party plugin. 21// import 'froala-editor/js/third_party/image_tui.min.js'; 22// import 'froala-editor/js/third_party/embedly.min.js'; 23// import 'froala-editor/js/third_party/spell_checker.min.js'; 24 25// Include font-awesome css if required. 26// install using "npm install font-awesome --save" 27// import 'font-awesome/css/font-awesome.css'; 28// import 'froala-editor/js/third_party/font_awesome.min.js'; 29 30// Include special components if required. 31// import FroalaEditorView from 'react-froala-wysiwyg/FroalaEditorView'; 32// import FroalaEditorA from 'react-froala-wysiwyg/FroalaEditorA'; 33// import FroalaEditorButton from 'react-froala-wysiwyg/FroalaEditorButton'; 34// import FroalaEditorImg from 'react-froala-wysiwyg/FroalaEditorImg'; 35// import FroalaEditorInput from 'react-froala-wysiwyg/FroalaEditorInput'; 36 37// Render Froala Editor component. 38ReactDOM.render(<FroalaEditorComponent tag='textarea'/>, document.getElementById('editor'));
Add editor to UI by passing id to html element
<div id="editor">
</div>
Pass properties to the wrapping DOM element
1<FroalaEditor 2 tag='textarea' 3 config={this.config} 4 model={this.state.model} 5 onModelChange={this.handleModelChange} 6/>
tag attr is used to tell on which tag the editor is initialized.
There are special tags: a, button, img, input. Do not use them in FroalaEditor component. To initialize the editor on a special tag, use FroalaEditorA
, FroalaEditorButton
, FroalaEditorImg
and FroalaEditorInput
components.
Config
You can pass editor options as component attribute (optional).
config={this.config}
You can pass any existing Froala option. Consult the Froala documentation to view the list of all the available options:
1config={{ 2 placeholderText: 'Edit Your Content Here!', 3 charCounterCount: false 4}}
Aditional option is used:
- immediateReactModelUpdate: (default: false) This option updates the React model as soon as a key is released in the editor. Note that it may affect performances.
Events and Methods
Events can be passed in with the options, with a key events and object where the key is the event name and the value is the callback function.
1config={{ 2 placeholder: "Edit Me", 3 events : { 4 'focus' : function(e, editor) { 5 console.log(editor.selection.get()); 6 } 7 } 8}}
Using the editor instance from the arguments of the callback you can call editor methods as described in the method docs.
Froala events are described in the events docs.
Model
The WYSIWYG HTML editor content model.
model = {this.state.model}
Two way binding:
1import React from 'react'; 2 3class EditorComponent extends React.Component { 4 constructor () { 5 super(); 6 7 this.handleModelChange = this.handleModelChange.bind(this); 8 9 this.state = { 10 model: 'Example text' 11 }; 12 } 13 14 handleModelChange: function(model) { 15 this.setState({ 16 model: model 17 }); 18 } 19 20 render () { 21 return <FroalaEditor 22 model={this.state.model} 23 onModelChange={this.handleModelChange} 24 /> 25 } 26}
To achieve one way binding and pass only the initial editor content, simply do not pass onModelChange
attribute.
Use the content in other places:
1<input value={this.state.model}/>
Special tags
You can also use the editor on img, button, input and a tags:
1<FroalaEditorImg 2 config={this.config} 3/> 4<FroalaEditorButton 5 config={this.config} 6/> 7<FroalaEditorInput 8 config={this.config} 9/> 10<FroalaEditorA 11 config={this.config} 12/>
The model must be an object containing the attributes for your special tags. Example:
1constructor () { 2 super(); 3 4 this.handleModelChange = this.handleModelChange.bind(this); 5 6 this.state = { 7 model: {src: 'path/to/image.jpg'} 8 }; 9}
- The model can contain a special attribute named innerHTML which inserts innerHTML in the element: If you are using 'button' tag, you can specify the button text like this:
1this.state = { 2 model: {innerHTML: 'Click Me'} 3};
As the button text is modified by the editor, the innerHTML attribute from buttonModel model will be modified too.
Manual Instantiation
Gets the functionality to operate on the editor: create, destroy and get editor instance. Use it if you want to manually initialize the editor.
onManualControllerReady={this.handleManualController}
1handleManualController: function(initControls) { 2 //... 3}
The object received by the function will contain the following methods:
- initialize: Call this method to initialize the Froala Editor
- destroy: Call this method to destroy the Froala Editor
- getEditor: Call this method to retrieve the editor that was created. This method will return null if the editor was not yet created
Displaying HTML
To display content created with the froala editor use the FroalaEditorView
component.
1<FroalaEditor 2 model={this.state.content} 3 onModelChange={this.handleModelChange} 4/> 5<FroalaEditorView 6 model={this.state.content} 7/>
Usage with Functional Component
1. Require and use Froala Editor component inside your application.
1import React from 'react'; 2import ReactDOM from 'react-dom'; 3 4// Require Editor CSS files. 5import 'froala-editor/css/froala_style.min.css'; 6import 'froala-editor/css/froala_editor.pkgd.min.css'; 7 8import FroalaEditorComponent from 'react-froala-wysiwyg'; 9 10// Import all Froala Editor plugins; 11// import 'froala-editor/js/plugins.pkgd.min.js'; 12 13// Import a single Froala Editor plugin. 14// import 'froala-editor/js/plugins/align.min.js'; 15 16// Import a language file. 17// import 'froala-editor/js/languages/de.js'; 18 19// Import a third-party plugin. 20// import 'froala-editor/js/third_party/image_tui.min.js'; 21// import 'froala-editor/js/third_party/embedly.min.js'; 22// import 'froala-editor/js/third_party/spell_checker.min.js'; 23 24// Include font-awesome css if required. 25// install using "npm install font-awesome --save" 26// import 'font-awesome/css/font-awesome.css'; 27// import 'froala-editor/js/third_party/font_awesome.min.js'; 28 29// Include special components if required. 30// import FroalaEditorView from 'react-froala-wysiwyg/FroalaEditorView'; 31// import FroalaEditorA from 'react-froala-wysiwyg/FroalaEditorA'; 32// import FroalaEditorButton from 'react-froala-wysiwyg/FroalaEditorButton'; 33// import FroalaEditorImg from 'react-froala-wysiwyg/FroalaEditorImg'; 34// import FroalaEditorInput from 'react-froala-wysiwyg/FroalaEditorInput'; 35 36// Render Froala Editor component. 37const root = ReactDOM.createRoot(document.getElementById('editor')); 38root.render( 39 <FroalaEditorComponent tag='textarea'/> 40) 41
Add editor to UI by passing id to html element
<div id="editor">
</div>
Pass properties to the wrapping DOM element
1<FroalaEditor 2 tag='textarea' 3 config={config} 4 model={model} 5 onModelChange={handleModelChange} 6/>
tag attr is used to tell on which tag the editor is initialized.
There are special tags: a, button, img, input. Do not use them in FroalaEditor component. To initialize the editor on a special tag, use FroalaEditorA
, FroalaEditorButton
, FroalaEditorImg
and FroalaEditorInput
components.
Config
You can pass editor options as component attribute (optional).
config={config}
You can pass any existing Froala option. Consult the Froala documentation to view the list of all the available options:
1config={{ 2 placeholderText: 'Edit Your Content Here!', 3 charCounterCount: false 4}}
Aditional option is used:
- immediateReactModelUpdate: (default: false) This option updates the React model as soon as a key is released in the editor. Note that it may affect performances.
Events and Methods
Events can be passed in with the options, with a key events and object where the key is the event name and the value is the callback function.
1config={{ 2 placeholder: "Edit Me", 3 events : { 4 'focus' : function(e, editor) { 5 console.log(editor.selection.get()); 6 } 7 } 8}}
Using the editor instance from the arguments of the callback you can call editor methods as described in the method docs.
Froala events are described in the events docs.
Now you can use these buttons in options:
1toolbarButtons: [['undo', 'redo' , 'bold'], ['alert', 'clear', 'insert']], 2
Model
The WYSIWYG HTML editor content model.
model = {model}
Two way binding:
1import React,{ useState } from 'react'; 2 3const App=()=> { 4 const [model,setModel] = useState("Example Set"); 5 6 const handleModelChange= (event)=>{ 7 setModel(event) 8 } 9 return ( 10 <div className="App"> 11 <FroalaEditorComponent 12 tag='textarea' 13 onModelChange={handleModelChange} 14 /> 15 <FroalaEditorView 16 model={model} 17 /> 18 </div> 19 ); 20}
To achieve one way binding and pass only the initial editor content, simply do not pass onModelChange
attribute.
Use the content in other places:
1<input value={model}/>
Special tags
You can also use the editor on img, button, input and a tags:
1<FroalaEditorImg 2 model={model} 3/> 4<FroalaEditorButton 5 model={model} 6/> 7<FroalaEditorInput 8 model={model} 9/> 10<FroalaEditorA 11 model={model} 12/> 13
The model must be an object containing the attributes for your special tags. Example:
1 model={{src: 'path/to/image.jpg', 2 width:"300px", 3 alt:"Old Clock" 4 }}
- The model can contain a special attribute named innerHTML which inserts innerHTML in the element: If you are using 'button' tag, you can specify the button text like this:
1model={{innerHTML: 'Click Me'}}
As the button text is modified by the editor, the innerHTML attribute from buttonModel model will be modified too.
Manual Instantiation
Gets the functionality to operate on the editor: create, destroy and get editor instance. Use it if you want to manually initialize the editor.
onManualControllerReady={handleManualController}
1handleManualController =(initControls) =>{ 2 //... 3}
The object received by the function will contain the following methods:
- initialize: Call this method to initialize the Froala Editor
- destroy: Call this method to destroy the Froala Editor
- getEditor: Call this method to retrieve the editor that was created. This method will return null if the editor was not yet created
Displaying HTML
To display content created with the froala editor use the FroalaEditorView
component.
1<FroalaEditor 2 model={content} 3 onModelChange={handleModelChange} 4/> 5<FroalaEditorView 6 model={content} 7/>
Specific option for special tags
- reactIgnoreAttrs: (default: null) This option is an array of attributes that you want to ignore when the editor updates the froalaModel:
1config: { 2 reactIgnoreAttrs: ['class', 'id'] 3},
Using type definition file
index.d.ts
file is the type definition file for this repository. It is placed inside lib folder.In order to use it in your code , use the following line:
///<reference path= "index.d.ts" />
where path is the location of index.d.ts file.
Custom Buttons
You can pass the custom buttons to the editor by following way:
1<script> 2import Froalaeditor from 'froala-editor'; 3Froalaeditor.DefineIcon('alert', {NAME: 'info', SVG_KEY: 'help'}); 4 Froalaeditor.RegisterCommand('alert', { 5 title: 'Hello', 6 focus: false, 7 undo: false, 8 refreshAfterCallback: false, 9 callback: function () { 10 alert('Hello!'); 11 } 12 }); 13 14 Froalaeditor.DefineIcon('clear', {NAME: 'remove', SVG_KEY: 'remove'}); 15 Froalaeditor.RegisterCommand('clear', { 16 title: 'Clear HTML', 17 focus: false, 18 undo: true, 19 refreshAfterCallback: true, 20 callback: function () { 21 this.html.set(''); 22 this.events.focus(); 23 } 24 }); 25 26 Froalaeditor.DefineIcon('insert', {NAME: 'plus', SVG_KEY: 'add'}); 27 Froalaeditor.RegisterCommand('insert', { 28 title: 'Insert HTML', 29 focus: true, 30 undo: true, 31 refreshAfterCallback: true, 32 callback: function () { 33 this.html.insert('My New HTML'); 34 } 35 }); 36 </script> 37
Now you can use these buttons in options:
1toolbarButtons: [['undo', 'redo' , 'bold'], ['alert', 'clear', 'insert']], 2
License
The react-froala-wyswiyg
project is under MIT license. However, in order to use Froala WYSIWYG HTML Editor plugin you should purchase a license for it.
Froala Editor has 3 different licenses for commercial use. For details please see License Agreement.
Development environment setup
If you want to contribute to react-froala-wyswiyg, you will first need to install the required tools to get the project going.
Prerequisites
- Node Package Manager (NPM)
- Git
Install dependencies
$ npm install
Build
$ npm run build
Run Demo
$ npm run demo
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
Found 6/26 approved changesets -- score normalized to 2
Reason
2 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 1
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: containerImage not pinned by hash: Dockerfile:1: pin your Docker image by updating node:14.19.0 to node:14.19.0@sha256:224cb9e0a988e1f6cc9b2c30be4dc508ef0ee1199b0f507d27297ff026d742c8
- Warn: npmCommand not pinned by hash: Dockerfile:16
- Info: 0 out of 1 containerImage dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 11 are checked with a SAST tool
Score
2.8
/10
Last Scanned on 2024-12-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More