Coder Social home page Coder Social logo

kommitters / editorjs-drag-drop Goto Github PK

View Code? Open in Web Editor NEW
169.0 7.0 22.0 488 KB

Drag and Drop feature for Editor.js

Home Page: https://www.npmjs.com/package/editorjs-drag-drop

License: MIT License

JavaScript 94.89% CSS 5.11%
editorjs editorjs-plugin javascript drag-and-drop hacktoberfest

editorjs-drag-drop's Introduction

EditorJS Drag/Drop Plugin

Stability Badge Coverage Status OpenSSF Best Practices OpenSSF Scorecard

Drag/Drop feature for Editor.js.

Installation

Install via NPM

Get the package

$ npm i --save-dev editorjs-drag-drop

Include module at your application

import DragDrop from 'editorjs-drag-drop';

Load from CDN

You can load a specific version of the package from jsDelivr CDN.

Require this script on a page with Editor.js.

<script src="https://cdn.jsdelivr.net/npm/editorjs-drag-drop"></script>

Usage

const editor = new EditorJS({
  onReady: () => {
    new DragDrop(editor);
  },
});

Select the block, drag the toolbar settings button, and drop it at the desired position.

You can optionally provide a second parameter to customize the indicator border style. If no parameter is provided, the default border style 1px dashed #aaa is used.

If you're already using editorjs-undo, then your code will look somewhat like this:

const editor = new EditorJS({
  onReady: () => {
    new Undo({ editor });
    new DragDrop(editor);
  },
});

Usage with React.

If you are using React, you could create a function to handle the onReady property, the function will store the DragDrop instance. Then, you must call the function in onReady in the editorJS instance.

const handleReady = (editor) => {
  new DragDrop(editor);
};

class ReactEditor extends Component {
  render() {
    return (
      <EditorJs
        onReady = { handleReady }
        tools = { ... }
      />
    )
  }
}

Note: If you are already using editorjs-undo your handleReady function must have the editorjs-undo instance.

const handleReady = (editor) => {
  new Undo({ editor });
  new DragDrop(editor);
};

Usage with react-editor-js.

If you are using react-editor-js, you should use the 'onInitialize' prop in the ReactEditorJS component to obtain the abstract editorjs as follow:

........
export const ReactEditor = () => {
  const editorCore = React.useRef(null)

  const handleInitialize = React.useCallback((instance) => {
    editorCore.current = instance
  }, [])

  const handleReady = () => {
    const editor = editorCore.current._editorJS;
    new Undo({ editor })
    new DragDrop(editor);
  };

  const ReactEditorJS = createReactEditorJS()
  return(
  <ReactEditorJS
    onInitialize={handleInitialize}
    onReady = {handleReady}
    tools={....}
    defaultValue={....}
  />
  )
}

Development

Development mode

$ yarn build:dev

Production release

  1. Create a production bundle
$ yarn build
  1. Commit dist/bundle.js

Run tests

$ yarn test

Code of conduct

We welcome everyone to contribute. Make sure you have read the CODE_OF_CONDUCT before.

Contributing

For information on how to contribute, please refer to our CONTRIBUTING guide.

Changelog

Features and bug fixes are listed in the CHANGELOG file.

License

This library is licensed under an MIT license. See LICENSE for details.

Acknowledgements

Made with 💙 by kommitters Open Source

editorjs-drag-drop's People

Contributors

boterop avatar brc-dd avatar chenguzhen87 avatar cristhianrodriguezmolina avatar dependabot[bot] avatar felipeguzmansierra avatar jhonatan-kmt avatar juanhurtado10 avatar juliandsg0222 avatar karolrojas07 avatar mariorodriguezs avatar marthox avatar miguelnietoa avatar nicolasgaviria avatar renovate[bot] avatar step-security-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

editorjs-drag-drop's Issues

Header drag and drop leaves a blank header block.

When I highlight the whole header block and drag and drop it elsewhere it leaves a blank header block in the old position,
Here is a demo:

