-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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!: rework the clicks system #1279
Conversation
Hey, thanks a lot for the initiative! Indeed I think the clicks system needed some improvements. Some feedback:
I am not very sure what
I like it!
Is this necessary? People could do that with
I am not sure if it's internal. IIRC, it was a PR to add that support. If there is no strong technical reason, I would keep it to avoid making breaking changes
Why not add
This is definitely a no to me. I use it a lot in my slides. No matter how perfect the clicks inference we might have, we still need to have an escape hatch for users to manually specify the clicks they want. In addition, it's possible to have dynamic conditions like: <div :class='$clicks > 5 ? 'some-class' : 'another-class'" /> |
@antfu Thank you for your support and affirmation.
It is. The previous auto-calculate clicks also consider the elements with specified About the meaning of
Yes, it is. because
I considered it again and I now think this is meaningful. I will implement this maybe tomorrow (UTC+8).
Nice idea
I forgot that it is possible to use click system programatically😢. I will revert the removement. By the way, could you have a look at vuejs/core#10295? This is needed in this PR to work with nested |
I am wondering what's the actual usage of this relative value besides the internal usage. Previously, <div v-click> show >= 1 </div>
<div v-click="'+2'"> show >= 4 </div>
<div v-click> show >= 3 </div> I think this is kind of useless, because when the user wants to do this, he may write like this, which is much more direct: <div v-click> show >= 1 </div>
<div v-click="4"> show >= 4 </div>
<div v-click> show >= 3 </div> In my opinion, it is better to reserve this syntax but give it a similar meaning: like <div v-click> show >= 1 </div>
<div v-click="'+2'"> show >= 3 </div> !!!!!
<div v-click> show >= 4 </div> !!!!! In this way, |
I don't understand what do you mean here.
Well, ofc. But absolute values are less flexible, especially if you have a lot of click elements in a single slide. Imagine you want to insert a new v-click before this, you have to manually bump 1 for every absolute clicks after that. In that case relative values could save a lot.
I like that, and yes this is probably more intuitive. We could do that.
Sounds good, then we could avoid introduce the
<div v-click> show >= 1 </div>
<div v-click="'+2'"> show >= 3 </div>
<div v-click="'-1'"> show >= 2 </div> I like that consistency 👍 |
新年快乐~ The ba9d9ab commit refactored the clicks context, and fixed Presenter and Print mode. Currently, there is only one injection value about the clicks system: interface ClicksContext {
readonly disabled: boolean // Before this commit, it was `injectionClicksDisabled`
readonly current: number // Current click num. Before this commit, it was `injectionClicks`
readonly flow: ClicksFlow // Before this commit, it was `injectionClicksFlow`
readonly map: ClicksMap / Before this commit, it was `injectionClicksMap`
register: (el: ClicksElement, resolved: ResolvedClicksInfo) => void // Register an element to the clicks flow and map
unregister: (el: ClicksElement) => void // Unregister an element
readonly flowSum: number // sum(...flow.values())
readonly total: number // Math.max(...[...map.values()].map(v => v.max))
} Currently, there is one restriction: One element can only be provided with the same Check the state of a element:const clicks = inject(injectionClicks)!.value
clicks.map.get(el) // => ResolvedClicksInfo // @slidev/types
export interface ResolvedClicksInfo {
max: number // The max required clicks num. Used to automatically calculate the clicks num of the slide.
flowSize: number // The "duration" of the element in the flow. For absolute elements, it is zero.
isCurrent?: ComputedRef<boolean> // CLASS_VCLICK_CURRENT
isActive?: ComputedRef<boolean> // For `v-click`, active means it is visible; For `v-click-hide`, active means it is hidden.
shows?: ComputedRef<boolean> // Is this element visible?
} |
0c0afda
to
792e2b8
Compare
792e2b8
to
3ed7292
Compare
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.
Overall great refactors! Thanks a lot!
return { | ||
nav: { | ||
...nav, | ||
...navClicks, |
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 feel we might still need this, that clicks
, clicksTotal
, clicksContext
should resolved from injections (as we have primary clicks and static clicks now). Components calling this function should get the context to the state of that slide
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 found this in the docs: (https://sli.dev/custom/vue-context#slidev-nav)
After a41a4f4, this PR behaves the same as what the doc says.
Should we get $slidev.nav.clicks
, $slidev.nav.clicksTotal
, $slidev.nav.clicksContext
from the injections, and update the docs?
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, good point. Yeah, I think it's better to use the injection and fix this, yes
6426fd2
to
f6a66f9
Compare
9b405ee
to
1611175
Compare
Fixed in 9586e76
|
That's a really nice PR + the description you have! Certainly don't worry about the English writing - you are doing great! Overall looks good to me, let's merge it and ship as a beta to test out how it goes. Thank you! |
Thank you for the encouragement. I will try my best to update the docs as soon as possible. |
Overview
This PR refactors the clicks system.
Affected:
v-click
,v-after
,v-click-hide
directivesVClicks
,CodeBlockWrapper
,KaTexBlockWrapper
,SlidevVideo
componentsVClickGap
componentFixes:
v-clicks
CSS classes #863v-click
don't work well together #1136Changes
Design
I personally think that the clicks system is a little ambiguous.
This PR considers the clicks to be whether relative or absolute.
"relative" elements
vs.previous auto-calculate clicks
Similar to previous auto-calculate clicks, "relative" elements' click num are calculated depending on the total click num of "relative" elements before this element.
In this PR, only "relative" elements get auto-calculate clicks and add the "relative"s' current total click num by its "size" (for
v-click
it's 1, forv-click="'+3'"
it's 3, forv-after
it's 0). The example is above.User-facing
VClicks.props.every
now accepts string.Code block/latex block line highlight range now supports
'none'
and'hide'
.i.e. Accepts ranges like
1-3,5
, or'none'
, or'hide'
'none'
: No lines are highlighted'hide'
: The code block is hiddenCode block/latex block line highlight adds a
finally
prop.Default:
'last'
, the last highlight range. If no highlight animation, all lines are highlighted.This can also be ranges like
1-3,5
,'none'
, or'hide'
.The difference between this prop and the last one in the ranges: See fix!: rework the clicks system #1279 (comment).
The relative value of
at
prop like"+1"
"-1"
now affects the position of following "relative" elements.See fix!: rework the clicks system #1279 (comment) and fix!: rework the clicks system #1279 (comment)
v-click
===v-click="'+1'"
v-after
===v-click="'+0'"
Add
v-after.fade
andv-click-hide.fade
for consistency withv-click
.Deprecatev-click.hide
(it works the same asv-click-hide
, and there hasn't been av-after.hide
)v-click.hide
andv-after.hide
are both available now.Removerestored.clicks
in page frontmatter, because it is useless nowInternal
clicks
,clicksDisabled
,clicksElements
andclicksOrderMap
clicksContext
(see fix!: rework the clicks system #1279 (comment))Todos
v-after-hide
or fixv-after
to support this?SlidevVideo
(which was introduced by feat: add Video built-in component #905, but I am wondering how it worked with clicks before)VClickGap
component for a gap in clicks flowFind a custom directive hook that is first called inThis enables nestedparent
, then inchild
(Inconsistency order ofcreated
hook between component and custom directive vuejs/core#10295)v-click
directive, which is not supported previously.