@slidejs/editor 0.1.3

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,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 slidejs
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.
22
+
package/README.md ADDED
@@ -0,0 +1,188 @@
1
+ # @slidejs/editor
2
+
3
+ Slide DSL Monaco Editor with syntax highlighting support.
4
+
5
+ ## 特性
6
+
7
+ - ✅ **语法高亮**: 完整的 Slide DSL 语法高亮支持
8
+ - ✅ **Monaco Editor 集成**: 基于 Monaco Editor,提供强大的编辑体验
9
+ - ✅ **类型安全**: 完整的 TypeScript 类型定义
10
+ - ✅ **易于使用**: 简单的 API,快速集成
11
+
12
+ ## 安装
13
+
14
+ ```bash
15
+ pnpm add @slidejs/editor monaco-editor
16
+ ```
17
+
18
+ ## 使用示例
19
+
20
+ ### 基础用法
21
+
22
+ ```typescript
23
+ import { createSlideDSLEditor } from '@slidejs/editor';
24
+ import 'monaco-editor';
25
+
26
+ const container = document.getElementById('editor');
27
+ if (container) {
28
+ const editor = createSlideDSLEditor(container, {
29
+ value: `present quiz "my-quiz" {
30
+ rules {
31
+ rule start "intro" {
32
+ slide {
33
+ content text {
34
+ "Welcome!"
35
+ }
36
+ }
37
+ }
38
+ }
39
+ }`,
40
+ theme: 'vs-dark',
41
+ fontSize: 14,
42
+ onChange: value => {
43
+ console.log('DSL changed:', value);
44
+ },
45
+ });
46
+ }
47
+ ```
48
+
49
+ ### 配置选项
50
+
51
+ ```typescript
52
+ interface SlideDSLEditorOptions {
53
+ /** 初始内容 */
54
+ value?: string;
55
+ /** 主题 */
56
+ theme?: 'vs' | 'vs-dark' | 'hc-black';
57
+ /** 字体大小 */
58
+ fontSize?: number;
59
+ /** 是否显示行号 */
60
+ lineNumbers?: 'on' | 'off' | 'relative' | 'interval';
61
+ /** 是否显示小地图 */
62
+ minimap?: { enabled: boolean };
63
+ /** 是否自动换行 */
64
+ wordWrap?: 'on' | 'off' | 'wordWrapColumn' | 'bounded';
65
+ /** 是否只读 */
66
+ readOnly?: boolean;
67
+ /** 是否自动布局 */
68
+ automaticLayout?: boolean;
69
+ /** 内容变化回调 */
70
+ onChange?: (value: string) => void;
71
+ }
72
+ ```
73
+
74
+ ### 手动注册语言
75
+
76
+ 如果需要手动注册 Slide DSL 语言(例如在多个编辑器实例之间共享):
77
+
78
+ ```typescript
79
+ import { registerSlideDSLLanguage } from '@slidejs/editor';
80
+
81
+ // 注册语言(只需调用一次)
82
+ registerSlideDSLLanguage();
83
+
84
+ // 然后可以创建多个编辑器实例
85
+ const editor1 = createSlideDSLEditor(container1, { value: '...' });
86
+ const editor2 = createSlideDSLEditor(container2, { value: '...' });
87
+ ```
88
+
89
+ ## 语法高亮支持
90
+
91
+ 编辑器支持以下语法元素的语法高亮:
92
+
93
+ - **关键字**: `present`, `rule`, `start`, `content`, `end`, `for`, `in`, `slide`, `dynamic`, `text`, `name`, `attrs`, `behavior`, `transition`
94
+ - **类型**: `quiz`, `survey`, `form`, `assessment`
95
+ - **字符串**: 双引号和单引号字符串
96
+ - **数字**: 整数和浮点数
97
+ - **布尔值**: `true`, `false`
98
+ - **注释**: 单行注释 (`//`) 和多行注释 (`/* */`)
99
+ - **操作符**: `:`, `{`, `}`, `+`, `.`
100
+
101
+ ## API 参考
102
+
103
+ ### `createSlideDSLEditor(container, options)`
104
+
105
+ 创建 Slide DSL 编辑器实例。
106
+
107
+ **参数**:
108
+
109
+ - `container`: `HTMLElement` - 容器元素
110
+ - `options`: `SlideDSLEditorOptions` - 编辑器选项
111
+
112
+ **返回**: `monaco.editor.IStandaloneCodeEditor` - Monaco Editor 实例
113
+
114
+ ### `registerSlideDSLLanguage()`
115
+
116
+ 注册 Slide DSL 语言到 Monaco Editor。通常在创建编辑器前调用一次即可。
117
+
118
+ ### `updateEditorValue(editor, value)`
119
+
120
+ 更新编辑器内容。
121
+
122
+ **参数**:
123
+
124
+ - `editor`: `monaco.editor.IStandaloneCodeEditor` - 编辑器实例
125
+ - `value`: `string` - 新内容
126
+
127
+ ### `setEditorTheme(editor, theme)`
128
+
129
+ 设置编辑器主题。
130
+
131
+ **参数**:
132
+
133
+ - `editor`: `monaco.editor.IStandaloneCodeEditor` - 编辑器实例
134
+ - `theme`: `'vs' | 'vs-dark' | 'hc-black'` - 主题名称
135
+
136
+ ## 与 Vite 集成
137
+
138
+ 在 `vite.config.ts` 中配置:
139
+
140
+ ```typescript
141
+ import { defineConfig } from 'vite';
142
+ import path from 'path';
143
+
144
+ export default defineConfig({
145
+ optimizeDeps: {
146
+ exclude: ['monaco-editor', '@slidejs/editor'],
147
+ },
148
+ resolve: {
149
+ alias: {
150
+ '@slidejs/editor': path.resolve(__dirname, '../../packages/@slidejs/editor/src'),
151
+ },
152
+ },
153
+ });
154
+ ```
155
+
156
+ ### Worker 配置
157
+
158
+ 编辑器包使用 **Vite 的 `?worker` 导入方式**,这是官方推荐的最佳实践。
159
+
160
+ **工作原理**:
161
+
162
+ - 使用 `?worker` 后缀导入 Worker 文件(如 `monaco-editor/esm/vs/editor/editor.worker?worker`)
163
+ - Vite 会自动:
164
+ 1. 在构建时将 Worker 文件打包到 `dist/assets/` 目录
165
+ 2. 生成正确的 Worker URL
166
+ 3. 处理开发和生产环境的路径差异
167
+
168
+ **开发环境**:
169
+
170
+ - Vite 开发服务器自动处理 Worker 文件
171
+ - 支持 HMR(热模块替换)
172
+
173
+ **生产环境**:
174
+
175
+ - Worker 文件自动打包到 `dist/assets/` 目录
176
+ - 使用正确的相对路径,无需额外配置
177
+ - 完全自包含,无需 CDN 或外部依赖
178
+
179
+ **优势**:
180
+
181
+ - ✅ 无需手动配置 Worker 路径
182
+ - ✅ 自动处理开发和生产环境
183
+ - ✅ Worker 文件自动打包,无需复制
184
+ - ✅ 支持所有 Monaco Editor 语言 Worker
185
+
186
+ ## 许可证
187
+
188
+ MIT