Skip to content

Commit 675ffae

Browse files
committed
fix: prevent all Twoslash poppers from showing by default on load
1 parent 044eb3b commit 675ffae

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

packages/client/composables/useNav.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { slides } from '#slidev/slides'
55
import { clamp } from '@antfu/utils'
66
import { parseRangeString } from '@slidev/parser/utils'
77
import { createSharedComposable } from '@vueuse/core'
8+
import { hideAllPoppers } from 'floating-vue'
89
import { computed, ref, watch } from 'vue'
910
import { useRoute, useRouter } from 'vue-router'
1011
import { CLICKS_MAX } from '../constants'
@@ -118,6 +119,8 @@ export function useNavBase(
118119

119120
watch(currentSlideRoute, (next, prev) => {
120121
navDirection.value = next.no - prev.no
122+
if (prev)
123+
hideAllPoppers()
121124
})
122125

123126
async function openInEditor(url?: string) {

packages/slidev/node/options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ function getDefine(options: Omit<ResolvedSlidevOptions, 'utils'>): Record<string
123123
__DEV__: options.mode === 'dev',
124124
__SLIDEV_CLIENT_ROOT__: toAtFS(options.clientRoot),
125125
__SLIDEV_HASH_ROUTE__: options.data.config.routerMode === 'hash',
126+
__SLIDEV_FEATURE_TWOSLASH_AUTOSHOW__: false,
126127
__SLIDEV_FEATURE_DRAWINGS__: matchMode(options.data.config.drawings.enabled),
127128
__SLIDEV_FEATURE_EDITOR__: options.mode === 'dev' && options.data.config.editor !== false,
128129
__SLIDEV_FEATURE_DRAWINGS_PERSIST__: !!options.data.config.drawings.persist,

packages/slidev/node/syntax/markdown-it/markdown-it-shiki.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { ResolvedSlidevOptions } from '@slidev/types'
22
import type { ShikiTransformer } from 'shiki'
33
import { isTruthy } from '@antfu/utils'
44
import { fromHighlighter } from '@shikijs/markdown-it/core'
5+
import { transformerTwoslashConditional } from '../transform/twoslash-conditional'
56
import { escapeVueInCode } from '../transform/utils'
67

78
export default async function MarkdownItShiki({ data: { config }, mode, utils }: ResolvedSlidevOptions) {
@@ -16,6 +17,8 @@ export default async function MarkdownItShiki({ data: { config }, mode, utils }:
1617
},
1718
},
1819
}),
20+
(config.twoslash === true || config.twoslash === mode)
21+
&& transformerTwoslashConditional(),
1922
{
2023
pre(pre) {
2124
this.addClassToHast(pre, 'slidev-code')
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import type { Element } from 'hast'
2+
import type { ShikiTransformer } from 'shiki'
3+
4+
const FLAG_NAME = '__SLIDEV_FEATURE_TWOSLASH_AUTOSHOW__'
5+
6+
function applyAutoShowFlag(node: Element | undefined) {
7+
if (!node)
8+
return
9+
10+
if (node.tagName === 'v-menu') {
11+
const properties = node.properties || (node.properties = {})
12+
if (properties[':shown'] === 'true')
13+
properties[':shown'] = FLAG_NAME
14+
}
15+
16+
const children = Array.isArray(node.children) ? node.children : []
17+
for (const child of children) {
18+
if (child && typeof child === 'object' && 'type' in child && child.type === 'element')
19+
applyAutoShowFlag(child as Element)
20+
}
21+
}
22+
23+
/**
24+
* Custom Twoslash transformer that rewrites the shown binding to use the build-time flag.
25+
*/
26+
export function transformerTwoslashConditional(): ShikiTransformer {
27+
return {
28+
name: 'slidev:twoslash-conditional',
29+
code(codeEl) {
30+
applyAutoShowFlag(codeEl as Element)
31+
},
32+
}
33+
}

0 commit comments

Comments
 (0)