diff --git a/packages/client/composables/useDragElements.ts b/packages/client/composables/useDragElements.ts index 262e5ecd0f..658ee5f0e3 100644 --- a/packages/client/composables/useDragElements.ts +++ b/packages/client/composables/useDragElements.ts @@ -7,6 +7,7 @@ import { injectionCurrentPage, injectionFrontmatter, injectionRenderContext, inj import { makeId } from '../logic/utils' import { activeDragElement } from '../state' import { directiveInject } from '../utils' +import { isTrusted } from '../env' import { useSlideBounds } from './useSlideBounds' import { useDynamicSlideInfo } from './useSlideInfo' @@ -21,7 +22,7 @@ export type DragElementsUpdater = (id: string, posStr: string, type: DragElement const map: Record = {} export function useDragElementsUpdater(no: number) { - if (!(__DEV__ && __SLIDEV_FEATURE_EDITOR__)) + if (!(__SLIDEV_FEATURE_EDITOR__ && isTrusted.value)) return () => {} if (map[no]) diff --git a/packages/client/composables/useFeatures.ts b/packages/client/composables/useFeatures.ts new file mode 100644 index 0000000000..ec4d94caf5 --- /dev/null +++ b/packages/client/composables/useFeatures.ts @@ -0,0 +1,20 @@ +import { createSharedComposable } from '@vueuse/core' +import { computed, reactive } from 'vue' +import { configs, isTrusted } from '../env' +import { useNav } from './useNav' + +export const useFeatures = createSharedComposable(() => { + const { isPresenter, isEmbedded } = useNav() + + const showDrawings = computed(() => __SLIDEV_FEATURE_DRAWINGS__ && !isEmbedded.value && isTrusted.value) + const allowToDraw = computed(() => __SLIDEV_FEATURE_DRAWINGS__ && !isEmbedded.value && isTrusted.value && (!configs.drawings.presenterOnly || isPresenter.value)) + const allowToEdit = computed(() => __SLIDEV_FEATURE_EDITOR__ && isTrusted.value) + const enterPresenter = computed(() => __SLIDEV_FEATURE_PRESENTER__ && !isPresenter.value && isTrusted.value) + + return reactive({ + showDrawings, + allowToDraw, + allowToEdit, + enterPresenter, + }) +}) diff --git a/packages/client/composables/useNav.ts b/packages/client/composables/useNav.ts index 7e42c4bd34..4d872668b2 100644 --- a/packages/client/composables/useNav.ts +++ b/packages/client/composables/useNav.ts @@ -10,7 +10,6 @@ import { getCurrentTransition } from '../logic/transition' import { getSlide, getSlidePath } from '../logic/slides' import { CLICKS_MAX } from '../constants' import { skipTransition } from '../logic/hmr' -import { configs } from '../env' import { useRouteQuery } from '../logic/route' import { useTocTree } from './useTocTree' import { createClicksContextBase } from './useClicks' @@ -76,7 +75,6 @@ export interface SlidevContextNavState { isPlaying: ComputedRef isPresenter: ComputedRef isNotesViewer: ComputedRef - isPresenterAvailable: ComputedRef hasPrimarySlide: ComputedRef currentSlideNo: ComputedRef currentSlideRoute: ComputedRef @@ -285,7 +283,6 @@ const useNavState = createSharedComposable((): SlidevContextNavState => { const isPlaying = computed(() => currentRoute.value.name === 'play') const isPresenter = computed(() => currentRoute.value.name === 'presenter') const isNotesViewer = computed(() => currentRoute.value.name === 'notes') - const isPresenterAvailable = computed(() => !isPresenter.value && (!configs.remote || query.value.get('password') === configs.remote)) const hasPrimarySlide = logicOr(isPlaying, isPresenter) const currentSlideNo = computed(() => hasPrimarySlide.value ? getSlide(currentRoute.value.params.no as string)?.no ?? 1 : 1) @@ -355,7 +352,6 @@ const useNavState = createSharedComposable((): SlidevContextNavState => { isPlaying, isPresenter, isNotesViewer, - isPresenterAvailable, hasPrimarySlide, currentSlideNo, currentSlideRoute, diff --git a/packages/client/env.ts b/packages/client/env.ts index ab64122a71..196e96d967 100644 --- a/packages/client/env.ts +++ b/packages/client/env.ts @@ -1,11 +1,10 @@ import { computed, ref } from 'vue' import { objectMap } from '@antfu/utils' +import { useRouteQuery } from './logic/route' import configs from '#slidev/configs' export { configs } -export const mode = __DEV__ ? 'dev' : 'build' - export const slideAspect = ref(configs.aspectRatio ?? (16 / 9)) export const slideWidth = ref(configs.canvasWidth ?? 980) @@ -20,3 +19,6 @@ export const themeVars = computed(() => { export const slidesTitle = configs.slidesTitle export const pathPrefix = import.meta.env.BASE_URL + (__SLIDEV_HASH_ROUTE__ ? '#/' : '') + +const password = useRouteQuery('password') +export const isTrusted = computed(() => !configs.remote || password.value === configs.remote) diff --git a/packages/client/internals/Controls.vue b/packages/client/internals/Controls.vue index dc840ae011..698b51c88c 100644 --- a/packages/client/internals/Controls.vue +++ b/packages/client/internals/Controls.vue @@ -2,16 +2,16 @@ import { shallowRef } from 'vue' import { showInfoDialog, showRecordingDialog } from '../state' import { configs } from '../env' -import { useNav } from '../composables/useNav' +import { useFeatures } from '../composables/useFeatures' import QuickOverview from './QuickOverview.vue' import InfoDialog from './InfoDialog.vue' import Goto from './Goto.vue' import ContextMenu from './ContextMenu.vue' -const { isEmbedded } = useNav() -const drawingEnabled = __SLIDEV_FEATURE_DRAWINGS__ && !configs.drawings.presenterOnly && !isEmbedded.value +const features = useFeatures() + const DrawingControls = shallowRef() -if (drawingEnabled) +if (__SLIDEV_FEATURE_DRAWINGS__ && features.allowToDraw) import('../internals/DrawingControls.vue').then(v => DrawingControls.value = v.default) const WebCamera = shallowRef() @@ -23,7 +23,7 @@ if (__SLIDEV_FEATURE_RECORD__) { -