Skip to content

Remove unstable JSON serialization functions + unify copy+paste to be HTML - #2241

Merged
trueadm merged 16 commits into
mainfrom
serialization-json
May 31, 2022
Merged

trueadm merged 16 commits into
mainfrom
serialization-json

Conversation

@trueadm

@trueadm trueadm commented May 23, 2022 •

Copy link
Copy Markdown
Collaborator

Note: This PR is a major breaking change, so we should version the next version 0.3 (I believe we planned to do this anway).

This PR does the following:

  • removes the unstable_ prefixed JSON import/export serialization functions, instead makes their functionality use the original toJSON and parseEditorState methods. The new editor state does NOT include selection.
  • Removes adding x-lexical-editor-state from clipboard, instead we only put on HTML and parse HTML accordingly.
  • Fixes a bunch of issues with HTML, including rogue empty line breaks + missing import/export HTML definitions.
  • Removes namespace from config, as no longer needed.
  • Updates Flow/TS types accordingly.
  • Adds some functional UTs
  • Adds some docs around the APIs

This PR should remove quite a lot of logic around parsing logic from the core.

@vercel

vercel Bot commented May 23, 2022 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
lexical ✅ Ready (Inspect) Visit Preview May 31, 2022 at 0:08AM (UTC)
lexical-playground ✅ Ready (Inspect) Visit Preview May 31, 2022 at 0:08AM (UTC)

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 23, 2022

@zurfyx zurfyx left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So ultimately we're saying that both HTML and JSON have the same fidelity. The only difference with JSON is that is can handle versions in a more structured manner..

Comment on lines -251 to -254
export function parseEditorState(
parsedEditorState: ParsedEditorState,
editor: LexicalEditor,
): EditorState {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Currently used in WWW (PoC @acywatson)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea I imagine this change will break all of the previously stored states.

@acywatson

Copy link
Copy Markdown
Contributor

So ultimately we're saying that both HTML and JSON have the same fidelity. The only difference with JSON is that is can handle versions in a more structured manner..

I’m not sure that it’s true that HTML has the same fidelity as JSON. Have we found a way to represent nested editors in HTML? The problem with less than perfect fidelity is that copying and pasting within the same editor (like moving sections of a document around) can result in data loss. I think the tolerance for this is higher between editors, but I would generally expect copying within the same editor to reproduce the pasted content almost perfectly.

@tylerjbainbridge

tylerjbainbridge commented May 23, 2022 •

Copy link
Copy Markdown
Contributor

So ultimately we're saying that both HTML and JSON have the same fidelity. The only difference with JSON is that is can handle versions in a more structured manner..

This isn't true right now, there's no reliable way to represent decorator nodes as HTML until we add support for a data-lexical-node-type attribute and find a way to store a decorator node's properties on an HTML element in order to import properly. Until then we won't know that some random <div> is actually an excalidraw node, for instance.

I'm hesitant to accept this PR because without x-lexical-editor-state there's no way to copy + paste decorator nodes around in the same document unless I'm missing something.

@trueadm

trueadm commented May 23, 2022

Copy link
Copy Markdown
Collaborator Author

I'm hesitant to accept this PR because without x-lexical-editor-state there's no way to copy + paste decorator nodes around in the same document unless I'm missing something.

I added logic to copy some of the decorators to this PR already. Check out ImageNode it also handles the nested caption too. :)

@tylerjbainbridge

tylerjbainbridge commented May 23, 2022 •

Copy link
Copy Markdown
Contributor

I'm hesitant to accept this PR because without x-lexical-editor-state there's no way to copy + paste decorator nodes around in the same document unless I'm missing something.

I added logic to copy some of the decorators to this PR already. Check out ImageNode it also handles the nested caption too. :)

Decorator Nodes that have semantic HTML equivalents (ImageNode, HorizontalRuleNode, etc) are easy enough to import/export to HTML but YoutubeEmbedNode, PollNode, ExcalidrawNode, etc, are more complicated to import and export losslessly until we have a robust Decorator<->HTML solution.

@trueadm

trueadm commented May 23, 2022

Copy link
Copy Markdown
Collaborator Author

Decorator Nodes that have semantic HTML equivalents (ImageNode, HorizontalRuleNode, etc) are easy enough to import/export to HTML but YoutubeEmbedNode, PollNode, ExcalidrawNode, etc, are more complicated to import and export losslessly until we have a robust Decorator<->HTML solution.

I did ExcalidrawNode and EquationNode. Need to do the others, but I used an attribute as signal.

@tylerjbainbridge

Copy link
Copy Markdown
Contributor

I did ExcalidrawNode and EquationNode. Need to do the others, but I used an attribute as signal.

Ahh, I see that now. I guess I was imagining something added to the core serialization logic to support Decorator Nodes by default so people don't have to add identifying data-attributes and serialized node properties themselves, but this is probably fine for now.

Comment thread packages/lexical-link/src/index.ts Resolved
Comment thread packages/lexical/Lexical.d.ts Resolved
Comment thread packages/lexical/src/LexicalEditor.js Resolved

This branch was successfully deployed

2 active deployments
Preview – lexical-playground — 8ad2e011 Deployed May 31, 2022 by vercel[bot]
Preview – lexical — 8ad2e011 Deployed May 31, 2022 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants