Socket
Socket
Sign inDemoInstall

draft-js-aws-amplify-s3-plugin

Package Overview
Dependencies
189
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    draft-js-aws-amplify-s3-plugin

This is a plugin for use with [draft-js-plugins-editor](https://github.com/draft-js-plugins/draft-js-plugins)


Version published
Maintainers
1
Install size
24.0 kB
Created

Readme

Source

DraftJS AWS Amplify S3 Plugin

This is a plugin for use with draft-js-plugins-editor

It is heavily inspired by the draft-js-image-plugin.

Assumptions

Peer Dependencies

Please note that using this plugin requires your project has aws-amplify (not @aws-amplify/storage), react and react-dom packages installed.

Peer Dependencies Motivation

DraftJS has peer dependencies on react and react-dom. Additionally, to successfully use hooks, the react import from your application code needs to resolve to the same module as the react import from inside the react-dom package.

Since the Amplify module installed in your node_modules is correctly configured (using Amplify.configure()), this library hooks directly into that configuration via the peerDependency.

Amplify Configuration

This plugin assumes you've successfully configured AWS Amplify with an awsconfig.

Example Usage

import { EditorState } from 'draft-js';
import Editor from 'draft-js-plugins-editor';
import createImagePlugin from 'draft-js-aws-amplify-s3-plugin';
import React from 'react';

const s3Plugin = createS3Plugin();
const plugins = [s3Plugin];

// The Editor accepts an array of plugins. In this case, only the s3Plugin
// is passed in, although it is possible to pass in multiple plugins.
const MyEditor = ({ editorState }: { editorState: EditorState }) => {
  const onImageChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
    const { files } = e.target;
    const [file] = Array.from(files);
    const { key: s3Key } = (await Storage.put(file.name, file)) as {
      key: string;
    };
    const newEditorState = s3Plugin.addS3Image(editorState, s3Key);
    setEditorState(newEditorState);
  };

  return (
    <>
      <Editor editorState={editorState} onChange={onChange} plugins={plugins} />
      <input type="file" onChange={onImageChange} />
    </>
  );
};

export default MyEditor;

FAQs

Last updated on 26 Dec 2019

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc