From f9818e0ed71e6c26844555df7ddead6c3d8f8bac Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sun, 25 Feb 2024 18:37:16 +0100 Subject: [PATCH] feat: support clicks in notes (#1334) --- demo/starter/slides.md | 12 ++++ packages/client/builtin/VClick.ts | 3 +- packages/client/composables/useClicks.ts | 7 ++- packages/client/constants.ts | 2 + packages/client/internals/NoteDisplay.vue | 55 ++++++++++++++++++- packages/client/internals/NoteEditor.vue | 4 ++ packages/client/internals/NoteStatic.vue | 2 + .../client/internals/OverviewClicksSlider.vue | 3 +- packages/client/internals/SlidesOverview.vue | 3 +- packages/client/logic/nav.ts | 3 +- packages/client/pages/overview.vue | 4 +- packages/client/pages/presenter.vue | 2 + packages/client/styles/index.css | 33 +++++++++++ packages/slidev/node/plugins/loaders.ts | 27 ++++++--- 14 files changed, 143 insertions(+), 17 deletions(-) diff --git a/demo/starter/slides.md b/demo/starter/slides.md index 93fb38cbd3..ddff683fb8 100644 --- a/demo/starter/slides.md +++ b/demo/starter/slides.md @@ -166,6 +166,18 @@ doubled.value = 2 } + + --- # Components diff --git a/packages/client/builtin/VClick.ts b/packages/client/builtin/VClick.ts index 040366f98c..6d088264ee 100644 --- a/packages/client/builtin/VClick.ts +++ b/packages/client/builtin/VClick.ts @@ -6,6 +6,7 @@ import type { PropType, VNode } from 'vue' import { Text, defineComponent, h } from 'vue' +import { CLICKS_MAX } from '../constants' import VClicks from './VClicks' export default defineComponent({ @@ -31,7 +32,7 @@ export default defineComponent({ return h( VClicks, { - every: 99999, + every: CLICKS_MAX, at: this.at, hide: this.hide, fade: this.fade, diff --git a/packages/client/composables/useClicks.ts b/packages/client/composables/useClicks.ts index fff802fb21..b16baf3c26 100644 --- a/packages/client/composables/useClicks.ts +++ b/packages/client/composables/useClicks.ts @@ -5,6 +5,7 @@ import { ref, shallowReactive } from 'vue' import type { RouteRecordRaw } from 'vue-router' import { currentRoute, isPrintMode, isPrintWithClicks, queryClicks, routeForceRefresh } from '../logic/nav' import { normalizeAtProp } from '../logic/utils' +import { CLICKS_MAX } from '../constants' /** * @internal @@ -65,14 +66,14 @@ export function useClicksContextBase(getCurrent: () => number, clicksOverrides?: export function usePrimaryClicks(route: RouteRecordRaw | undefined): ClicksContext { if (route?.meta?.__clicksContext) return route.meta.__clicksContext - const thisPath = +(route?.path ?? 99999) + const thisPath = +(route?.path ?? CLICKS_MAX) const context = useClicksContextBase( () => { - const currentPath = +(currentRoute.value?.path ?? 99999) + const currentPath = +(currentRoute.value?.path ?? CLICKS_MAX) if (currentPath === thisPath) return queryClicks.value else if (currentPath > thisPath) - return 99999 + return CLICKS_MAX else return 0 }, diff --git a/packages/client/constants.ts b/packages/client/constants.ts index de65481247..7522912a39 100644 --- a/packages/client/constants.ts +++ b/packages/client/constants.ts @@ -22,6 +22,8 @@ export const CLASS_VCLICK_HIDDEN_EXP = 'slidev-vclick-hidden-explicitly' export const CLASS_VCLICK_CURRENT = 'slidev-vclick-current' export const CLASS_VCLICK_PRIOR = 'slidev-vclick-prior' +export const CLICKS_MAX = 999999 + export const TRUST_ORIGINS = [ 'localhost', '127.0.0.1', diff --git a/packages/client/internals/NoteDisplay.vue b/packages/client/internals/NoteDisplay.vue index 0913387784..1e85f12ace 100644 --- a/packages/client/internals/NoteDisplay.vue +++ b/packages/client/internals/NoteDisplay.vue @@ -1,19 +1,70 @@