diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index a21b4d96cd..690e799607 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -65,7 +65,10 @@ export default defineConfig({ transformerTwoslash({ twoslashOptions: { // The @slidev/* installed in docs package are very old and should only be used in the homepage demo - vfsRoot: fileURLToPath(new URL('../../demo/starter/', import.meta.url)), + vfsRoot: fileURLToPath(import.meta.url), + compilerOptions: { + resolveJsonModule: true, + }, }, }), ], diff --git a/docs/.vitepress/scripts/prepare.js b/docs/.vitepress/scripts/prepare.js index 661b2a1962..3597981b4d 100644 --- a/docs/.vitepress/scripts/prepare.js +++ b/docs/.vitepress/scripts/prepare.js @@ -2,7 +2,7 @@ import { copy, remove } from 'fs-extra' async function main() { await remove('.vitepress/@slidev') - await copy('node_modules/@slidev', '.vitepress/@slidev', { dereference: true }) + await copy('node_modules/@slidev-old', '.vitepress/@slidev', { dereference: true }) } main() diff --git a/docs/custom/config-code-runners.md b/docs/custom/config-code-runners.md index a00ec319c9..f373c28493 100644 --- a/docs/custom/config-code-runners.md +++ b/docs/custom/config-code-runners.md @@ -8,7 +8,12 @@ By default, JavaScript, TypeScript runners are supported built-in. They run in t Create `./setup/code-runners.ts` with the following content: + + ```ts twoslash +declare const executePythonCodeRemotely: (code: string) => Promise +declare const sanitizeHtml: (html: string) => string +// ---cut--- import { defineCodeRunnersSetup } from '@slidev/types' export default defineCodeRunnersSetup(() => { @@ -35,6 +40,9 @@ export default defineCodeRunnersSetup(() => { The second argument `ctx` is the runner context, which contains the following properties: ```ts twoslash +import type { CodeRunnerOutputs } from '@slidev/types' +import type { CodeToHastOptions } from 'shiki' +// ---cut--- export interface CodeRunnerContext { /** * Options passed to runner via the `runnerOptions` prop. diff --git a/docs/custom/config-context-menu.md b/docs/custom/config-context-menu.md index 8b4b2b83f8..a8a1b2ccfe 100644 --- a/docs/custom/config-context-menu.md +++ b/docs/custom/config-context-menu.md @@ -6,9 +6,16 @@ Customize the context menu items in Slidev. Create `./setup/context-menu.ts` with the following content: + + ```ts twoslash +// ---cut--- import { defineContextMenuSetup } from '@slidev/types' +import { useNav } from '@slidev/client' import { computed } from 'vue' +// ---cut-start--- +// @ts-expect-error missing types +// ---cut-end--- import Icon3DCursor from '~icons/carbon/3d-cursor' export default defineContextMenuSetup((items) => { diff --git a/docs/custom/config-highlighter.md b/docs/custom/config-highlighter.md index da8cd5ce16..398270c769 100644 --- a/docs/custom/config-highlighter.md +++ b/docs/custom/config-highlighter.md @@ -30,14 +30,15 @@ If you want to add custom theme or language (TextMate grammar/themes in JSON), y ```ts twoslash -declare module '*.tmTheme.json' { - const value: any - export default value -} -// ---cut--- /* ./setup/shiki.ts */ import { defineShikiSetup } from '@slidev/types' +// ---cut-start--- +// @ts-expect-error missing types +// ---cut-end--- import customTheme from './customTheme.tmTheme.json' +// ---cut-start--- +// @ts-expect-error missing types +// ---cut-end--- import customLanguage from './customLanguage.tmLanguage.json' export default defineShikiSetup(() => { diff --git a/docs/custom/config-parser.md b/docs/custom/config-parser.md index 7218fa6796..0725bd3761 100644 --- a/docs/custom/config-parser.md +++ b/docs/custom/config-parser.md @@ -1,7 +1,7 @@ # Configure Pre-Parser ::: info -Custom pre-parsers are not supposed to be used too often. Please only use it if you really want to have your custom syntax. +Custom pre-parsers are not supposed to be used too often. Usually you can use [Transformers](./config-transformers) for custom syntaxes. ::: Slidev parses your presentation file (e.g. `slides.md`) in three steps: @@ -162,7 +162,7 @@ import { definePreparserSetup } from '@slidev/types' export default definePreparserSetup(() => { return [ { - transformSlide(content, frontmatter) { + async transformSlide(content, frontmatter) { if ('_scale' in frontmatter) { return [ ``, diff --git a/docs/custom/config-routes.md b/docs/custom/config-routes.md index 4ec1499d21..f87bccb81e 100644 --- a/docs/custom/config-routes.md +++ b/docs/custom/config-routes.md @@ -16,6 +16,9 @@ export default defineRoutesSetup((routes) => { ...routes, { path: '/my-page', + // ---cut-start--- + // @ts-expect-error missing types + // ---cut-end--- component: () => import('../pages/my-page.vue'), }, ] diff --git a/docs/custom/config-vite.md b/docs/custom/config-vite.md index fac5c8f77e..18fb5ef346 100644 --- a/docs/custom/config-vite.md +++ b/docs/custom/config-vite.md @@ -19,7 +19,13 @@ Slidev internally adds the following plugins to Vite: To configure the built-in plugins listed above, create a `vite.config.ts` with the following content. Please note that Slidev has some [default configurations](https://github.com/slidevjs/slidev/blob/main/packages/slidev/node/vite/index.ts) for those plugins, this usage will override some of them, which may potentially cause the app to break. Please treat this as **an advanced feature**, and make sure you know what you are doing before moving on. + + ```ts twoslash +/// +import type MarkdownIt from 'markdown-it' +declare const MyPlugin: (md: MarkdownIt) => void +// ---cut--- import { defineConfig } from 'vite' export default defineConfig({ @@ -31,7 +37,7 @@ export default defineConfig({ /* markdown-it options */ markdownItSetup(md) { /* custom markdown-it plugins */ - md.use(/* ... */) + md.use(MyPlugin/* ... */) }, }, /* options for other plugins */ diff --git a/docs/custom/config-vue.md b/docs/custom/config-vue.md index 0096963021..ed945fcf43 100644 --- a/docs/custom/config-vue.md +++ b/docs/custom/config-vue.md @@ -6,7 +6,12 @@ Slidev uses [Vue 3](https://v3.vuejs.org/) to render the application on the clie Create `./setup/main.ts` with the following content: + + ```ts twoslash +import type { Plugin } from 'vue' +declare const YourPlugin: Plugin +// ---cut--- import { defineAppSetup } from '@slidev/types' export default defineAppSetup(({ app, router }) => { diff --git a/docs/package.json b/docs/package.json index f55aef2fb4..caef451c8c 100644 --- a/docs/package.json +++ b/docs/package.json @@ -17,10 +17,13 @@ "devDependencies": { "@iconify/json": "^2.2.230", "@shikijs/vitepress-twoslash": "^1.11.1", - "@slidev/client": "0.34.3", - "@slidev/parser": "0.34.3", - "@slidev/theme-default": "0.21.2", - "@slidev/types": "0.34.3", + "@slidev-old/client": "npm:@slidev/client@0.34.3", + "@slidev-old/parser": "npm:@slidev/parser@0.34.3", + "@slidev-old/theme-default": "npm:@slidev/theme-default@0.21.2", + "@slidev-old/types": "npm:@slidev/types@0.34.3", + "@slidev/client": "workspace:*", + "@slidev/parser": "workspace:*", + "@slidev/types": "workspace:*", "@types/fs-extra": "^11.0.4", "@types/node": "^20.14.11", "@unocss/reset": "^0.61.5", diff --git a/package.json b/package.json index 13fd778f86..af92382d43 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "lint:fix": "nr lint --fix", "typecheck": "vue-tsc --noEmit", "docs": "pnpm -C docs run dev", - "docs:build": "pnpm -C docs run build && pnpm demo:build", + "docs:build": "pnpm run --filter {./docs}... build && pnpm demo:build", "release": "bumpp package.json packages/*/package.json docs/package.json --all -x \"zx scripts/update-versions.mjs\"", "test": "vitest test", "prepare": "simple-git-hooks" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d47b210054..99a357a072 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -251,18 +251,27 @@ importers: '@shikijs/vitepress-twoslash': specifier: ^1.11.1 version: 1.11.1(@nuxt/kit@3.11.2(rollup@4.19.0))(typescript@5.5.4) + '@slidev-old/client': + specifier: npm:@slidev/client@0.34.3 + version: '@slidev/client@0.34.3(rollup@4.19.0)(typescript@5.5.4)(vite@5.3.4(@types/node@20.14.11))' + '@slidev-old/parser': + specifier: npm:@slidev/parser@0.34.3 + version: '@slidev/parser@0.34.3' + '@slidev-old/theme-default': + specifier: npm:@slidev/theme-default@0.21.2 + version: '@slidev/theme-default@0.21.2' + '@slidev-old/types': + specifier: npm:@slidev/types@0.34.3 + version: '@slidev/types@0.34.3' '@slidev/client': - specifier: 0.34.3 - version: 0.34.3(rollup@4.19.0)(typescript@5.5.4)(vite@5.3.4(@types/node@20.14.11)) + specifier: workspace:* + version: link:../packages/client '@slidev/parser': - specifier: 0.34.3 - version: 0.34.3 - '@slidev/theme-default': - specifier: 0.21.2 - version: 0.21.2 + specifier: workspace:* + version: link:../packages/parser '@slidev/types': - specifier: 0.34.3 - version: 0.34.3 + specifier: workspace:* + version: link:../packages/types '@types/fs-extra': specifier: ^11.0.4 version: 11.0.4