Test 1:
editor-1

Test 2:
editor-2

I thought it is my mistake but I tried it in some other opensource projects which use editorjs and this plugin and it behaves the same..

Documentation to use it along with editorjs-undo

Hey! Is there any documentation with instructions to use this module along with editorjs-undo? I think simply adding this will work fine:

const editor = new EditorJS({
  onReady: () => {
    new DragDrop(editor);
    new Undo({ editor });
  },
});

Documentation is incomplete. Missing documentation for holder

Precheck

  • Do a quick search and make sure the bug has not been reported yet.
  • Please disclose security vulnerabilities privately at [email protected].
  • Finally, be nice and have fun!.

Description

I have added DragDrop initialization to onReady callback but am receiving

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'holder')

Looking at the DragDrop constructor I can see that it expects a holder param to be passed during initialization but this is not documented

Dragging the only block in the editor above itself causes EditorJS to be broken

Precheck

  • Do a quick search and make sure the bug has not been reported yet.
  • Please disclose security vulnerabilities privately at [email protected].
  • Finally, be nice and have fun!.

Description

When there is only one block in the editor you can drag a block above itself. Doing this will break the editor. It seems it you move the block out of an array, but I'm not sure.

Screenshot 2021-12-06 at 13 34 53

Environment

  • Editor.js version: 2.19.3
  • Plugins you use with their versions:
    • @editorjs/header: 2.6.2
    • editorjs-drag-drop: 1.0.0
  • Device, Browser, OS: Chrome 96.0.4664.55 (Official Build) (arm64), macOS Version 12.0.1 (Build 21A559)

Current behavior (steps to reproduce)

  • Create a new EditorJs instance and add the drag-and-drop plugin as described in the readme (without undo plugin)
  • Create a paragraph block
  • Drag the block until you see and indicator appear above the block and drop it
  • The editor is now broken.

Expected behavior

You shouldn't be able to move a block when there is only one present.

Additional context

When there is more than one block in the editor the drag-and-drop works as expected.

Drag and Drop removes last character every time it's used

Precheck

  • Do a quick search and make sure the bug has not been reported yet.
  • Please disclose security vulnerabilities privately at [email protected].
  • Finally, be nice and have fun!.

Description

If I Drag and Drop all the time then the behavior removes the last characters of the headline.

Environment

  • Editor.js version: 2.24.2
  • Plugins you use with their versions:
  • Device, Browser, OS: Moneterey 12.3 - Safari - Version 15.4 (17613.1.17.1.6)

Current behavior

See video

Expected behavior

A clear and concise description of what you expected to happen.

Additional context

Screen.Recording.2022-05-02.at.09.37.30.mov

CTRL+Z does not behave as expected.

When a part of the text is dragged to another position and CTRL+Z is pressed it makes a duplication.

Here is a demo:
N4Cd4aCJQN

I installed the editorjs-undo plugin but it behaves the same.

Issue with drop visual indicators

Hi

First of all, congrats for this addon!

Using the latest version from CDN of both Editor and this plugin but the arrow is not centered. I have to put the CSS from index.css directly on my page to get it centered. Here's what happens:

image

Also, what is the correct way of changing the style of that dashed line without messing with the plugin code? Can it be done using CSS?

Thank you!

Drag and Drop removes last character every time it's used (improvement)

Precheck

  • Do a quick search and make sure the bug has not been reported yet.
  • Please disclose security vulnerabilities privately at [email protected].
  • Finally, be nice and have fun!.

Description

There was implemented a solution for a bug in the drag and drop plugin that makes everytime you drag, having your cursor in any part of the text, it deletes the letter just after it. But it has some problems because it clones the original holder changing the parent hierarchy of the holders, so giving it another try could be a good idea because it can solve some related bugs.

Environment

  • Editor.js version: 2.24.2
  • Plugins you use with their versions:
  • Device, Browser, OS: Windows 11, Chrome

