Editor.js: Cut and Paste (CMD+X -> CMD+P) does not restore pasted custom block with it's data

Created on 22 Nov 2019  路  5Comments  路  Source: codex-team/editor.js

Issue

In our app we have lot's of "Enrichments". They can have several different types (eg. image, audio, ...). Because of legacy reasons we cannot simply render a <img> or <audio> tag.

Nevertheless, I was able to register and add custom tools (with React support) for each enrichment type. _BUT_ when one moves them with CMD+X and CMD+P they are added as a simple paragraph _or_ when the block is detected without data.

FTR:

  • I am not sure if the pasteConfig is correct, as I render a div with some other elements inside. Not sure what's the correct pattern/tag then.
  • Not sure how to make sure onPaste receives existing data from the pasted block as well.

Expected outcome

I can copy and paste existing blocks with all it's data within the Editor container.

Example

An example codesandbox can be found here: https://codesandbox.io/s/epic-feynman-myinj.

Screen Capture on 2019-11-22 at 11-33-20

Environment

  • React: "react": "16.11.0"
  • Editorjs: "@editorjs/editorjs": "2.15.1"
viewed

Most helpful comment

Awesome, so far I can confirm it works. Thank you @neSpecc.

All 5 comments

i am getting a number in the text object of theresult , if i copy and paste text it puts numbers as shown below :

{ "time" : 1574519623180, "blocks" : [ { "type" : "paragraph", "data" : { "text" : "2" } }, { "type" : "paragraph", "data" : { "text" : "2" } } ], "version" : "2.15.1" }

We can add special formatting to the copied text that will allow us to determine block types on pasting. But in this case, copying/pasting to the other regular text documents will contain unwanted extra symbols.

We will research this case and find a solution. Maybe this can be done by modifying the DataTransfer object by adding our own mime-type. Or we can provide options on how you want to copy selected fragment: as simple text or as Editorjs format.

Hi @neSpecc, thanks for the feedback. If I came up with an idea, I'll let you know.

Resolved by #1060
Released in 2.17.0

Awesome, so far I can confirm it works. Thank you @neSpecc.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

guillaumepn picture guillaumepn  路  4Comments

cossssmin picture cossssmin  路  3Comments

ar53n picture ar53n  路  3Comments

hata6502 picture hata6502  路  3Comments

talyguryn picture talyguryn  路  3Comments