New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

draft-js-select-image-plugin

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

draft-js-select-image-plugin

Embed a local image in your draft-js editor

  • 0.5.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

draft-js-select-image-plugin

Embed a local image in your draft-js editor

This is a plugin for draft-js-plugins-editor.

Installation

npm install draft-js-select-image-plugin

Usage

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;

Configuration

ParamDefaultDescription
imageTypeIMAGEType of entity created when inserting the atomic block. By default it's the same value as draft-js-image-plugin

Integration

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'));

Acknowledge

  • Icon by: https://www.iconfinder.com/icons/290132/gallery_image_photo_photography_picture_pictures_icon

Keywords

FAQs

Package last updated on 05 Jun 2018

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc