GitXplorerGitXplorer
A

draft-js-aws-amplify-s3-plugin

public
4 stars
0 forks
15 issues

Commits

List of commits on branch master.
Verified
7236c17c1d467d209d7810f64add2a77b0a022ba

Fix bad README

AAryanJ-NYC committed 4 years ago
Unverified
e103079974d6df7cee41109bf7dca0fe43808fcb

Fix import in README

committed 5 years ago
Unverified
0beb25bced0dd8b317dfcf6cd4d9f8b5f9444160

Move draft-js to dev dependency

committed 5 years ago
Unverified
f74bc3c4b3fdd47a8c878c2f345441ba9f47888f

Move draft-js to dev dependency

committed 5 years ago
Verified
2292a5893659b814dc94dd817bcab84a765a8e7f

Update README.md

AAryanJ-NYC committed 5 years ago
Verified
71a42d2be2e330661008b71537b724c447c171d0

Update README.md

AAryanJ-NYC committed 5 years ago

README

The README file for this repository.

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), draft-js, 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 { Storage } from 'aws-amplify';
import { EditorState } from 'draft-js';
import Editor from 'draft-js-plugins-editor';
import createS3Plugin 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;