Current behavior

everytime you drag, having your cursor in any part of the text, it deletes the letter just after it.

Expected behavior

everytime you drag, having your cursor in any part of the text, it DOES NOT deletes the letter just after it.

Additional context

Add any other context about the problem here.

Dropping images or videos into the editor incorrectly causes reordering of blocks

Precheck

  • Do a quick search and make sure the bug has not been reported yet.
  • Please disclose security vulnerabilities privately at [email protected].
  • Finally, be nice and have fun!.

Description

The "drop" listener does not take into consideration the dropping of new images or videos into the editor. This drop event creates a new block in the editor and triggers the event listener from this plugin which incorrectly calls moveBlocks

Environment

  • Editor.js version: 2.25.0
  • Plugins you use with their versions:
    "editorjs-drag-drop": "1.1.4"
    "editorjs-strikethrough": "1.0.0"
    "editorjs-text-alignment-blocktune": "1.0.3"
    "editorjs-text-color-plugin": "1.12.1"
    "editorjs-undo": "1.0.1"
    
  • Device, Browser, OS: macOS 12.4, Chrome version 104.0.5112.79

Current behavior

Drop event listener is triggered when an image is dropped into the editor and calls the moveBlocks function. However the startBlock value is not correctly set because this drop event is not following a drag start event which would have set the startBlock value because this drop was from a drag outside of the editor

Expected behavior

Dropping in an image or video should not reorder the other elements in the editor

Additional context

Video of the described behaviour

issue.mov

Security Policy violation SECURITY.md

This issue was automatically created by Allstar.

Security Policy Violation
Security policy not enabled.
A SECURITY.md file can give users information about what constitutes a vulnerability and how to report one securely so that information about a bug is not publicly visible. Examples of secure reporting methods include using an issue tracker with private issue support, or encrypted email with a published key.

To fix this, add a SECURITY.md file that explains how to handle vulnerabilities found in your repository. Go to https://github.com/kommitters/editorjs-drag-drop/security/policy to enable.

For more information, see https://docs.github.com/en/code-security/getting-started/adding-a-security-policy-to-your-repository.


This issue will auto resolve when the policy is in compliance.

Issue created by Allstar. See https://github.com/ossf/allstar/ for more information. For questions specific to the repository, please contact the owner or maintainer.

Having issues with React Editor Js

Description

I am getting this error. Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'configuration')
Code works if I remove the OnReady. Where do i get the EditorJS. using React Editor JS uses createReactEditorJS()

Environment

"@editorjs/attaches": "^1.2.1",
"@editorjs/checklist": "^1.3.0",
"@editorjs/code": "^2.7.0",
"@editorjs/delimiter": "^1.2.0",
"@editorjs/editorjs": "^2.22.2",
"@editorjs/embed": "^2.5.0",
"@editorjs/header": "^2.6.2",
"@editorjs/image": "^2.6.2",
"@editorjs/inline-code": "^1.3.1",
"@editorjs/link": "^2.4.0",
"@editorjs/list": "^1.6.2",
"@editorjs/marker": "^1.2.2",
"@editorjs/paragraph": "^2.8.0",
"@editorjs/quote": "^2.4.0",
"@editorjs/raw": "^2.3.0",
"@editorjs/simple-image": "^1.4.1",
"@editorjs/table": "^2.0.1",
"@editorjs/warning": "^1.2.0",
"editorjs-button": "^1.0.4",
"editorjs-drag-drop": "^1.0.1",
"editorjs-style": "^3.0.2",
"editorjs-undo": "^1.0.1",

Current behavior

import React, {useState} from 'react';
import { createReactEditorJS } from 'react-editor-js'
import { EDITOR_JS_TOOLS } from '@/Shared/EditorTools'

import DragDrop from 'editorjs-drag-drop'
import Undo from 'editorjs-undo'

const handleReady = (editor) => {
    new Undo({ editor })
    new DragDrop(editor);
  };

