-
Notifications
You must be signed in to change notification settings - Fork 66
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
Fix double MarkdownBlock
EasyMDE initialisation
#142
Conversation
@lb- would appreciate your input on this |
The new Stimulus controller makes this simpler
3c9a27b
to
9ced970
Compare
|
||
connect() { | ||
if (this.autodownloadValue != null) { | ||
if (this.hasAutodownloadValue) { |
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.
tl;dr - EasyMDE will try to detect if FA is present if initialized with a null value. Given static values = { autodownload: Boolean};
a missing value would be false, so we were initialising EasyMDE with "don't download FA"
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.
Sorry. Just reading this now.
The hasSomeValue
just checks if the value is declared in the DOM so I'm not sure this is what you want.
<textarea data-controller="easymde" ... (No html data attribute for the value )
// this.hasAutodownloadValue - will be false
<textarea data-controller="easymde" data-easymde-autodownload="false" ...
// this.hasAutodownloadValue - will be true
<textarea data-controller="easymde" data-easymde-autodownload="true" ...
// this.hasAutodownloadValue - will be true
I think the issue was the confusion of checking against null with a !=
as this will try to coerce the Boolean into a comparable value. As a general guide it's good to use strict inequality and try to align checks with the type set of the value.
Or keep the code simpler with returns or a non-comparison approach.
easymdeAttach(this.element.id, this.autodownloadValue);
this.autodownloadValue
will always return a Boolean, Stimulus does this for us, so why do any branch logic at all. The default will be false
if not set in the html.
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 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 for additional context, LB.
this.hasAutodownloadValue
is what I want because we only set the data attribute the setting is present, hence I only want to pass it down when the attribute is set.
https://github.com/Ionaru/easy-markdown-editor?tab=readme-ov-file#configuration
autoDownloadFontAwesome: If set to true, force downloads Font Awesome (used for icons). If set to false, prevents downloading. Defaults to undefined, which will intelligently check whether Font Awesome has already been included, then download accordingly.
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.
Ok. No problems.
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.
tested locally and it fixed the issue in #141
Fixes #141
@lb- suggested a conditional
in the
wagtailmarkdown/js/markdown-textarea-adapter.js
Telepath adapter, but that is really not needed with the new controller