Skip to content

Commit 25aab36

Browse files
Azir-11zhiyuanzmj
andauthored
docs: added support for Chinese documents (#14)
* feat(docs): added support for Chinese documents. close #13 * chore: remove vue-jsx * chore: update * chore: update --------- Co-authored-by: zhiyuanzmj <[email protected]>
1 parent e803bd5 commit 25aab36

File tree

17 files changed

+1101
-20
lines changed

17 files changed

+1101
-20
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Vapor Mode of Vue JSX.
1111
- ✨ Macros: Support most macros of Vue, Friendly to JSX.
1212
- 🌈 Hot Module Replacement: Support functional components or defined by defineComponent.
1313
- 🦾 Type Safe: Provide Volar plugin support by install TS Macro (VSCode plugin).
14-
- ⚙️ ESLint: Provide an ESLint plugin for vue-jsx-vapor to automatically fix code.
14+
- ⚙️ ESLint: Provide an ESLint plugin for vue-jsx-vapor to automatically format code.
1515

1616
## Installation
1717

docs/.vitepress/config.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,67 @@ export default defineConfig({
88
title: 'Vue JSX Vapor',
99
description: 'Vue JSX Vapor',
1010
head: [['link', { rel: 'icon', type: 'image/svg+xml', href: '/logo.svg' }]],
11+
locales: {
12+
root: {
13+
label: 'English',
14+
lang: 'en',
15+
},
16+
zh: {
17+
label: '简体中文',
18+
lang: 'zh-CN',
19+
link: '/zh/',
20+
themeConfig: {
21+
nav: [
22+
{ text: '首页', link: '/zh/' },
23+
{ text: '特性', link: '/zh/features/directives' },
24+
{
25+
text: 'Playground',
26+
link: 'https://repl.zmjs.dev/vuejs/vue-jsx-vapor',
27+
},
28+
],
29+
sidebar: [
30+
{
31+
text: '介绍',
32+
items: [
33+
{
34+
text: '快速开始',
35+
link: `/zh/introduction/getting-started`,
36+
},
37+
{
38+
text: '互操作性',
39+
link: `/zh/introduction/interop`,
40+
},
41+
{
42+
text: '迁移',
43+
link: `/zh/introduction/migration`,
44+
},
45+
{
46+
text: 'ESLint',
47+
link: `/zh/introduction/eslint`,
48+
},
49+
],
50+
},
51+
{
52+
text: '特性',
53+
items: [
54+
{
55+
text: '指令',
56+
link: '/zh/features/directives',
57+
},
58+
{
59+
text: '宏',
60+
link: '/zh/features/macros',
61+
},
62+
{
63+
text: 'useRef',
64+
link: '/zh/features/use-ref',
65+
},
66+
],
67+
},
68+
],
69+
},
70+
},
71+
},
1172
themeConfig: {
1273
// https://vitepress.dev/reference/default-theme-config
1374
logo: '/logo.svg',

docs/features/directives.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Because JSX doesn't support `[]` keyword, use `$` instead.
1919
## Modifiers
2020

2121
Modifiers are special postfixes denoted by a `_`, which indicate that a directive should be bound in some special way.
22-
Because JSX doesn't support `.` keyword, we use `_` instead.
22+
Because JSX doesn't support `.` keyword, use `_` instead.
2323

2424
```tsx
2525
<form onSubmit_prevent>

docs/features/macros.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Macros
22

3-
A collection of macros. They are need to muanually enabled by set `macros` to `true`.
3+
A collection of macros for JSX. They are need to manually enabled by set `macros` to `true`.
44

55
| Directive | Vue | Volar |
66
| :---------------: | :----------------: | :----------------: |

docs/features/use-ref.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,23 @@ import { useRef } from 'vue-jsx-vapor'
1010
// or
1111
// import { shallowRef as useRef } from 'vue'
1212

13-
export const Comp = defineComponent({
14-
setup() {
15-
return { foo: 1 }
16-
},
17-
})
13+
export const Comp = () => {
14+
defineExpose({
15+
foo: 1
16+
})
17+
18+
return <div />
19+
}
1820

1921
export default defineComponent(() => {
2022
const comp = useRef()
2123
comp.value?.foo
2224
// ^?
2325

2426
return (
25-
<>
27+
<div>
2628
<Comp ref={comp} />
27-
</>
29+
</div>
2830
)
2931
})
3032
```

docs/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ layout: home
55
hero:
66
name: "Vue JSX Vapor"
77
text: "Type-safe, Improve DX, High Performance"
8-
tagline: Supports Vapor Mode, all build-in directives and most macros of Vue.
8+
tagline: Vapor Mode of Vue JSX
99
image:
1010
src: /logo.svg
1111
alt: Vue JSX Vapor
@@ -35,6 +35,6 @@ features:
3535
details: Support functional components or defined by defineComponent.
3636
- icon: ⚙️
3737
title: ESLint
38-
details: Provide an ESLint plugin for vue-jsx-vapor to automatically fix code.
38+
details: Provide an ESLint plugin for vue-jsx-vapor to automatically format code.
3939
---
4040

docs/introduction/eslint.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ESLint
22

3-
This is an ESLint plugin for `vue-jsx-vapor` to automatically fix code.
3+
An ESLint plugin for `vue-jsx-vapor` to automatically format code.
44

55
## Install
66

docs/introduction/getting-started.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ export default defineConfig({
5151

5252
## Typescript
5353

54-
Due to `vue-jsx-vapor`'s support for all Vue directives and most Vue macros, the [ts-macro](https://github.com/ts-macro/ts-macro) VSCode plugin is required to enable TypeScript support when using the `vue-jsx-vapor/volar` plugin.
54+
Since `vue-jsx-vapor` supports Vue directives and Vue macros, so need to install the [TS Macro](https://marketplace.visualstudio.com/items?itemName=zhiyuanzmj.vscode-ts-macro) VSCode plugin to load the `vue-jsx-vapor/volar` plugin for type support.
5555

56-
After installing the `ts-macro` VSCode plugin, it automatically loads `vue-jsx-vapor/volar` by analyzing vite.config.ts and shared vueJsxVapor options, eliminating the need to configure ts-macro.config.ts.
56+
The `TS Macro` VSCode plugin will automatically loads the `vue-jsx-vapor/volar` by analyzing `vite.config.ts` and shares the user configuration of the `vue-jsx-vapor/vite` plugin, without the need to manually configure `ts-macro.config.ts`.
5757

58+
::: details manually configuration
5859
::: code-group
5960

6061
```ts [ts-macro.config.ts]

docs/introduction/interop.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Interop
22

3-
`vue-jsx-vapor` support virtual-dom and vapor-dom co-usage. After set interop to `true`, vue-jsx-vapor will be only convert in `defineVaporComponent`'s JSX.
3+
`vue-jsx-vapor` supports Virtual DOM and Vapor DOM co-usage. After setting interop to `true`, JSX within `defineVaporComponent` will be compiled to Vapor DOM, while JSX outside `defineVaporComponent` will be compiled to `Virtual DOM `.
44

55
## Vapor in Virtual DOM
66

@@ -9,7 +9,6 @@
99
::: code-group
1010

1111
```ts [vite.config.ts]
12-
import vueJsx from '@vitejs/plugin-vue-jsx'
1312
import { defineConfig } from 'vite'
1413
import vueJsxVapor from 'vue-jsx-vapor/vite'
1514

@@ -19,7 +18,6 @@ export default defineConfig({
1918
macros: true,
2019
interop: true,
2120
}),
22-
vueJsx(),
2321
],
2422
})
2523
```
@@ -68,7 +66,6 @@ export default defineComponent(() => {
6866
::: code-group
6967

7068
```ts [vite.config.ts]
71-
import vueJsx from '@vitejs/plugin-vue-jsx'
7269
import { defineConfig } from 'vite'
7370
import vueJsxVapor from 'vue-jsx-vapor/vite'
7471

@@ -78,7 +75,6 @@ export default defineConfig({
7875
macros: true,
7976
interop: true,
8077
}),
81-
vueJsx(),
8278
],
8379
})
8480
```

docs/zh/features/directives.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# 指令
2+
3+
用于 JSX 的 Vue 内置指令。
4+
5+
| 指令 | Vue | Volar |
6+
| :---------------------------: | :----------------: | :----------------: |
7+
| `v-if`, `v-else-if`, `v-else` | :white_check_mark: | :white_check_mark: |
8+
| `v-slot`, `v-slots` | :white_check_mark: | :white_check_mark: |
9+
| `v-for` | :white_check_mark: | :white_check_mark: |
10+
| `v-model` | :white_check_mark: | :white_check_mark: |
11+
| `v-html`, `v-text` | :white_check_mark: | / |
12+
| `v-once` | :white_check_mark: | / |
13+
14+
## 动态参数
15+
16+
也可以在指令参数中使用变量。
17+
因为 JSX 不支持 `[]` 关键字,所以使用 `$` 代替。
18+
19+
## 修饰符
20+
21+
修饰符是以 `_` 表示的特殊后缀,表示指令应以某种特殊方式绑定。
22+
因为 JSX 不支持 `.` 关键字,所以用 `_` 代替。
23+
24+
```tsx
25+
<form onSubmit_prevent>
26+
<input v-model_number={value} />
27+
</form>
28+
```
29+
30+
## `v-if`, `v-else-if`, `v-else`
31+
32+
```tsx twoslash
33+
export default ({ foo = 0 }) => {
34+
// ---cut-start---
35+
// prettier-ignore
36+
// ---cut-end---
37+
return (
38+
<>
39+
<div v-if={foo === 0}>{foo}</div>
40+
41+
<div v-else-if={foo === 1}>{foo}</div>
42+
// ^?
43+
44+
<div v-else>{foo}</div>
45+
// ^?
46+
</>
47+
)
48+
}
49+
```
50+
51+
## `v-for`
52+
53+
```tsx twoslash
54+
export default () => (
55+
<div v-for={(item, index) in 4} key={index}>
56+
{item}
57+
</div>
58+
)
59+
```
60+
61+
## `v-slot`, `v-slots`
62+
63+
::: code-group
64+
65+
```tsx [v-slot] twoslash
66+
const Comp = () => {
67+
defineSlots<{
68+
default: () => any
69+
slot: (scope: { bar: number }) => any
70+
slots: (scope: { baz: boolean }) => any
71+
}>()
72+
return <div />
73+
}
74+
75+
// ---cut-start---
76+
// prettier-ignore
77+
// ---cut-end---
78+
export default () => (
79+
<Comp>
80+
默认插槽
81+
<template v-slot:slot={{ bar }}>
82+
// ^|
83+
{bar}
84+
</template>
85+
</Comp>
86+
)
87+
```
88+
89+
```tsx [v-slots] twoslash
90+
const Comp = () => {
91+
defineSlots<{
92+
default: () => any
93+
slot: (scope: { bar: number }) => any
94+
slots: (scope: { baz: boolean }) => any
95+
}>()
96+
return <div />
97+
}
98+
99+
export default () => (
100+
<Comp
101+
v-slots={{
102+
default: () => <>默认插槽</>,
103+
slot: ({ bar }) => <>{bar}</>,
104+
}}
105+
/>
106+
)
107+
```
108+
109+
:::
110+
111+
## `v-model`
112+
113+
```tsx twoslash
114+
import { ref } from 'vue'
115+
116+
const Comp = () => {
117+
const model = defineModel<string>('model')
118+
const models = defineModel<string[]>('models')
119+
return <div />
120+
}
121+
122+
export default () => {
123+
const foo = ref('')
124+
const name = ref('model')
125+
return (
126+
<Comp
127+
v-model:$name_value$={foo.value}
128+
v-model:model={foo.value}
129+
// ^|
130+
/>
131+
)
132+
}
133+
```

0 commit comments

Comments
 (0)