Async check on every link mark

Hey folks!!

I need to do an async check when a link mark is added to the editor.

what would be the way to keep track of all the links that were added to the editor?

Things I need to do in this async check:

  • check if the link match a certain pattern
  • do a special call to the href link (async)
  • if none of those pass, then leave the link as it is and remove the link from the state set

I was thinking on having a plugin state that keeps a set for each link and its position (mark position), the issue I have is that I don’t know how to update this set when the link park position change or is deleted (is important if a change to the mark happens when the async query is on the fly).

which data structure should I use in this plugin state to keep track of every link and remove it when the check finishes?

thanks in advance!

it would be very helpful in there’s a simple example of such a plugin. I saw the image upload plugin example from the documentation. that’s using a DecorationSet to store the image while is being uploaded. not sure if that’s what I can use for the link marks too?

I think that I’m hearing that the challenge is trying to track where the link is after some Async operation. I would like more context of the problem and goal to feel more confident in an answer but the first things that come to mind are to use the link href as a key, and when resolved, decorate / expand the link inline. Maybe on paste of content giving each link a randomly generated key synchronously would be even more stable. Use that key in the editorstate that the plugin owns (like a “cached enrichment data” spot on the document) when that transaction is made for adding that state data, maybe it’s important to try to associate it with the original step from inserting the link, I’m not sure.

An in-line decoration could be used to project that additional data on mouse hover, I think.

I don’t think my advice here is complete in how I’d go about this, but these are the first ideas that come to mind without a clearer picture of what the goal/feature is.

1 Like