From e05a716b250eb42608999fc9105616e7c686027b Mon Sep 17 00:00:00 2001 From: _Kerman Date: Thu, 22 Feb 2024 16:10:19 +0800 Subject: [PATCH] fix: slide patching (#1327) --- packages/client/logic/note.ts | 8 ++++---- packages/slidev/node/plugins/loaders.ts | 8 +++----- packages/types/src/types.ts | 5 +++++ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/client/logic/note.ts b/packages/client/logic/note.ts index 9d9f614217..932cf7d16c 100644 --- a/packages/client/logic/note.ts +++ b/packages/client/logic/note.ts @@ -2,11 +2,11 @@ import type { MaybeRef } from '@vueuse/core' import { useFetch } from '@vueuse/core' import type { Ref } from 'vue' import { computed, ref, unref } from 'vue' -import type { SlideInfo } from '@slidev/types' +import type { SlideInfo, SlidePatch } from '@slidev/types' export interface UseSlideInfo { info: Ref - update: (data: Partial) => Promise + update: (data: SlidePatch) => Promise } export function useSlideInfo(id: number | undefined): UseSlideInfo { @@ -21,7 +21,7 @@ export function useSlideInfo(id: number | undefined): UseSlideInfo { execute() - const update = async (data: Partial) => { + const update = async (data: SlidePatch) => { return await fetch( url, { @@ -64,7 +64,7 @@ export function useDynamicSlideInfo(id: MaybeRef) { return { info: computed(() => get(unref(id)).info.value), - update: async (data: Partial, newId?: number) => { + update: async (data: SlidePatch, newId?: number) => { const info = get(newId ?? unref(id)) const newData = await info.update(data) if (newData) diff --git a/packages/slidev/node/plugins/loaders.ts b/packages/slidev/node/plugins/loaders.ts index c11f4103dc..a5509145de 100644 --- a/packages/slidev/node/plugins/loaders.ts +++ b/packages/slidev/node/plugins/loaders.ts @@ -8,7 +8,7 @@ import { bold, gray, red, yellow } from 'kolorist' // @ts-expect-error missing types import mila from 'markdown-it-link-attributes' -import type { SlideInfo } from '@slidev/types' +import type { SlideInfo, SlidePatch } from '@slidev/types' import * as parser from '@slidev/parser/fs' import equal from 'fast-deep-equal' @@ -106,12 +106,10 @@ export function createSlidesLoader( return res.end() } if (type === 'json' && req.method === 'POST') { - const body = await getBodyJson(req) + const body: SlidePatch = await getBodyJson(req) const slide = data.slides[idx] - const onlyNoteChanged = Object.keys(body).length === 2 - && 'note' in body && body.raw === null - if (!onlyNoteChanged) + if (body.content && body.content !== slide.source.content) hmrPages.add(idx) Object.assign(slide.source, body) diff --git a/packages/types/src/types.ts b/packages/types/src/types.ts index 7f152438c1..e689f246b3 100644 --- a/packages/types/src/types.ts +++ b/packages/types/src/types.ts @@ -40,6 +40,11 @@ export interface SlideInfo extends SlideInfoBase { noteHTML?: string } +/** + * Editable fields for a slide + */ +export type SlidePatch = Partial> + /** * Metadata for "slidev" field in themes' package.json */