udecode / plate

A rich-text editor powered by AI
https://platejs.org
Other
11.73k stars 713 forks source link

[deserialize-html] Pasting Image from clipboard into empty paragraph creates node image without url #926

Closed PibeG closed 3 years ago

PibeG commented 3 years ago

Description

After copying an image (eg. from wikimedia) and pasting it into an empty paragraph, an 'image' node without the "url" property is created.

Steps

  1. Copy an image (eg. https://commons.wikimedia.org/wiki/Main_Page).
  2. Go to https://platejs.org
  3. paste the image on a paragraph without text.

Sandbox

https://codesandbox.io/s/plate-reproduction-image-deserializing-o2g4m

Expectation

If you paste the same image in any other paragraph, the editor splits the content and creates the 'image' node correctly.

Environment

Funding

Fund with Polar

siliconeidolon commented 3 years ago

This behaviour is also seen when copy-pasting slate (ast) images within the editor, so I imagine it's not specifically related to the HTML deserialization, but more likely one of the insertion helper functions: https://codesandbox.io/s/plate-reproduction-image-ast-deserializing-7cler?file=/index.tsx Try copying the image and pasting it into an empty paragraph.

dylans commented 3 years ago

This should be fixed on Slate 0.66 gets released, namely with https://github.com/ianstormtaylor/slate/pull/4489 and then after we land https://github.com/udecode/plate/pull/995 and release. So probably sometime next week this should work.

In the interim, you could add a custom preInsert method that does not attempt to rewrite the first node type.

siliconeidolon commented 3 years ago

Ah great, thanks for the update.

PibeG commented 3 years ago

Thanks @dylans, I'll close this since #995 is just waiting review