Skip to content

Commit f69f0e3

Browse files
committed
wip: setup twoslash
1 parent d20200f commit f69f0e3

File tree

9 files changed

+826
-173
lines changed

9 files changed

+826
-173
lines changed

.npmrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# This is needed for TwoSlash to resolve the types correctly
2+
shamefully-hoist=true

.vitepress/config.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { defineConfigWithTheme } from 'vitepress'
44
import type { Config as ThemeConfig } from '@vue/theme'
55
import baseConfig from '@vue/theme/config'
66
import { headerPlugin } from './headerMdPlugin'
7+
import { transformerTwoslash } from 'vitepress-plugin-twoslash'
78
// import { textAdPlugin } from './textAdMdPlugin'
89

910
const nav: ThemeConfig['nav'] = [
@@ -622,6 +623,8 @@ export default defineConfigWithTheme<ThemeConfig>({
622623
]
623624
],
624625

626+
627+
625628
themeConfig: {
626629
nav,
627630
sidebar,
@@ -711,15 +714,19 @@ export default defineConfigWithTheme<ThemeConfig>({
711714
},
712715

713716
markdown: {
717+
theme: 'github-dark',
714718
config(md) {
715719
md.use(headerPlugin)
716720
// .use(textAdPlugin)
717-
}
721+
},
722+
codeTransformers: [
723+
transformerTwoslash()
724+
]
718725
},
719726

720727
vite: {
721728
define: {
722-
__VUE_OPTIONS_API__: false
729+
__VUE_OPTIONS_API__: true
723730
},
724731
optimizeDeps: {
725732
include: ['gsap', 'dynamics.js'],

.vitepress/theme/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import 'vitepress-plugin-twoslash/style.css'
12
import './styles/index.css'
2-
import { h, App } from 'vue'
3+
4+
import { h, App, Plugin } from 'vue'
35
import { VPTheme } from '@vue/theme'
6+
import twoslashFloatingVue from 'vitepress-plugin-twoslash/client'
47
import PreferenceSwitch from './components/PreferenceSwitch.vue'
58
import {
69
preferComposition,
@@ -22,6 +25,7 @@ export default Object.assign({}, VPTheme, {
2225
})
2326
},
2427
enhanceApp({ app }: { app: App }) {
28+
app.use(twoslashFloatingVue as Plugin<[]>)
2529
app.provide('prefer-composition', preferComposition)
2630
app.provide('prefer-sfc', preferSFC)
2731
app.provide('filter-headers', filterHeadersByPreference)

.vitepress/theme/styles/index.css

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
@import "./pages.css";
22
@import "./badges.css";
3+
@import "./twoslash.css";
34
@import "./options-boxes.css";
45
@import "./inline-demo.css";
56
@import "./utilities.css";
67
@import "./style-guide.css";
7-
8-
/* vitepress rc.31 migrated to shijiki and need this to apply code styles */
9-
.vp-code span {
10-
color: var(--shiki-dark, inherit);
11-
}

.vitepress/theme/styles/twoslash.css

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.floating-vue-twoslash .twoslash-popup-type {
2+
max-width: 600px;
3+
display: block;
4+
padding: 6px 12px;
5+
width: fit-content;
6+
min-width: 100%;
7+
font-family: var(--vt-font-family-mono);
8+
line-height: var(--vt-doc-code-line-height);
9+
font-size: 14px;
10+
color: white;
11+
transition: color 0.5s;
12+
white-space: pre-wrap;
13+
}
14+
15+
.v-popper--theme-twoslash .v-popper__inner {
16+
background: #24292e;
17+
color: white;
18+
border-color: #8885;
19+
}
20+
21+
.v-popper--theme-dropdown .v-popper__arrow-outer {
22+
border-color: #8885;
23+
}
24+
25+
.v-popper--theme-dropdown .v-popper__arrow-inner {
26+
border-color: #24292e;
27+
}

package.json

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,29 @@
1010
"preinstall": "npx only-allow pnpm"
1111
},
1212
"dependencies": {
13-
"@vue/repl": "^3.0.0",
13+
"@vue/repl": "^3.3.0",
1414
"@vue/theme": "^2.2.5",
1515
"dynamics.js": "^1.1.5",
16-
"gsap": "^3.9.0",
17-
"vitepress": "1.0.0-rc.33",
18-
"vue": "^3.4.0"
16+
"floating-vue": "^5.0.3",
17+
"gsap": "^3.12.4",
18+
"vitepress": "1.0.0-rc.36",
19+
"vue": "^3.4.13"
1920
},
2021
"devDependencies": {
21-
"@types/markdown-it": "^12.2.3",
22-
"@types/node": "^20.10.1",
23-
"terser": "^5.14.2"
22+
"@types/markdown-it": "^13.0.7",
23+
"@types/node": "^20.11.0",
24+
"shikiji": "0.10.0-beta.1",
25+
"shikiji-transformers": "0.10.0-beta.1",
26+
"shikiji-twoslash": "0.10.0-beta.1",
27+
"terser": "^5.26.0",
28+
"vitepress-plugin-twoslash": "0.10.0-beta.1"
2429
},
2530
"pnpm": {
2631
"overrides": {
27-
"@vitejs/plugin-vue": "5.0.0-beta.1"
32+
"shikiji": "0.10.0-beta.1",
33+
"shikiji-transformers": "0.10.0-beta.1",
34+
"shikiji-twoslash": "0.10.0-beta.1",
35+
"vitepress-plugin-twoslash": "0.10.0-beta.1"
2836
},
2937
"peerDependencyRules": {
3038
"ignoreMissing": [

0 commit comments

Comments
 (0)