
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
draft-js-select-image-plugin
Advanced tools
Embed a local image in your draft-js editor
This is a plugin for draft-js-plugins-editor
.
npm install draft-js-select-image-plugin
This plugin exposes a button that integrates with the side toolbar.
import createSelectImagePlugin from 'draft-js-select-image-plugin';
const selectImagePlugin = createSelectImagePlugin({});
const { SelectImageButton } = selectImagePlugin;
Param | Default | Description |
---|---|---|
imageType | IMAGE | Type of entity created when inserting the atomic block. By default it's the same value as draft-js-image-plugin |
Rendering the image is out of scope, but in the following example you can see how to integrate draft-js-image-plugin
.
import React from 'react';
import ReactDOM from 'react-dom';
import Editor from 'draft-js-plugins-editor';
import { EditorState } from 'draft-js';
import createSideToolbarPlugin from 'draft-js-side-toolbar-plugin';
import BlockTypeSelect from 'draft-js-side-toolbar-plugin/lib/components/BlockTypeSelect';
import createImagePlugin from 'draft-js-image-plugin';
import createSelectImagePlugin from 'draft-js-select-image-plugin';
import 'draft-js-side-toolbar-plugin/lib/plugin.css';
const imagePlugin = createImagePlugin();
const selectImagePlugin = createSelectImagePlugin();
const DefaultBlockTypeSelect = ({ getEditorState, setEditorState, theme }) => (
<BlockTypeSelect
getEditorState={getEditorState}
setEditorState={setEditorState}
theme={theme}
structure={[
selectImagePlugin.SelectImageButton
]}
/>
);
const sideToolbarPlugin = createSideToolbarPlugin({
structure: [DefaultBlockTypeSelect],
});
const { SideToolbar } = sideToolbarPlugin;
class MyEditor extends React.Component {
constructor(props) {
super(props);
this.state = {
editorState: EditorState.createEmpty()
};
this.plugins = [
sideToolbarPlugin,
imagePlugin
];
}
onChange = (editorState) => {
this.setState({ editorState });
}
render() {
return (
<div className="editor">
<Editor
editorState={this.state.editorState}
onChange={this.onChange}
plugins={this.plugins}
placeholder="Tell a story" />
<SideToolbar />
</div>
);
}
}
ReactDOM.render(<MyEditor />, document.getElementById('root'));
FAQs
Embed a local image in your draft-js editor
The npm package draft-js-select-image-plugin receives a total of 2 weekly downloads. As such, draft-js-select-image-plugin popularity was classified as not popular.
We found that draft-js-select-image-plugin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.