Skip to content

Allowing changing currentLexicalNode in HTML Paste Post-Processor Signature#1160

Merged
acywatson merged 7 commits intomainfrom
post-transform-2
Jan 31, 2022
Merged

Allowing changing currentLexicalNode in HTML Paste Post-Processor Signature#1160
acywatson merged 7 commits intomainfrom
post-transform-2

Conversation

@acywatson
Copy link
Copy Markdown
Contributor

This changes the the "after" function to accept and return the currentLexicalNode, allowing the user to reference it or mutate it in the post-processing step, as @fantactuka suggested here:

#1153 (comment)

Now that I've written this, I'm not actually sure that we need it. I was having trouble thinking of a use case, since the transformer function itself already allows us to set the currentLexicalNode to be whatever we want. Open to comments/suggestions.

@vercel
Copy link
Copy Markdown

vercel bot commented Jan 22, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/fbopensource/lexical/88xoJUbufXoP3sgA1XWxbc5Rom1F
✅ Preview: https://lexical-git-post-transform-2-fbopensource.vercel.app

@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 Jan 22, 2022
@fantactuka
Copy link
Copy Markdown
Collaborator

fantactuka commented Jan 22, 2022

Yeah, it seems like current API can solve all cases we've discussed. In the worst case you can always manipulate raw dom node and update it before it's converted into lexical node. I'd say this PR still has valuable change - to pass childLexicalNodes instead of all lexicalNodes (which might include non-child nodes). As you've mentioned even currentLexicalNode is not needed as after argument, as conversion fn has access to it from closure. So it can remain as simple as(lexicalChildren: Array<LexicalNode>) => Array<LexicalNode>.

@trueadm
Copy link
Copy Markdown
Collaborator

trueadm commented Jan 23, 2022

Please can I request you get together and do a tech talk on this logic please? I’d love to understand it all fully.

@acywatson
Copy link
Copy Markdown
Contributor Author

acywatson commented Jan 23, 2022

Please can I request you get together and do a tech talk on this logic please? I’d love to understand it all fully.

Definitely - I was planning to do this since others were also interested. Will set something up for next week.

@acywatson
Copy link
Copy Markdown
Contributor Author

Yeah, it seems like current API can solve all cases we've discussed. In the worst case you can always manipulate raw dom node and update it before it's converted into lexical node. I'd say this PR still has valuable change - to pass childLexicalNodes instead of all lexicalNodes (which might include non-child nodes). As you've mentioned even currentLexicalNode is not needed as after argument, as conversion fn has access to it from closure. So it can remain as simple as(lexicalChildren: Array) => Array.

I was thinking about this more - the argument currentLexicalNode is the domNode after it has been transformed to Lexical, This isn't available in the outer function scope, but might be useful if you wanted to make some changes to the children based on the nature of the parent LexicalNode. For instance, in the case of Lists, maybe we want to check that all immediate children are ListItemNodes if their parent is a ListNode.

@fantactuka
Copy link
Copy Markdown
Collaborator

You should be able to access it, or is it wrong example?

  ul: (domNode: Node) => {
    const listNode = $createListNode();

    return {
      node: listNode,  // <-- used to set currentLexicalNode value
      after: (childLexicalNodes) => {
        ... check "listNode" if needed ...
        return childLexicalNodes;
      },
    };
  },
	

@acywatson
Copy link
Copy Markdown
Contributor Author

You should be able to access it, or is it wrong example?

  ul: (domNode: Node) => {
    const listNode = $createListNode();

    return {
      node: listNode,  // <-- used to set currentLexicalNode value
      after: (childLexicalNodes) => {
        ... check "listNode" if needed ...
        return childLexicalNodes;
      },
    };
  },
	

Lol no, you're exactly right - I don't know what I was thinking.

@acywatson acywatson merged commit f31f826 into main Jan 31, 2022
@trueadm trueadm deleted the post-transform-2 branch April 6, 2022 15:22
acywatson added a commit that referenced this pull request Apr 9, 2022
…nature (#1160)

* wip

* wip

* add postTransform to HTML paste logic

* Add code pasting support (#1159)

* Add code detecting and e2e tests

* Add quip paste

* Add github table-based code pasting

* Change post-transform API to accomodate changing the currentLexicalNode

* simplify function signature in HTMl paste post-processor

* rebase fixes

Co-authored-by: Maksim Horbachevsky <fantactuka@gmail.com>
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.

4 participants