@slidev/client 52.17.2 → 52.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,56 @@
1
+ import type { ClicksContext, SlideRoute } from '@slidev/types'
2
+ import { describe, expect, it, vi } from 'vitest'
3
+ import { computed, ref } from 'vue'
4
+ import { useNavBase } from './useNav'
5
+
6
+ vi.mock('#slidev/slides', async () => {
7
+ const { ref } = await import('vue')
8
+ return { slides: ref([]) }
9
+ })
10
+
11
+ vi.mock('../env', async () => {
12
+ const { ref } = await import('vue')
13
+ return {
14
+ configs: {},
15
+ slideAspect: ref(16 / 9),
16
+ }
17
+ })
18
+
19
+ vi.mock('../state', async () => {
20
+ const { ref } = await import('vue')
21
+ return { hmrSkipTransition: ref(false) }
22
+ })
23
+
24
+ function route(no: number, frontmatter: Record<string, any>): SlideRoute {
25
+ return {
26
+ no,
27
+ meta: {
28
+ slide: { frontmatter },
29
+ },
30
+ } as unknown as SlideRoute
31
+ }
32
+
33
+ describe('useNavBase', () => {
34
+ it('exposes reactive frontmatter for the current slide', () => {
35
+ const currentRoute = ref(route(1, { title: 'Intro', section: 'start' }))
36
+ const nav = useNavBase(
37
+ computed(() => currentRoute.value),
38
+ computed(() => ({ current: 0, clicksStart: 0, total: 0 }) as ClicksContext),
39
+ ref(0),
40
+ ref(false),
41
+ ref(false),
42
+ )
43
+
44
+ expect(nav.currentFrontmatter.value).toEqual({
45
+ title: 'Intro',
46
+ section: 'start',
47
+ })
48
+
49
+ currentRoute.value = route(2, { title: 'Details', section: 'body' })
50
+
51
+ expect(nav.currentFrontmatter.value).toEqual({
52
+ title: 'Details',
53
+ section: 'body',
54
+ })
55
+ })
56
+ })
@@ -26,6 +26,7 @@ export interface SlidevContextNav {
26
26
  currentSlideRoute: ComputedRef<SlideRoute>
27
27
  currentTransition: ComputedRef<TransitionGroupProps | undefined>
28
28
  currentLayout: ComputedRef<string>
29
+ currentFrontmatter: ComputedRef<Record<string, any>>
29
30
 
30
31
  nextRoute: ComputedRef<SlideRoute>
31
32
  prevRoute: ComputedRef<SlideRoute>
@@ -105,6 +106,7 @@ export function useNavBase(
105
106
  const currentPath = computed(() => getSlidePath(currentSlideRoute.value, isPresenter.value))
106
107
  const currentSlideNo = computed(() => currentSlideRoute.value.no)
107
108
  const currentLayout = computed(() => currentSlideRoute.value.meta?.layout || (currentSlideNo.value === 1 ? 'cover' : 'default'))
109
+ const currentFrontmatter = computed(() => currentSlideRoute.value.meta.slide.frontmatter)
108
110
 
109
111
  const clicks = computed(() => clicksContext.value.current)
110
112
  const clicksStart = computed(() => clicksContext.value.clicksStart)
@@ -223,6 +225,7 @@ export function useNavBase(
223
225
  currentPage: currentSlideNo,
224
226
  currentSlideRoute,
225
227
  currentLayout,
228
+ currentFrontmatter,
226
229
  currentTransition,
227
230
  clicksDirection,
228
231
  nextRoute,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@slidev/client",
3
3
  "type": "module",
4
- "version": "52.17.2",
4
+ "version": "52.18.0",
5
5
  "description": "Presentation slides for developers",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -65,8 +65,8 @@
65
65
  "vue": "^3.5.39",
66
66
  "vue-router": "^5.1.0",
67
67
  "yaml": "^2.9.0",
68
- "@slidev/parser": "52.17.2",
69
- "@slidev/types": "52.17.2"
68
+ "@slidev/parser": "52.18.0",
69
+ "@slidev/types": "52.18.0"
70
70
  },
71
71
  "devDependencies": {
72
72
  "vite": "^8.1.3"
package/shim.d.ts CHANGED
@@ -1,4 +1,18 @@
1
- /// <reference types="vite-plugin-pwa/client" />
1
+ // `vite-plugin-pwa` is an optional peer dependency (only needed when the `pwa`
2
+ // option is enabled), so declare the subset of `virtual:pwa-register` we use
3
+ // inline instead of `/// <reference types="vite-plugin-pwa/client" />`. When
4
+ // PWA is off, the CLI serves a no-op stub for this module.
5
+ declare module 'virtual:pwa-register' {
6
+ export interface RegisterSWOptions {
7
+ immediate?: boolean
8
+ onNeedRefresh?: () => void
9
+ onOfflineReady?: () => void
10
+ onRegisteredSW?: (swScriptUrl: string, registration: ServiceWorkerRegistration | undefined) => void
11
+ onRegisterError?: (error: any) => void
12
+ }
13
+
14
+ export function registerSW(options?: RegisterSWOptions): (reloadPage?: boolean) => Promise<void>
15
+ }
2
16
 
3
17
  declare module '*.md' {
4
18
  // with unplugin-vue-markdown, markdowns can be treat as Vue components