-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add architecture for granual pasteAsPlainText support #68
Conversation
Looks good! 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's some fragility to storing state on DOM nodes. Did you consider a weak map of element to value?
Indeed, I considered having a weak map inside the That being said, I am happy to update to this if you believe this is a stronger approach 👍 |
can you explain the difference between |
The difference is that, even in the event of |
I also just pushed a commit here cd58a52 to use a |
@anleac – so this would allow for a config that does not apply other formatting like images, tables, bold etc. but DOES linkify still? Another way to do that is just to subscribe to a subset of the functionality. - const unsubscribe = subscribe(el)
+ installLink() |
Yes that was the current motive - it would be similar to the toggle switch Edge has here (it is not the same, but similar) in being able to toggle rich HTML or plain text by default |
My proposal, which I updated in 2661306, we can make the config name very specific ( |
shouldPastePlainText
pasteLinkAsPlainTextOverSelectedText
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like where you've landed on this. It has room to scale to other formatters if needed. Note.
I do have the one API question – I think it's worth keeping the signature of all install
functions parallel.
I would also like to see some docs added to the readme about this.
} | ||
|
||
interface PlainTextParams { | ||
urlLinks?: boolean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great!
installCallbacks: Array<(el: HTMLElement) => void>, | ||
installCallbacksWithOptions: Array<(el: HTMLElement, optionConfig?: OptionConfig) => void>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather than have two arrays here, why not just pass options to all the callbacks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was hoping to avoid confusion given we export the individual installation functions, too, but the documentation update would be sufficient. Let me tackle this now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👋 my concern with sharing the installation signature across all the functions is that only one actually can be influenced by the config, while the rest wouldn't be, and we export all of these installations which possibly could be misleading. I guess we can circumvent this via the docs and marking this as not yet implemented? |
yeah ... that was my thought. The actual type signature for the I guess the other option would be to have the install commands implement either an |
pasteLinkAsPlainTextOverSelectedText
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looks great! Thank you for being patient and working through the multiple rounds of feedback. I think the extra work should pay off in keeping this API healthy.
Only the `urlLinks` param is currently supported. | ||
|
||
If there is no config passed in, or attributes missing, this will always default to `false`, being the existing behavior. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you this is great 👏
Motive
We wish to be able to have granual control over specifically the behaviour of whether to linkify when pasting a link over selected text. This pull request extends the current code base to support granual config support on the installation of the package, at this time, it only adds one control being for the
paste-markdown-link
(urlLinks in our API params).This config, which is default set to false (undefined | false), is the existing behaviour and therefore not a breaking change.
The approach would therefore add the following "new" behaviour, given the pasteLinkAsPlainTextOverSelectedText flag for
paste-markdown-link
, and depending on whether the skipFormattingFlag is on/off:As we add future support, we should extend this down to the future classes + add tests, I do not believe it would be much extra work but let's do it as a follow up or as a per-need basis.
Drawbacks
End-users may see this optional config as misleading, as we are passing in the options params to all base paste classes but only have it supported in one currently, but the documentation will reflect this.