froala/react-froala-wysiwyg
Trên GitHub, froala/react-froala-wysiwyg đã đạt 1 sao, ngôn ngữ JavaScript. React component for Froala WYSIWYG HTML Rich Text Editor.
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
Snapshot
Cộng tác viên hàng đầu
Xem cộng tác viên hàng đầu
React JS Froala WYSIWYG Editor
react-froala-wyswiyg provides React bindings to the Froala WYSIWYG editor VERSION 3.
Installation
npm install react-froala-wysiwyg --save
Update editor version
npm update froala-editor
Install font-awesome
npm install font-awesome --save
Usage with Class Component
1. Require and use Froala Editor component inside your application.
import React from 'react';
import ReactDOM from 'react-dom/client';
// Require Editor CSS files.
import 'froala-editor/css/froala_style.min.css';
import 'froala-editor/css/froala_editor.pkgd.min.css';
import FroalaEditorComponent from 'react-froala-wysiwyg';
// 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';
// Include special components if required.
// import FroalaEditorView from 'react-froala-wysiwyg/FroalaEditorView';
// import FroalaEditorA from 'react-froala-wysiwyg/FroalaEditorA';
// import FroalaEditorButton from 'react-froala-wysiwyg/FroalaEditorButton';
// import FroalaEditorImg from 'react-froala-wysiwyg/FroalaEditorImg';
// import FroalaEditorInput from 'react-froala-wysiwyg/FroalaEditorInput';
// Render Froala Editor component.
const root = ReactDOM.createRoot(document.getElementById('editor'));
root.render(<FroalaEditorComponent tag='textarea'/>);
Add editor to UI by passing id to html element
<div id="editor">
</div>
Pass properties to the wrapping DOM element
<FroalaEditor
tag='textarea'
config={this.config}
model={this.state.model}
onModelChange={this.handleModelChange}
/>
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:
config={{
placeholderText: 'Edit Your Content Here!',
charCounterCount: false
}}
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.
config={{
placeholder: "Edit Me",
events : {
'focus' : function(e, editor) {
console.log(editor.selection.get());
}
}
}}
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:
import React from 'react';
class EditorComponent extends React.Component {
constructor () {
super();
this.handleModelChange = this.handleModelChange.bind(this);
this.state = {
model: 'Example text'
};
}
handleModelChange: function(model) {
this.setState({
model: model
});
}
render () {
return <FroalaEditor
model={this.state.model}
onModelChange={this.handleModelChange}
/>
}
}
To achieve one way binding and pass only the initial editor content, simply do not pass onModelChange attribute.
Use the content in other places:
<input value={this.state.model}/>
Special tags
You can also use the editor on img, button, input and a tags:
<FroalaEditorImg
config={this.config}
/>
<FroalaEditorButton
config={this.config}
/>
<FroalaEditorInput
config={this.config}
/>
<FroalaEditorA
config={this.config}
/>
The model must be an object containing the attributes for your special tags. Example:
constructor () {
super();
this.handleModelChange = this.handleModelChange.bind(this);
this.state = {
model: {src: 'path/to/image.jpg'}
};
}
- 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:
this.state = {
model: {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={this.handleManualController}
handleManualController: function(initControls) {
//...
}
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.
<FroalaEditor
model={this.state.content}
onModelChange={this.handleModelChange}
/>
<FroalaEditorView
model={this.state.content}
/>
Usage with Functional Component
1. Require and use Froala Editor component inside your application.
import React from 'react';
import ReactDOM from 'react-dom/client';
// Require Editor CSS files.
import 'froala-editor/css/froala_style.min.css';
import 'froala-editor/css/froala_editor.pkgd.min.css';
import FroalaEditorComponent from 'react-froala-wysiwyg';
// 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';
// Include special components if required.
// import FroalaEditorView from 'react-froala-wysiwyg/FroalaEditorView';
// import FroalaEditorA from 'react-froala-wysiwyg/FroalaEditorA';
// import FroalaEditorButton from 'react-froala-wysiwyg/FroalaEditorButton';
// import FroalaEditorImg from 'react-froala-wysiwyg/FroalaEditorImg';
// import FroalaEditorInput from 'react-froala-wysiwyg/FroalaEditorInput';
// Render Froala Editor component.
const root = ReactDOM.createRoot(document.getElementById('editor'));
root.render(
<FroalaEditorComponent tag='textarea'/>
)
Add editor to UI by passing id to html element
<div id="editor">
</div>
Pass properties to the wrapping DOM element
<FroalaEditor
tag='textarea'
config={config}
model={model}
onModelChange={handleModelChange}
/>
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:
config={{
placeholderText: 'Edit Your Content Here!',
charCounterCount: false
}}
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.
config={{
placeholder: "Edit Me",
events : {
'focus' : function(e, editor) {
console.log(editor.selection.get());
}
}
}}
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:
toolbarButtons: [['undo', 'redo' , 'bold'], ['alert', 'clear', 'insert']],
Model
The WYSIWYG HTML editor content model.
model = {model}
Two way binding:
import React,{ useState } from 'react';
const App=()=> {
const [model,setModel] = useState("Example Set");
const handleModelChange= (event)=>{
setModel(event)
}
return (
<div className="App">
<FroalaEditorComponent
tag='textarea'
onModelChange={handleModelChange}
/>
<FroalaEditorView
model={model}
/>
</div>
);
}
To achieve one way binding and pass only the initial editor content, simply do not pass onModelChange attribute.
Use the content in other places:
<input value={model}/>
Special tags
You can also use the editor on img, button, input and a tags:
<FroalaEditorImg
model={model}
/>
<FroalaEditorButton
model={model}
/>
<FroalaEditorInput
model={model}
/>
<FroalaEditorA
model={model}
/>
The model must be an object containing the attributes for your special tags. Example:
model={{src: 'path/to/image.jpg',
width:"300px",
alt:"Old Clock"
}}
- 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:
model={{innerHTML: 'Click Me'}}
As the button text is modified by the editor, the innerHTML attribute from buttonModel model will be modified too.
Usage with Server-Side Rendering
When using Server-Side Rendering you can use Froala components as described previously. If you require additonal plugins or translations, you will have to use React lazy loading in order to load the plugins first. Please refer to the examples below.
Class component
import React, { Suspense } from "react";
import 'froala-editor/css/froala_editor.pkgd.min.css';
import 'froala-editor/css/froala_style.css';
const FroalaEditor = React.lazy(() => import('react-froala-wysiwyg'));
export default class MyComponent extends React.Component {
constructor () {
super();
this.state = {
isInitialized: false
};
}
componentDidMount() {
// Import all Froala Editor plugins;
import('froala-editor/js/plugins.pkgd.min.js').then(() => this.setState({isInitialized: true}));
}
render() {
return <>
{this.state.isInitialized && (
<Suspense fallback={<p>Loading...</p>}>
<FroalaEditor
model={content}
/>
</Suspense>
)}
</>;
}
}
Functional component
import React, { Suspense, useEffect, useState } from "react";
import 'froala-editor/css/froala_editor.pkgd.min.css';
import 'froala-editor/css/froala_style.css';
const FroalaEditor = React.lazy(() => import('react-froala-wysiwyg'));
export default function MyComponent() {
const [isInitialized, setIsInitialized] = useState(false);
useEffect(() => {
async function initPlugins() {
// Import all Froala Editor plugins;
await import('froala-editor/js/plugins.pkgd.min.js');
setIsInitialized(true);
}
if (!isInitialized) {
initPlugins();
}
});
return <>
{isInitialized && (
<Suspense fallback={<p>Loading...</p>}>
<FroalaEditor
model={content}
/>
</Suspense>
)}
</>;
}
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}
handleManualController =(initControls) =>{
//...
}
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.
<FroalaEditor
model={content}
onModelChange={handleModelChange}
/>
<FroalaEditorView
model={content}
/>
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:
config: {
reactIgnoreAttrs: ['class', 'id']
},
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:
<script>
import Froalaeditor from 'froala-editor';
Froalaeditor.DefineIcon('alert', {NAME: 'info', SVG_KEY: 'help'});
Froalaeditor.RegisterCommand('alert', {
title: 'Hello',
focus: false,
undo: false,
refreshAfterCallback: false,
callback: function () {
alert('Hello!');
}
});
Froalaeditor.DefineIcon('clear', {NAME: 'remove', SVG_KEY: 'remove'});
Froalaeditor.RegisterCommand('clear', {
title: 'Clear HTML',
focus: false,
undo: true,
refreshAfterCallback: true,
callback: function () {
this.html.set('');
this.events.focus();
}
});
Froalaeditor.DefineIcon('insert', {NAME: 'plus', SVG_KEY: 'add'});
Froalaeditor.RegisterCommand('insert', {
title: 'Insert HTML',
focus: true,
undo: true,
refreshAfterCallback: true,
callback: function () {
this.html.insert('My New HTML');
}
});
</script>
Now you can use these buttons in options:
toolbarButtons: [['undo', 'redo' , 'bold'], ['alert', 'clear', 'insert']],
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
Repo liên quan
Master programming by recreating your favorite technologies from scratch.
A curated meta-list of curated lists organized by technology domain. The repository acts as a directory pointing to hundreds of specialized awesome lists covering programming languages, platforms, frameworks, and tooling. All content is community-contributed under the CC0 public domain dedication.
Public APIs is a community-curated GitHub repository listing free, publicly accessible APIs across a wide range of categories, with auth type, HTTPS, and CORS noted for each entry. It's a browsable reference, not a library to install.
freeCodeCamp.org's open-source codebase and curriculum. Learn math, programming, and computer science for free.
Trả lời nhanh
Đọc thêm về froala/react-froala-wysiwyg ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/froala/react-froala-wysiwyg là nguồn chính thức.
froala/react-froala-wysiwyg có phải mã nguồn mở không?
TopGit chưa ghi nhận license cho froala/react-froala-wysiwyg. Phần lớn repo public trên GitHub là mã nguồn mở, nhưng điều khoản khác nhau từng repo — mở file LICENSE để xác nhận.
froala/react-froala-wysiwyg có tag gì không?
Bản đồng bộ chưa ghi nhận topic GitHub nào cho froala/react-froala-wysiwyg. GitHub topics hiển thị ở thanh bên phải trang repo — đó là nơi đáng kiểm tra nhất.
froala/react-froala-wysiwyg có trang demo không?
Dự án có trang chủ ở https://froala.com/wysiwyg-editor. Tab "Readme" ở trang này thường có ảnh chụp và hướng dẫn bắt đầu nhanh.
froala/react-froala-wysiwyg còn đang phát triển không?
Commit gần nhất trên froala/react-froala-wysiwyg là 26 ngày trước (theo timestamp GitHub). Repo có 0 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
Đọc đầy đủ README ở tab phía trên.