question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Draft JS DnD Upload Plugin doesn't call handleUpload

See original GitHub issue

Use-case/Problem

I’m trying to setup an editor to handle drag and drop image uploading to S3, though it seems like the handleUpload function that is required to pass in is never actually called. Looks like it’s even commented out https://github.com/draft-js-plugins/draft-js-plugins/blob/master/draft-js-drag-n-drop-upload-plugin/src/handleDroppedFiles.js#L47

Is there a work around for this? The docs show this working https://www.draft-js-plugins.com/plugin/image

Full code for testing, when drag and dropping only the console.log(src) is called, not console.log(arguments) in the handleUpload function.

import React from 'react';
import { EditorState } from 'draft-js';
import Editor, { composeDecorators } from 'draft-js-plugins-editor';;
import createSideToolbarPlugin from 'draft-js-side-toolbar-plugin';
import createFocusPlugin from 'draft-js-focus-plugin';
import createImagePlugin from 'draft-js-image-plugin';
import createAlignmentPlugin from 'draft-js-alignment-plugin';
import createResizeablePlugin from 'draft-js-resizeable-plugin';
import createBlockDndPlugin from 'draft-js-drag-n-drop-plugin';
import createDragNDropUploadPlugin from '@mikeljames/draft-js-drag-n-drop-upload-plugin';

import 'draft-js-image-plugin/lib/plugin.css';

import editorStyles from './editorStyles.css';
import buttonStyles from './buttonStyles.css';
import toolbarStyles from './toolbarStyles.css';
import blockTypeSelectStyles from './blockTypeSelectStyles.css';

const sideToolbarPlugin = createSideToolbarPlugin({
  theme: { buttonStyles, toolbarStyles, blockTypeSelectStyles }
});
const { SideToolbar } = sideToolbarPlugin;
const focusPlugin = createFocusPlugin();
const resizeablePlugin = createResizeablePlugin();
const blockDndPlugin = createBlockDndPlugin();
const alignmentPlugin = createAlignmentPlugin();
const { AlignmentTool } = alignmentPlugin;

const decorator = composeDecorators(
  resizeablePlugin.decorator,
  alignmentPlugin.decorator,
  focusPlugin.decorator,
  blockDndPlugin.decorator
);
const imagePlugin = createImagePlugin({ decorator });

const dragNDropFileUploadPlugin = createDragNDropUploadPlugin({
  handleUpload: () => {
    console.log(arguments)
  },
  addImage: (editorState, src) => {
    console.log(src);
    return imagePlugin.addImage(editorState, src);
  }
});

const plugins = [
  dragNDropFileUploadPlugin,
  blockDndPlugin,
  focusPlugin,
  alignmentPlugin,
  resizeablePlugin,
  imagePlugin,
  sideToolbarPlugin
];

class DndEditor extends React.Component {
  constructor() {
    super();
    this.state = {editorState: EditorState.createEmpty()};
  }
  componentDidMount() {
    this.editor.focus()
  }
  onChange = (editorState) => {
    this.setState({
      editorState,
    });
  }
  focus = () => {
    this.editor.focus();
  }
  render() {
    return (
      <div className={editorStyles.editor} onClick={this.focus}>
        <Editor
          editorState={this.state.editorState}
          onChange={this.onChange}
          plugins={plugins}
          ref={(element) => { this.editor = element; }}
        />
        <AlignmentTool />
        <SideToolbar />
      </div>
    );
  }
}

export default DndEditor;

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
sofianeOuafircommented, Nov 9, 2018

any update on this?

1reaction
dinubscommented, Apr 19, 2018

Thanks! It’s mentioned in the Alignment + Resize + Focus + Drag'n'Drop + Drag'n'Drop Upload Example section for the Image plugin on the website which is originally why I thought it worked.

https://www.draft-js-plugins.com/plugin/image

Read more comments on GitHub >

github_iconTop Results From Across the Web

draft-js-dragndrop-upload-plugin - npm
Dropping & uploading files with DraftJS. Latest version: 2.0.3, last published: 3 years ago. Start using draft-js-dragndrop-upload-plugin in ...
Read more >
DraftJS — Insert/Paste images into your content. | by Dave Teu
DraftJS is a text editor by the Facebook team that allows you to create ... URL of the uploaded file so insertImage can...
Read more >
Live coding – Draft.js copy-paste fix - YouTube
I go through the development of a bug fix for a well known Draft. js issue: copy-paste between editors not preserving all formatting...
Read more >
Editor Component - Draft.js
This article discusses the API and props of the core controlled contentEditable.
Read more >
How To Make A Drag-and-Drop File Uploader With Vue.js 3
Now that we have the project set up, let's dive into the code. We'll start with a component that handles the drag-and-drop functionality....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found