const OnboardingEditor = () => {
const ReactEditorJS = createReactEditorJS()
return(
<ReactEditorJS 
                                            onReady = { handleReady }
                                            tools={EDITOR_JS_TOOLS} 
                                            defaultValue={{
                                                time: 1635603431943,
                                                blocks: [
                                                  {
                                                    id: "sheNwCUP5A",
                                                    type: "header",
                                                    data: {
                                                      text: "Editor.js",
                                                      level: 2
                                                    }
                                                  },
                                                  {
                                                    id: "12iM3lqzcm",
                                                    type: "paragraph",
                                                    data: {
                                                      text:
                                                        "Hey. Meet the new Editor. On this page you can see it in action — try to edit this text."
                                                    }
                                                  },
                                                  {
                                                    id: "fvZGuFXHmK",
                                                    type: "header",
                                                    data: {
                                                      text: "Key features",
                                                      level: 3
                                                    }
                                                  },
                                                  {
                                                    id: "xnPuiC9Z8M",
                                                    type: "list",
                                                    data: {
                                                      style: "unordered",
                                                      items: [
                                                        "It is a block-styled editor",
                                                        "It returns clean data output in JSON",
                                                        "Designed to be extendable and pluggable with a simple API"
                                                      ]
                                                    }
                                                  },
                                                  {
                                                    id: "-MhwnSs3Dw",
                                                    type: "header",
                                                    data: {
                                                      text: "What does it mean «block-styled editor»",
                                                      level: 3
                                                    }
                                                  },
                                                  {
                                                    id: "Ptb9oEioJn",
                                                    type: "paragraph",
                                                    data: {
                                                      text:
                                                        'Workspace in classic editors is made of a single contenteditable element, used to create different HTML markups. Editor.js <mark class="cdx-marker">workspace consists of separate Blocks: paragraphs, headings, images, lists, quotes, etc</mark>. Each of them is an independent contenteditable element (or more complex structure) provided by Plugin and united by Editor\'s Core.'
                                                    }
                                                  },
                                                  {
                                                    id: "-J7nt-Ksnw",
                                                    type: "paragraph",
                                                    data: {
                                                      text:
                                                        'There are dozens of <a href="https://github.com/editor-js">ready-to-use Blocks</a> and the <a href="https://editorjs.io/creating-a-block-tool">simple API</a> for creation any Block you need. For example, you can implement Blocks for Tweets, Instagram posts, surveys and polls, CTA-buttons and even games.'
                                                    }
                                                  },
                                                  {
                                                    id: "SzwhuyoFq6",
                                                    type: "header",
                                                    data: {
                                                      text: "What does it mean clean data output",
                                                      level: 3
                                                    }
                                                  },
                                                  {
                                                    id: "x_p-xddPzV",
                                                    type: "paragraph",
                                                    data: {
                                                      text:
                                                        "Classic WYSIWYG-editors produce raw HTML-markup with both content data and content appearance. On the contrary, Editor.js outputs JSON object with data of each Block. You can see an example below"
                                                    }
                                                  },
                                                  {
                                                    id: "6W5e6lkub-",
                                                    type: "paragraph",
                                                    data: {
                                                      text:
                                                        'Given data can be used as you want: render with HTML for <code class="inline-code">Web clients</code>, render natively for <code class="inline-code">mobile apps</code>, create markup for <code class="inline-code">Facebook Instant Articles</code> or <code class="inline-code">Google AMP</code>, generate an <code class="inline-code">audio version</code> and so on.'
                                                    }
                                                  },
                                                  {
                                                    id: "eD2kuEfvgm",
                                                    type: "paragraph",
                                                    data: {
                                                      text:
                                                        "Clean data is useful to sanitize, validate and process on the backend."
                                                    }
                                                  },
                                                  {
                                                    id: "N8bOHTfUCN",
                                                    type: "delimiter",
                                                    data: {}
                                                  },
                                                  {
                                                    id: "IpKh1dMyC6",
                                                    type: "paragraph",
                                                    data: {
                                                      text:
                                                        "We have been working on this project more than three years. Several large media projects help us to test and debug the Editor, to make it's core more stable. At the same time we significantly improved the API. Now, it can be used to create any plugin for any task. Hope you enjoy. 😏"
                                                    }
                                                  },
                                                  {
                                                    id: "FF1iyF3VwN",
                                                    type: "image",
                                                    data: {
                                                      file: {
                                                        url: "https://codex.so/public/app/img/external/codex2x.png"
                                                      },
                                                      caption: "",
                                                      withBorder: false,
                                                      stretched: false,
                                                      withBackground: false
                                                    }
                                                  }
                                                ]
                                            }}
                                        />
)
}

