-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
feat: Vue components, mount options, global options, and v3 support #1409
Conversation
- Add detection of Vue HTML directives to trigger mounting - Fix bug that processed markdown child nodes as global Vue instances even if vueGlobalOptions is not specified - Fix bug that prevented passing vueGlobalOptions to global instances if `data()` prop did not exist - Update Vue config check to test for existence of object keys instead of just the existence object - Update tests
docs/vue.md
Outdated
1. Process unmounted Vue content using `vueGlobalOptions` | ||
- Docsify will not mount an existing Vue instance or an element that contains an existing Vue instance. | ||
- Docsify will automatically destroy/unmount all Vue instances it creates before new page content is loaded. | ||
- When processing `vueGlobalOptions`, docsify parses the child elements within the main content area (`#main`) and mounts the element if it contains Vue content. Docsify does not parse each individual node within the main content area. |
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'm not clear on the last bullet point. I guess if it'll start to explain this magic part, it might just need to go into more detail.
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.
Yes, I agree this description could use some work. To be honest, I debated about even adding it. I've updated the description to (hopefully) make it more clear. At the end of the day, this text exists to help explain why this edge case won't work:
window.$docsify = {
vueGlobalOptions: {
data() {
return {
globalMsg: 'Hello from vueGlobalOptions!',
};
},
},
vueMounts: {
'#test': {
data() {
return {
mountMsg: 'Hello from vueMounts!'
};
},
},
},
};
Example 1: This will work
<!-- Source -->
<p>{{ globalMsg }}</p>
<p id="test">{{ mountMsg }}</p>
<!-- Output -->
<p>Hello from vueGlobalOptions!</p>
<p id="test">Hello from vueMounts!</p>
In this example, docsify first mounts the top-level <p id="test">
from vueMounts
. Docsify then iterates over the top-level child elements (<p>
), skips the ones that contain or are themselves Vue instances, detects Vue template syntax in the top-level <p>
element, and mounts it using vueGlobalOptions
. Great.
Example 2: This will not work
<!-- Source -->
<div>
<p>{{ globalMsg }}</p>
<p id="test">{{ mountMsg }}</p>
</div>
<!-- Output -->
<div>
<p>{{ globalMsg }}</p>
<p id="test">Hello from vueMounts!</p>
</div>
Like the previous example, docsify first mounts the top-level <p id="test">
from vueMounts
. Docsify then iterates over the top-level child elements (<div>
), detects that <div>
contains a Vue instance (<p id="test">
) and skips that element. This behavior is explained in the following "Technical Notes" bullet point:
- Docsify will not mount an existing Vue instance or an element that contains an existing Vue instance.
I think it is highly unlikely that this will be an issue, but I added the related technical notes in hopes of making life easier for everyone if it does. The trick is how to do this succinctly without going into the same level of detail above. Hopefully the changes I've put in place are good enough for now. We can always revisit if/when needed.
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.
@jhildenbiddle The example of what works vs what doesn't will be very helpful to some people. I think it'd be worth pasting what you wrote into the docs.
-moz-osx-font-smoothing initial | ||
-webkit-font-smoothing initial | ||
|
||
.markdown-section code |
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.
Are these style changes potentially breaking (website will look different when v4 user updates)?
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.
Oh never mind, looks like only refactoring.
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.
Non-breaking change because styles did not exist previously.
Thanks to your contribution. the vue content in documentation now looks great 👍🏻 |
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.
LGTM.
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.
damnnnn good. 👍
Fix #752 #1252
Summary
This PR significantly improves Vue functionality in docsify and addresses a few bugs/issues with the test environment.
Note that the preview site auto-generated for this PR is not built with the correct
index.html
so it will not process Vue content as expected. To preview locally, check out the branch/PR and run the following:Public Changes
vueComponents
configuration optionvueMounts
configuration optionvueGlobalOptions
configuration option<output>
element tovue.css
/docs/
siteDev Changes
There was a significant test-related bug fixed in this PR. Due to the way Jest manages the JSDOM environment, global objects like the
window
anddocument
objects are not reset after each test in the same file. As a result, event listeners added to thewindow
object by docsify were not being cleared after each test, resulting in event listeners from previous previous tests continuing to be triggered.docsify-init()
for functions inconfig
Add.markdownlint.json
_logHTML.selector
option todocsify-init()
--runInBand
flag from local Jest tests/test/config/jest.setup-tests.js
waitForSelector()
timeout in/test/helpers/wait-for.js
docsify-init()
handling ofconfig.basePath
optionWhat kind of change does this PR introduce? (check at least one)
If changing the UI of default theme, please provide the before/after screenshot:
Screenshot of new
<output>
styling (below code block):Does this PR introduce a breaking change? (check one)
If yes, please describe the impact and migration path for existing applications:
The PR fulfills these requirements:
fix #xxx[,#xxx]
, where "xxx" is the issue number)You have tested in the following browsers: (Providing a detailed version will be better.)
If adding a new feature, the PR's description includes: