Skip to content

Commit 3a10b3a

Browse files
authored
fix: handle slot in v-clicks (#1191)
1 parent 2f5a610 commit 3a10b3a

File tree

7 files changed

+114
-3
lines changed

7 files changed

+114
-3
lines changed

cypress/e2e/examples/basic.spec.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,37 @@ context('Basic', () => {
220220
cy.get('.cy-depth > ul > .slidev-vclick-target:not(.slidev-vclick-hidden)')
221221
.should('have.text', 'A B CDEF GHIJKL')
222222
})
223+
224+
it('slot in v-clicks', () => {
225+
goPage(12)
226+
227+
cy
228+
.url()
229+
.should('eq', 'http://localhost:3030/12')
230+
231+
cy.get('body')
232+
.type('{RightArrow}{RightArrow}{RightArrow}{RightArrow}{RightArrow}{RightArrow}')
233+
.url()
234+
.should('eq', 'http://localhost:3030/12?clicks=6') // we should still be on page 12
235+
236+
cy.get('body')
237+
.type('{RightArrow}')
238+
.url()
239+
.should('eq', 'http://localhost:3030/13')
240+
241+
cy.get('.cy-wrapdecorate > ul > .slidev-vclick-target.slidev-vclick-hidden')
242+
.should('have.text', 'AEFZ')
243+
244+
cy.get('body')
245+
.type('{RightArrow}{RightArrow}{RightArrow}')
246+
247+
cy.get('.cy-wrapdecorate > ul > .slidev-vclick-target:not(.slidev-vclick-hidden)')
248+
.should('have.text', 'AEF')
249+
250+
cy.get('body')
251+
.type('{RightArrow}')
252+
253+
cy.get('.cy-wrapdecorate > ul > .slidev-vclick-target:not(.slidev-vclick-hidden)')
254+
.should('have.text', 'AEFZ')
255+
})
223256
})
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<template>
2+
<li>Step b</li>
3+
<slot />
4+
<li>Step y</li>
5+
</template>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<template>
2+
<div style="border: 1px solid blue">
3+
<v-clicks>
4+
<slot />
5+
</v-clicks>
6+
</div>
7+
</template>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<template>
2+
<v-clicks>
3+
<ul style="border: 1px solid red">
4+
<li>A</li>
5+
<slot />
6+
<li>Z</li>
7+
</ul>
8+
</v-clicks>
9+
</template>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<template>
2+
<v-clicks>
3+
<ol style="border: 1px solid green">
4+
<li>Point a</li>
5+
<decorate-with-li>
6+
<slot />
7+
</decorate-with-li>
8+
<li>Point z</li>
9+
</ol>
10+
</v-clicks>
11+
</template>

cypress/fixtures/basic/slides.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,40 @@ Left
141141

142142
</v-clicks>
143143
</div>
144+
145+
---
146+
147+
# Page 12
148+
149+
<v-clicks>
150+
<ul><li>A</li><li>B</li></ul>
151+
</v-clicks>
152+
153+
<wrap-in-clicks>
154+
<ul><li>A</li><li>B</li></ul>
155+
</wrap-in-clicks>
156+
157+
<wrap-in-clicks>
158+
159+
- A
160+
- B
161+
162+
</wrap-in-clicks>
163+
164+
---
165+
166+
# Page 13
167+
168+
<div class="cy-wrapdecorate">
169+
<wrap-in-clicks-decorate>
170+
<li>E</li>
171+
<li>F</li>
172+
</wrap-in-clicks-decorate>
173+
174+
(the next is kept for a future patch but not animating the nesting)
175+
176+
<wrap-in-component-in-clicks>
177+
<li>step i</li>
178+
<li>step j</li>
179+
</wrap-in-component-in-clicks>
180+
</div>

packages/client/builtin/VClicks.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,25 @@ export default defineComponent({
5050
]])
5151
}
5252

53+
const openAllTopLevelSlots = <T extends VNodeArrayChildren | VNode[]>(children: T): T => {
54+
return children.flatMap((i) => {
55+
if (isVNode(i) && typeof i.type === 'symbol' && Array.isArray(i.children))
56+
return openAllTopLevelSlots(i.children)
57+
else
58+
return [i]
59+
}) as T
60+
}
61+
5362
let defaults = this.$slots.default?.()
5463

5564
if (!defaults)
5665
return
5766

58-
defaults = toArray(defaults)
67+
defaults = openAllTopLevelSlots(toArray(defaults))
5968

6069
const mapSubList = (children: VNodeArrayChildren, depth = 1): [VNodeArrayChildren, number] => {
6170
let idx = 0
62-
const vNodes = children.map((i) => {
71+
const vNodes = openAllTopLevelSlots(children).map((i) => {
6372
if (!isVNode(i))
6473
return i
6574
if (listTags.includes(i.type as string) && Array.isArray(i.children)) {
@@ -76,7 +85,7 @@ export default defineComponent({
7685
let globalIdx = 0
7786
const mapChildren = (children: VNodeArrayChildren, depth = 1): [VNodeArrayChildren, number] => {
7887
let idx = 0
79-
const vNodes = children.map((i) => {
88+
const vNodes = openAllTopLevelSlots(children).map((i) => {
8089
if (!isVNode(i) || i.type === Comment)
8190
return i
8291
const directive = idx % this.every === 0 ? click : after

0 commit comments

Comments
 (0)