vitepress-plugin-sfc 0.0.0-stage → 2.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 HeroUI-Vue
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,156 @@
1
- # Temporary Holding Version
1
+ # Vitepress Plugin Component
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [简体中文](README-zh-CN.md)
4
+
5
+ A VitePress plugin to display Vue components in your documentation with an automatically generated two-tab interface: one for the component's preview and another to show its source code.
6
+
7
+ ## Features
8
+
9
+ - [x] **Component Preview** - Directly view the rendered output of your component within the documentation.
10
+ - [x] **Syntax Highlighting** - Compatible with VitePress's syntax highlighting.
11
+ - [x] **Code Copying** - One-click copy for the component's source code.
12
+ - [x] **Dark Mode Support** - Automatically adapts to VitePress's light and dark themes.
13
+ - [x] **Lightweight** - No complex dependencies, only `2kb` / gzip:`1kb`.
14
+ - [x] **Internationalization Support** - Default support for Chinese and English, configurable for other languages.
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ npm install vitepress-plugin-sfc --save-dev
20
+ ```
21
+
22
+ ## Configuration
23
+
24
+ ### Add Markdown Plugin
25
+
26
+ Add the plugin to your VitePress configuration file (`.vitepress/config.js` or `.vitepress/config.ts`):
27
+
28
+ ```ts
29
+ import { defineConfig } from 'vitepress'
30
+ import { componentViewMarkdownPlugin } from 'vitepress-plugin-sfc'
31
+
32
+ export default defineConfig({
33
+ // ... other configurations
34
+
35
+ markdown: {
36
+ config: (md) => {
37
+ md.use(componentViewMarkdownPlugin)
38
+ }
39
+ },
40
+ })
41
+ ```
42
+
43
+ ### Configure Client
44
+
45
+ VitePress resolves themes from `.vitepress/theme/index.js` or `.vitepress/theme/index.ts`, and we configure the client here as well.
46
+
47
+ ```ts
48
+ // theme/index.ts
49
+ import DefaultTheme from "vitepress/theme";
50
+ import { enhanceAppWithComponentView } from 'vitepress-plugin-sfc/client'
51
+
52
+ export default {
53
+ extends: DefaultTheme, // Use VitePress's default theme
54
+ enhanceApp({ app }) {
55
+ enhanceAppWithComponentView(app)
56
+ }
57
+ }
58
+ ```
59
+
60
+ The `enhanceAppWithComponentView` function automatically registers the preview component on the passed root component.
61
+
62
+ ### Configure Internationalization
63
+
64
+ The plugin gets language configuration from the `locales.lang` option in VitePress and supports `zh` and `en` languages by default. You can also manually configure other languages or even override the default languages.
65
+
66
+ Configure internationalization in the client configuration:
67
+
68
+ ```ts
69
+ export default {
70
+ // Other configurations
71
+ enhanceApp({ app }) {
72
+ enhanceAppWithComponentView(app, {
73
+ // Configure corresponding languages through localeMappings option
74
+ localeMappings: {
75
+ fr: {
76
+ previewLabel: "foo",
77
+ codeLabel: "bar",
78
+ },
79
+ },
80
+ });
81
+ },
82
+ };
83
+ ```
84
+
85
+ ## Example
86
+
87
+ This is an example of button SFC:
88
+
89
+ ```vue
90
+ <script setup lang="ts">
91
+ import { ref } from 'vue';
92
+
93
+ const count = ref(0)
94
+ </script>
95
+
96
+ <template>
97
+ <button class="my-button" @click="count++">
98
+ Clicked {{ count }} times
99
+ </button>
100
+ </template>
101
+
102
+ <style>
103
+ .my-button {
104
+ background-color: #3eaf7c;
105
+ color: white;
106
+ border: none;
107
+ padding: 8px 16px;
108
+ border-radius: 4px;
109
+ cursor: pointer;
110
+ }
111
+ </style>
112
+ ```
113
+
114
+ VitePress supports [importing Vue components in markdown files](https://vitepress.dev/guide/using-vue#using-components), we import the Button component in the same way:
115
+
116
+ ```bash
117
+ <script setup>
118
+ import Button from './Button.vue'
119
+ </script>
120
+ ```
121
+
122
+ Then use the specified syntax:
123
+
124
+ ```markdown
125
+ ::: component-view
126
+ <Button />
127
+ :::
128
+ ```
129
+
130
+ Here is the complete example code in a markdown file:
131
+
132
+ ```markdown
133
+ <script setup>
134
+ import Button from './Button.vue'
135
+ </script>
136
+
137
+ # This will render a button with click count and a tab bar showing **Preview** and **Source Code**
138
+
139
+ ::: component-view
140
+ <Button />
141
+ :::
142
+
143
+ ##
144
+ ```
145
+
146
+ You can view the component's preview and source code in the tabs above.
147
+
148
+ You can check out the [live demo here](https://vitepress-plugin-sfc-playgrou.vercel.app/).
149
+
150
+ ## Notes
151
+
152
+ - Component paths should be relative to the project root.
153
+ - Current version supports simple Vue components; complex components might require additional configuration. - Components must be valid Single File Components (SFCs).
154
+ ## License
155
+
156
+ [MIT](LICENSE)