Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@tinymce/tinymce-react
Advanced tools
@tinymce/tinymce-react is a React component for TinyMCE, a popular WYSIWYG (What You See Is What You Get) editor. It allows developers to integrate the TinyMCE editor into their React applications easily, providing a rich text editing experience with a wide range of features and customization options.
Basic Integration
This code demonstrates how to integrate the TinyMCE editor into a React application with basic configuration. The editor is initialized with some default content and a set of plugins and toolbar options.
import React from 'react';
import { Editor } from '@tinymce/tinymce-react';
function App() {
return (
<Editor
initialValue="<p>This is the initial content of the editor</p>"
init={{
height: 500,
menubar: false,
plugins: [
'advlist autolink lists link image charmap print preview anchor',
'searchreplace visualblocks code fullscreen',
'insertdatetime media table paste code help wordcount'
],
toolbar:
'undo redo | formatselect | bold italic backcolor | \
alignleft aligncenter alignright alignjustify | \
bullist numlist outdent indent | removeformat | help'
}}
/>
);
}
export default App;
Handling Editor Events
This code shows how to handle events from the TinyMCE editor. The `handleEditorChange` function logs the updated content to the console whenever the content of the editor changes.
import React from 'react';
import { Editor } from '@tinymce/tinymce-react';
function App() {
const handleEditorChange = (content, editor) => {
console.log('Content was updated:', content);
};
return (
<Editor
initialValue="<p>This is the initial content of the editor</p>"
init={{
height: 500,
menubar: false,
plugins: [
'advlist autolink lists link image charmap print preview anchor',
'searchreplace visualblocks code fullscreen',
'insertdatetime media table paste code help wordcount'
],
toolbar:
'undo redo | formatselect | bold italic backcolor | \
alignleft aligncenter alignright alignjustify | \
bullist numlist outdent indent | removeformat | help'
}}
onEditorChange={handleEditorChange}
/>
);
}
export default App;
Customizing the Toolbar
This code demonstrates how to customize the toolbar in the TinyMCE editor. A custom button is added to the toolbar, which shows an alert when clicked.
import React from 'react';
import { Editor } from '@tinymce/tinymce-react';
function App() {
return (
<Editor
initialValue="<p>This is the initial content of the editor</p>"
init={{
height: 500,
menubar: false,
plugins: [
'advlist autolink lists link image charmap print preview anchor',
'searchreplace visualblocks code fullscreen',
'insertdatetime media table paste code help wordcount'
],
toolbar:
'myCustomToolbarButton | undo redo | formatselect | bold italic backcolor | \
alignleft aligncenter alignright alignjustify | \
bullist numlist outdent indent | removeformat | help',
setup: (editor) => {
editor.ui.registry.addButton('myCustomToolbarButton', {
text: 'My Button',
onAction: () => alert('Button clicked!')
});
}
}}
/>
);
}
export default App;
React-Quill is a React component for Quill, a powerful, rich text editor. It offers a similar WYSIWYG editing experience and is known for its simplicity and ease of use. Compared to @tinymce/tinymce-react, React-Quill has fewer built-in plugins but is highly customizable through its API.
Draft.js is a framework for building rich text editors in React, developed by Facebook. It provides a lot of flexibility and control over the editor's behavior and appearance. Unlike @tinymce/tinymce-react, Draft.js is more of a low-level tool, requiring more setup and configuration to achieve similar functionality.
CKEditor 4 React is a React component for CKEditor 4, another popular WYSIWYG editor. It offers a wide range of features and plugins similar to TinyMCE. CKEditor 4 is known for its robust feature set and extensive documentation, making it a strong alternative to @tinymce/tinymce-react.
This package is a thin wrapper around tinymce
to make it easier to use in a React application.
For some quick demos, check out the storybook.
$ npm install @tinymce/tinymce-react
First you have to import the component, and how you do this depends on how the app you are developing is set up.
// es modules
import { Editor } from '@tinymce/tinymce-react';
// commonjs require
var { Editor } = require('@tinymce/tinymce-react');
Use the editor in your app like this:
<Editor
apiKey="API_KEY"
init={{ plugins: 'link table' }}
/>
The editor accepts the following props:
id
: An id for the editor so you can later grab the instance by using the tinymce.get('ID')
method on tinymce, defaults to an automatically generated uuid.init
: Object sent to the tinymce.init
method used to initialize the editor.initialValue
: Initial value that the editor will be initialized with.inline
: Shorthand for setting that the editor should be inline, <Editor inline />
is the same as setting {inline: true}
in the init.tagName
: Only used if the editor is inline, decides what element to initialize the editor on, defaults to div
.plugins
: Shorthand for setting what plugins you want to use, <Editor plugins="foo bar" />
is the same as setting {plugins: 'foo bar'}
in the init.toolbar
: Shorthand for setting what toolbar items you want to show, <Editor toolbar="foo bar" />
is the same as setting {toolbar: 'foo bar'}
in the init.apiKey
: Api key for TinyMCE cloud, more info below.cloudChannel
: Cloud channel for TinyMCE Cloud, more info below.You can bind editor events via a shorthand prop on the editor, for example:
<Editor onSelectionChange="this.handlerFunction" />
Where the handler function will be called with the event and a reference to the editor.
Here is a full list of the events available:
onActivate
onAddUndo
onBeforeAddUndo
onBeforeExecCommand
onBeforeGetContent
onBeforeRenderUI
onBeforeSetContent
onBeforePaste
onBlur
onChange
onClearUndos
onClick
onContextMenu
onCopy
onCut
onDblclick
onDeactivate
onDirty
onDrag
onDragDrop
onDragEnd
onDragGesture
onDragOver
onDrop
onExecCommand
onFocus
onFocusIn
onFocusOut
onGetContent
onHide
onInit
onKeyDown
onKeyPress
onKeyUp
onLoadContent
onMouseDown
onMouseEnter
onMouseLeave
onMouseMove
onMouseOut
onMouseOver
onMouseUp
onNodeChange
onObjectResizeStart
onObjectResized
onObjectSelected
onPaste
onPostProcess
onPostRender
onPreInit
onPreProcess
onProgressState
onRedo
onRemove
onReset
onSaveContent
onSelectionChange
onSetAttrib
onSetContent
onShow
onSubmit
onUndo
onVisualAid
The Editor
component needs TinyMCE to be globally available to work, but to make it as easy as possible it will automatically load TinyMCE Cloud if it can't find TinyMCE available when the component is mounting. To get rid of the This domain is not registered...
warning, sign up for the cloud and enter the api key like this:
<Editor apiKey='YOUR_API_KEY' init={{ /* your other settings */ }} />
You can also define what cloud channel you want to use out these three
stable
Default. The most stable and well tested version that has passed the Ephox quality assurance process.testing
This channel will deploy the current candidate for release to the stable
channel.dev
The cutting edge version of TinyMCE updated daily for the daring users.So using the dev
channel would look like this:
<Editor apiKey='YOUR_API_KEY' cloudChannel='dev' init={{ /* your other settings */ }} />
For more info on the different versions see the documentation.
To opt out of using TinyMCE cloud you have to make TinyMCE globally available yourself. This can be done either by hosting the tinymce.min.js
file by youself and adding a script tag to you HTML or, if you are using a module loader, installing TinyMCE with npm. For info on how to get TinyMCE working with module loaders check out this page in the documentation.
Can be found on TinyMCE.com.
2.1.3 - 2018-01-17
plugins
and toolbar
shorthands.FAQs
Official TinyMCE React Component
The npm package @tinymce/tinymce-react receives a total of 293,768 weekly downloads. As such, @tinymce/tinymce-react popularity was classified as popular.
We found that @tinymce/tinymce-react demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.