Drag-drop position / indication / style

Hey guys, thanks a lot for your plugin, it's awesome!

Just wanted to know if you have (or are considering to add) any way to indicate where I am about to put the new block (like a line showing where it would be placed if moved - a line on the bottom if it will be placed below the other block, or viceversa). Because I noticed that currently, when dragging a block it is not clear if it will be positioned on the top or the bottom of the other block.

Thanks again!

Add read-only mode support

Recent EditorJS version has included a property readOnly. Ref.

The suggested approach in README (creating new instance of class inside onReady) throws an exception (Unhandled Rejection (TypeError): Cannot read property 'setAttribute' of null), when used with readOnly: true.

It is possible to determine if readOnly is being passed to the editor internally?

The current workaround is simple: just add the object instantiation inside something like a if (!readOnly) block. But it will be nice if DragDrop can implicitly handle this.

handle button is 200 px above the cursor

Hi,
Thanks a lot for your plugin !

I have an issue with the handle button (four squares) when i drag a block. when I click on the button he appear 200px above the cursor.
handle

editorjs-drag-drop : 0.1.1
@editorjs/editorjs : 2.19.1

good night !

Toolbar stays open, since EditorJS 2.23+

Precheck

  • Do a quick search and make sure the bug has not been reported yet.
  • Please disclose security vulnerabilities privately at [email protected].
  • Finally, be nice and have fun!.

Description

EditorJS toolbar stays open. I guess this is due to the latest 2.23. changes:

  • Improvement — UI — Block Actions (BT toggler + Plus Button) will appear on block hovering instead of click

Environment

  • Editor.js version: 2.23.2
  • Plugins you use with their versions:
  • Device, Browser, OS: Moneterey 12.3 - Safari - Version 15.4 (17613.1.17.1.6)

Current behavior

On Drag event: The toolbar opens
On Drop event: The toolbar stays open

Expected behavior

Toolbar should not open on drag and on drop events.

Additional context

  • It's not happening on 2.22.x

During multiple drag and drop processes, part of the text will be lost

Precheck

  • Do a quick search and make sure the bug has not been reported yet.
  • Please disclose security vulnerabilities privately at [email protected].
  • Finally, be nice and have fun!.

Description

A clear and concise description of what the bug is.

Environment

  • Editor.js version:
  • Plugins you use with their versions:
  • Device, Browser, OS:

Current behavior

Include code samples, errors and stack traces if appropriate.
If reporting a bug, please include the reproducing steps.

Expected behavior

A clear and concise description of what you expected to happen.

Additional context

Add any other context about the problem here.

Drag event never fired

Precheck

  • Do a quick search and make sure the bug has not been reported yet.
  • Please disclose security vulnerabilities privately at [email protected].
  • Finally, be nice and have fun!.

Description

The drag event is never triggered so the feature does not work.
I've put a console.log('dragstart') on the listener dragstart and when I'm starting to drag by clicking on the menu Icon, I see the dragstart in the console.
But I did the same on the listener drag and I never see the output in the console.

I dig everywhere to find the origin of my issue but did not found a clue, it's like my react app has a conflict with the drag event...?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.