Skip to content

Commit 2149732

Browse files
committed
feat: enhance v-clicks component
1 parent 4054fca commit 2149732

File tree

4 files changed

+36
-9
lines changed

4 files changed

+36
-9
lines changed

docs/guide/animations.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ clicks: 10
6565

6666
### Ordering
6767

68-
By passing the click index to your directives, you can customize the order of the revealing
68+
Passing the click index to your directives, you can customize the order of the revealing
6969

7070
```md
7171
<!-- "1" go first -->
@@ -81,6 +81,13 @@ By passing the click index to your directives, you can customize the order of th
8181
<div v-click="1">3</div>
8282
```
8383

84+
```md
85+
<!-- visible after 3 clicks -->
86+
<v-click at="3">
87+
<div>Hi</div>
88+
</v-click>
89+
```
90+
8491
## Transitions
8592

86-
The built-in support for slides and elements transitions is NOT provided in the current version. We are planned add it in the next major version. Before that, you can still use your custom styles and libraries to do that.
93+
The built-in support for slides and elements transitions is NOT provided in the current version. We are have planned to add it in the next major version. Before that, you can still use your custom styles and libraries to do that.

packages/client/builtin/VClick.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import { createVNode, defineComponent } from 'vue'
22
import VClicks from './VClicks'
33

44
export default defineComponent({
5+
props: {
6+
at: {
7+
type: [Number, String],
8+
},
9+
},
510
render() {
6-
return createVNode(VClicks, { every: 99999 }, { default: this.$slots.default })
11+
return createVNode(VClicks, { every: 99999, at: this.at }, { default: this.$slots.default })
712
},
813
})

packages/client/builtin/VClicks.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
import { toArray } from '@antfu/utils'
2-
import { defineComponent, Directive, h, isVNode, resolveDirective, VNode, withDirectives } from 'vue'
2+
import { defineComponent, Directive, h, isVNode, resolveDirective, VNode, VNodeArrayChildren, withDirectives } from 'vue'
33

44
export default defineComponent({
55
props: {
66
every: {
77
type: Number,
88
default: 1,
99
},
10+
at: {
11+
type: [Number, String],
12+
},
1013
},
1114
render() {
1215
const click = resolveDirective('click')!
1316
const after = resolveDirective('after')!
1417

15-
function applyDirective(node: VNode, directive: Directive) {
18+
const applyDirective = (node: VNode, directive: Directive, delta: number) => {
19+
if (this.at != null)
20+
return withDirectives(node, [[directive, +this.at + delta]])
1621
return withDirectives(node, [[directive]])
1722
}
1823

@@ -23,12 +28,24 @@ export default defineComponent({
2328

2429
defaults = toArray(defaults)
2530

31+
const mapChildren = (children: VNodeArrayChildren) => {
32+
return children.map((i, idx) =>
33+
isVNode(i)
34+
? applyDirective(
35+
h(i),
36+
idx % this.every === 0 ? click : after,
37+
Math.floor(idx / this.every),
38+
)
39+
: i,
40+
)
41+
}
42+
2643
// handle ul list
2744
if (defaults.length === 1 && defaults[0].type === 'ul' && Array.isArray(defaults[0].children)) {
28-
defaults[0].children = defaults[0].children.map((i, idx) => isVNode(i) ? applyDirective(h(i), idx % this.every === 0 ? click : after) : i)
45+
defaults[0].children = mapChildren(defaults[0].children)
2946
return defaults
3047
}
3148

32-
return defaults.map((i, idx) => applyDirective(h(i), idx % this.every === 0 ? click : after))
49+
return mapChildren(defaults)
3350
},
3451
})

packages/client/internals/Editor.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ onMounted(() => {
6262
{
6363
mode: 'markdown',
6464
lineWrapping: true,
65-
// @ts-expect-error
6665
highlightFormatting: true,
6766
fencedCodeBlockDefaultMode: 'javascript',
6867
},
@@ -80,7 +79,6 @@ onMounted(() => {
8079
{
8180
mode: 'markdown',
8281
lineWrapping: true,
83-
// @ts-expect-error
8482
highlightFormatting: true,
8583
fencedCodeBlockDefaultMode: 'javascript',
8684
},

0 commit comments

Comments
 (0)