vue-repl-enhance 1.2.0 → 1.2.2

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/README.md CHANGED
@@ -1,2 +1,150 @@
1
- ## 使用
2
- 参考 [@vue/repl文档](https://github.com/vuejs/repl#readme)
1
+ # vue-repl-enhance
2
+
3
+ 一个功能增强版的 Vue REPL 组件,支持 Vue 2 和 Vue 3 的在线编辑与预览。基于 `@vue/repl` 开发,增加了对 Vue 2 的支持以及更多配置选项。
4
+
5
+ ## 特性
6
+
7
+ - ⚡️ **多版本支持**:无缝切换 Vue 2 (2.7+) 和 Vue 3 (3.x)。
8
+ - 📝 **编辑器支持**:内置 Monaco Editor 支持,提供强大的代码编辑体验。
9
+ - 🛠 **TypeScript 支持**:内置 TypeScript 编译支持。
10
+ - 📦 **依赖管理**:支持 Import Map,可自定义依赖包路径。
11
+ - 🖥 **灵活布局**:支持左右分栏、仅编辑器、仅预览等多种布局模式。
12
+ - 🎨 **主题定制**:支持亮色 (Light) 和暗色 (Dark) 主题。
13
+
14
+ ## 安装
15
+
16
+ ```bash
17
+ npm install vue-repl-enhance
18
+ # 或
19
+ pnpm add vue-repl-enhance
20
+ # 或
21
+ yarn add vue-repl-enhance
22
+ ```
23
+
24
+ ## 使用指南
25
+
26
+ ### 基础用法
27
+
28
+ ```vue
29
+ <script setup lang="ts">
30
+ import { onMounted } from 'vue'
31
+ import { Repl, ReplStore } from 'vue-repl-enhance'
32
+ import MonacoEditor from 'vue-repl-enhance/monaco-editor'
33
+
34
+ // 初始化 Store
35
+ const store = new ReplStore({
36
+ defaultVueVersion: '3.3.4', // 默认 Vue 版本
37
+ defaultTypescriptVersion: '5.0.2',
38
+ })
39
+
40
+ // 设置初始文件
41
+ onMounted(() => {
42
+ store.setFiles({
43
+ 'App.vue': `
44
+ <template>
45
+ <h1>Hello Vue Repl!</h1>
46
+ </template>
47
+ `
48
+ })
49
+ })
50
+ </script>
51
+
52
+ <template>
53
+ <Repl
54
+ :store="store"
55
+ :editor="MonacoEditor"
56
+ :showCompileOutput="false"
57
+ />
58
+ </template>
59
+
60
+ <style>
61
+ /* 确保容器有高度 */
62
+ .vue-repl {
63
+ height: 100vh;
64
+ }
65
+ </style>
66
+ ```
67
+
68
+ ### Vue 2 支持
69
+
70
+ 要支持 Vue 2,需要在初始化 Store 时指定 Vue 版本为 2.x,并确保提供了 Vue 2 的运行时 URL。
71
+
72
+ ```ts
73
+ const store = new ReplStore({
74
+ defaultVueVersion: '2.7.16',
75
+ // 如果需要,可以手动指定运行时 URL
76
+ // defaultVueRuntimeURL: '...'
77
+ })
78
+ ```
79
+
80
+ ## API 文档
81
+
82
+ ### Repl 组件 Props
83
+
84
+ | 属性名 | 类型 | 默认值 | 说明 |
85
+ |Ref |Ref |Ref |Ref |
86
+ | `editor` | `Component` | **Required** | 编辑器组件 (如 `MonacoEditor`) |
87
+ | `store` | `ReplStore` | `new ReplStore()` | REPL 状态管理实例 |
88
+ | `theme` | `'light' \| 'dark'` | `'light'` | 主题模式 |
89
+ | `layout` | `'horizontal' \| 'vertical'` | - | 布局方向 |
90
+ | `layoutMode` | `'both' \| 'editor' \| 'preview'` | `'both'` | 显示模式 |
91
+ | `split` | `number` | - | 分栏初始比例 |
92
+ | `autoResize` | `boolean` | `true` | 是否自动响应容器大小变化 |
93
+ | `showCompileOutput` | `boolean` | `false` | 是否显示编译输出 |
94
+ | `showImportMap` | `boolean` | `false` | 是否显示 Import Map 编辑器 |
95
+ | `showTsConfig` | `boolean` | `false` | 是否显示 tsconfig.json 编辑器 |
96
+ | `showError` | `boolean` | `true` | 是否显示错误提示 |
97
+ | `showFileSelector` | `boolean` | `true` | 是否显示文件选择器 |
98
+ | `showMessageToggle` | `boolean` | `true` | 是否显示消息切换按钮 |
99
+ | `clearConsole` | `boolean` | `true` | 运行前是否清空控制台 |
100
+ | `ssr` | `boolean` | `false` | 是否启用 SSR 预览模式 |
101
+ | `previewOptions` | `Object` | - | 预览 iframe 的高级配置 |
102
+
103
+ ### ReplStore 配置选项
104
+
105
+ ```ts
106
+ interface StoreOptions {
107
+ serializedState?: string; // 从 URL hash 恢复的状态字符串
108
+ showOutput?: boolean; // 初始是否显示编译输出
109
+ outputMode?: 'preview' | 'js' | 'css' | 'ssr'; // 初始输出模式
110
+ defaultVueVersion?: string; // 默认 Vue 版本
111
+ defaultTypescriptVersion?: string; // 默认 TypeScript 版本
112
+ defaultVueRuntimeURL?: string; // 自定义 Vue 运行时 URL
113
+ defaultVueServerRendererURL?: string;// 自定义 Vue SSR 渲染器 URL
114
+ latestVersions?: Record<string, string>; // 依赖包的最新版本映射
115
+ }
116
+ ```
117
+
118
+ ## 开发与构建
119
+
120
+ ### 启动开发服务器
121
+
122
+ ```bash
123
+ npm run dev
124
+ ```
125
+
126
+ ### 构建
127
+
128
+ ```bash
129
+ npm run build
130
+ ```
131
+
132
+ ## Nginx 配置
133
+
134
+ 如果使用 Nginx 部署,需要确保 `.mjs` 文件被正确识别为 `application/javascript` 类型,否则可能会遇到 MIME type 错误。
135
+
136
+ 在 `nginx.conf` 或 `mime.types` 中添加以下配置:
137
+
138
+ ```nginx
139
+ http {
140
+ include mime.types;
141
+ types {
142
+ application/javascript mjs;
143
+ }
144
+ # ... 其他配置
145
+ }
146
+ ```
147
+
148
+ ## 许可证
149
+
150
+ MIT
@@ -111944,12 +111944,12 @@ self.fetch = async (t, e) => {
111944
111944
  }
111945
111945
  }
111946
111946
  if (n.startsWith("https://cdn.jsdelivr.net/npm/")) {
111947
- const r = n.match(/https:\/\/cdn\.jsdelivr\.net\/npm\/(.+?)@(.+?)\/(.+)/);
111947
+ const r = n.match(/https:\/\/cdn\.jsdelivr\.net\/npm\/((?:@[^/@]+\/[^/@]+)|(?:[^/@]+))(?:@([^/]+))?\/(.+)/);
111948
111948
  if (r) {
111949
111949
  const i = r[1];
111950
111950
  let s = r[2];
111951
111951
  const a = r[3];
111952
- if (s === "latest" && (qs[i] ? s = qs[i] : i.startsWith("@vue/") && (s = qs.vue)), s !== "latest") {
111952
+ if ((!s || s === "latest") && (qs[i] ? s = qs[i] : i.startsWith("@vue/") && (s = qs.vue)), s && s !== "latest") {
111953
111953
  const l = `/vue-repl-deps/${i}@${s}/${a}`;
111954
111954
  try {
111955
111955
  if ((await Ac(l, { method: "HEAD" })).ok)