Skip to content

Commit 6c2aa62

Browse files
committed
feat: presenter mode controls
1 parent 6023868 commit 6c2aa62

File tree

4 files changed

+56
-17
lines changed

4 files changed

+56
-17
lines changed

packages/client/internals/Presenter.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ const controls = useNavigateControls()
2828
</SlideContainer>
2929
</div>
3030
<div class="grid-section next flex flex-col p-4 bg-gray-400 bg-opacity-10">
31-
<SlideContainer class="h-full w-full">
31+
<!-- <SlideContainer class="h-full w-full">
3232
<component :is="controls.nextRoute.value?.component" />
33-
</SlideContainer>
33+
</SlideContainer> -->
3434
</div>
3535
<div class="grid-section note"></div>
3636
<div class="grid-section bottom"></div>

packages/client/internals/SlidesOverview.vue

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,17 @@ const props = defineProps<{ modelValue: boolean }>()
1010
1111
const value = useVModel(props, 'modelValue', emit)
1212
13-
const { routes } = useNavigateControls()
13+
const { go: _go, routes } = useNavigateControls()
1414
1515
function close() {
1616
value.value = false
1717
}
1818
19+
function go(page: number) {
20+
_go(page)
21+
close()
22+
}
23+
1924
const sm = breakpoints.smaller('sm')
2025
const md = breakpoints.smaller('md')
2126
@@ -45,10 +50,9 @@ const cardWidth = computed(() => {
4550
:key="route.path"
4651
class="relative"
4752
>
48-
<RouterLink
49-
:to="route.path"
53+
<div
5054
class="inline-block border border-gray-400 rounded border-opacity-50 overflow-hidden bg-main hover:(border-primary)"
51-
@click="close"
55+
@click="go(+route.path)"
5256
>
5357
<SlideContainer
5458
v-click-disabled
@@ -57,7 +61,7 @@ const cardWidth = computed(() => {
5761
>
5862
<component :is="route.component" />
5963
</SlideContainer>
60-
</RouterLink>
64+
</div>
6165
<div
6266
class="absolute top-0 opacity-50"
6367
:style="`left: ${cardWidth + 5}px`"

packages/client/logic/controls.ts

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import { computed, App, InjectionKey, inject, ref, ComputedRef, Ref } from 'vue'
1+
import { computed, App, InjectionKey, inject, ref, ComputedRef, Ref, watch } from 'vue'
22
import { and, Fn, not, whenever } from '@vueuse/core'
33
import { Router, RouteRecordRaw } from 'vue-router'
44
import { clickCurrent, clickElements } from '../logic'
55
import { isInputing, magicKeys } from '../state'
66
import { rawRoutes } from '../routes'
7+
// @ts-expect-error
8+
import serverState from '/@server-ref/state'
79

810
declare module 'vue-router' {
911
interface RouteMeta {
@@ -31,6 +33,7 @@ export interface NavigateControls {
3133
paused: Ref<boolean>
3234
hasNext: ComputedRef<boolean>
3335
hasPrev: ComputedRef<boolean>
36+
go(page: number): void
3437
install(app: App): void
3538
}
3639

@@ -51,14 +54,34 @@ export function createNavigateControls(router: Router) {
5154
const hasPrev = computed(() => currentPage.value > 0)
5255
const nextRoute = computed(() => routes.find(i => i.path === `${Math.min(routes.length - 1, currentPage.value + 1)}`))
5356

57+
router.isReady().then(() => {
58+
watch(serverState,
59+
() => {
60+
if (+serverState.value.page !== +currentPage.value)
61+
router.replace(getPath(serverState.value.page))
62+
clickCurrent.value = serverState.value.tab || 0
63+
},
64+
{ deep: true },
65+
)
66+
})
67+
68+
function updateState() {
69+
if (isPresenter.value) {
70+
serverState.value.page = +currentPage.value
71+
serverState.value.tab = clickCurrent.value
72+
}
73+
}
74+
75+
watch(clickCurrent, updateState)
76+
5477
function next() {
5578
if (clickElements.value.length <= clickCurrent.value)
5679
nextSlide()
5780
else
5881
clickCurrent.value += 1
5982
}
6083

61-
function prev() {
84+
async function prev() {
6285
if (clickCurrent.value <= 0)
6386
prevSlide()
6487
else
@@ -69,18 +92,21 @@ export function createNavigateControls(router: Router) {
6992
return isPresenter.value ? `/presenter/${no}` : `/${no}`
7093
}
7194

72-
function nextSlide() {
73-
clickCurrent.value = 0
74-
clickElements.value = []
95+
async function nextSlide() {
7596
const next = Math.min(routes.length - 1, currentPage.value + 1)
76-
router.push(getPath(next))
97+
go(next)
7798
}
7899

79-
function prevSlide() {
100+
async function prevSlide() {
101+
const next = Math.max(0, currentPage.value - 1)
102+
go(next)
103+
}
104+
105+
async function go(page: number) {
80106
clickCurrent.value = 0
81107
clickElements.value = []
82-
const next = Math.max(0, currentPage.value - 1)
83-
router.push(getPath(next))
108+
await router.push(getPath(page))
109+
updateState()
84110
}
85111

86112
const shortcutEnabled = and(not(paused), not(isInputing))
@@ -105,6 +131,7 @@ export function createNavigateControls(router: Router) {
105131
routes,
106132
isPresenter,
107133
currentPage,
134+
go,
108135
install(app: App) {
109136
app.provide(NavigateControlsInjection, navigateControls)
110137
},

packages/slidev/node/plugins/preset.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,15 @@ export function ViteSlidevPlugin(options: SlidevPluginOptions = {}): Plugin[] {
111111
}),
112112

113113
VitePluginVueFactory(),
114-
VitePluginServerRef(),
114+
VitePluginServerRef({
115+
dataMap: {
116+
sync: false,
117+
state: {
118+
page: 0,
119+
tab: 0,
120+
},
121+
},
122+
}),
115123
createConfigPlugin(slidesOptions),
116124
createEntryPlugin(slidesOptions),
117125
createSlidesLoader(slidesOptions),

0 commit comments

Comments
 (0)