gzkx-editor 0.0.0

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/STARTUP.md ADDED
@@ -0,0 +1,535 @@
1
+ # ProseMirror 开发环境启动指南
2
+
3
+ ## 目录
4
+
5
+ - [项目简介](#项目简介)
6
+ - [环境要求](#环境要求)
7
+ - [项目结构](#项目结构)
8
+ - [首次设置](#首次设置)
9
+ - [常用命令详解](#常用命令详解)
10
+ - [开发工作流程](#开发工作流程)
11
+ - [测试](#测试)
12
+ - [CSS 文件说明](#css-文件说明)
13
+ - [故障排除](#故障排除)
14
+
15
+ ---
16
+
17
+ ## 项目简介
18
+
19
+ ProseMirror 是一个基于 `contentEditable` 的语义化富文本编辑器,支持协作编辑和自定义文档 Schema。
20
+
21
+ 本仓库是 ProseMirror 的中央仓库(monorepo),用于管理所有核心模块的开发和问题追踪。各核心模块以 Git 子模块的形式存在。
22
+
23
+ **官方资源:**
24
+ - 官网:https://prosemirror.net
25
+ - 问题追踪:https://code.haverbeke.berlin/prosemirror/prosemirror/issues
26
+ - 论坛:https://discuss.prosemirror.net
27
+
28
+ ---
29
+
30
+ ## 环境要求
31
+
32
+ - **Node.js**:建议 v18 或更高版本
33
+ - **npm**:随 Node.js 自动安装
34
+ - **Git**:用于管理子模块
35
+ - **操作系统**:macOS、Linux、Windows 均可
36
+
37
+ 验证环境:
38
+
39
+ ```bash
40
+ node --version # 应显示 v18.x.x 或更高
41
+ npm --version # 应显示 9.x.x 或更高
42
+ git --version # 应显示 2.x.x 或更高
43
+ ```
44
+
45
+ ---
46
+
47
+ ## 项目结构
48
+
49
+ ```
50
+ prosemirror/
51
+ ├── bin/
52
+ │ └── pm.js # 开发工具主脚本
53
+ ├── demo/ # Demo 页面
54
+ │ ├── index.html # Demo 主页
55
+ │ ├── demo.ts # Demo 入口
56
+ │ └── ...
57
+ ├── model/ # 文档数据模型
58
+ ├── transform/ # 文档转换操作
59
+ ├── state/ # 编辑器状态管理
60
+ ├── view/ # 视图渲染层
61
+ ├── keymap/ # 键盘快捷键绑定
62
+ ├── inputrules/ # 输入规则
63
+ ├── history/ # 撤销/重做
64
+ ├── collab/ # 协作编辑
65
+ ├── commands/ # 编辑命令
66
+ ├── gapcursor/ # 空隙光标
67
+ ├── schema-basic/ # 基础文档 Schema
68
+ ├── schema-list/ # 列表 Schema
69
+ ├── menu/ # 菜单栏
70
+ ├── example-setup/ # 示例配置
71
+ ├── markdown/ # Markdown 解析
72
+ ├── dropcursor/ # 拖拽光标
73
+ ├── search/ # 搜索功能
74
+ ├── test-builder/ # 测试构建工具
75
+ ├── changeset/ # 变更集
76
+ └── website/ # 官网
77
+ ```
78
+
79
+ ---
80
+
81
+ ## 首次设置
82
+
83
+ ### 步骤 1:克隆仓库
84
+
85
+ 如果你从 Git 克隆了本仓库,跳过此步。如果是从其他来源获取的,确保仓库完整。
86
+
87
+ ### 步骤 2:安装子模块
88
+
89
+ ProseMirror 的核心模块以 Git 子模块形式存在,需要单独克隆:
90
+
91
+ ```bash
92
+ node bin/pm.js install
93
+ ```
94
+
95
+ 此命令会:
96
+ 1. 克隆所有子模块到对应目录
97
+ 2. 安装根目录依赖
98
+ 3. 安装各子模块依赖
99
+ 4. 构建所有模块
100
+
101
+ **如果安装过程出错**,可以分步执行:
102
+
103
+ ```bash
104
+ # 1. 先手动克隆所有子模块
105
+ cd D:/work/prosemirror
106
+ for submodule in model transform state view keymap inputrules history collab commands gapcursor schema-basic schema-list menu example-setup markdown dropcursor test-builder changeset search website; do
107
+ git clone https://code.haverbeke.berlin/prosemirror/prosemirror-$submodule.git $submodule
108
+ done
109
+
110
+ # 2. 安装根目录依赖
111
+ npm install
112
+
113
+ # 3. 构建所有模块
114
+ node bin/pm.js build
115
+ ```
116
+
117
+ ### 步骤 3:处理 CSS 文件(仅 Windows)
118
+
119
+ **问题原因:**
120
+ - `demo/index.html` 中引用了 `parent/view/style/prosemirror.css` 等路径
121
+ - `parent` 本应是符号链接指向父目录,但 Windows 符号链接需要管理员权限
122
+ - 如果未正确设置,CSS 样式将无法加载
123
+
124
+ **解决方案:复制 CSS 文件**
125
+
126
+ ```bash
127
+ # 创建 CSS 目标目录
128
+ mkdir -p demo/view/style demo/menu/style demo/example-setup/style demo/gapcursor/style demo/search/style
129
+
130
+ # 复制 CSS 文件
131
+ cp view/style/*.css demo/view/style/
132
+ cp menu/style/*.css demo/menu/style/
133
+ cp example-setup/style/*.css demo/example-setup/style/
134
+ cp gapcursor/style/*.css demo/gapcursor/style/
135
+ cp search/style/*.css demo/search/style/
136
+
137
+ # 修改 index.html 中的路径
138
+ # 将 parent/view/style/prosemirror.css 改为 view/style/prosemirror.css
139
+ # (如果 index.html 尚未修改)
140
+ ```
141
+
142
+ **同时需要修改 `index.html`**(如果未修改的话):
143
+
144
+ 将:
145
+ ```html
146
+ <link rel=stylesheet href="parent/view/style/prosemirror.css">
147
+ <link rel=stylesheet href="parent/menu/style/menu.css">
148
+ <link rel=stylesheet href="parent/example-setup/style/style.css">
149
+ <link rel=stylesheet href="parent/gapcursor/style/gapcursor.css">
150
+ ```
151
+
152
+ 改为:
153
+ ```html
154
+ <link rel=stylesheet href="view/style/prosemirror.css">
155
+ <link rel=stylesheet href="menu/style/menu.css">
156
+ <link rel=stylesheet href="example-setup/style/style.css">
157
+ <link rel=stylesheet href="gapcursor/style/gapcursor.css">
158
+ ```
159
+
160
+ ---
161
+
162
+ ## 常用命令详解
163
+
164
+ ### 启动开发服务器
165
+
166
+ ```bash
167
+ node bin/pm.js dev-start
168
+ ```
169
+
170
+ - 启动 HTTP 服务器监听 8080 端口
171
+ - 启动文件监视器,自动重建发生变化的模块
172
+ - 访问地址:http://127.0.0.1:8080/demo/
173
+
174
+ **重要**:修改代码后会自动重新构建,刷新浏览器即可看到更新。
175
+
176
+ ---
177
+
178
+ ### 停止开发服务器
179
+
180
+ ```bash
181
+ node bin/pm.js dev-stop
182
+ ```
183
+
184
+ ---
185
+
186
+ ### 构建所有模块
187
+
188
+ ```bash
189
+ node bin/pm.js build
190
+ ```
191
+
192
+ 手动触发所有模块的 TypeScript 编译和打包。不启动服务器,不监视文件变化。
193
+
194
+ ---
195
+
196
+ ### 监视文件变化
197
+
198
+ ```bash
199
+ node bin/pm.js watch
200
+ ```
201
+
202
+ 与 `dev-start` 类似,但只监视和重建,不启动 HTTP 服务器。
203
+
204
+ ---
205
+
206
+ ### 运行测试
207
+
208
+ ```bash
209
+ # 运行所有测试(默认使用 Chrome 浏览器)
210
+ node bin/pm.js test
211
+
212
+ # 使用 Firefox 浏览器
213
+ node bin/pm.js test --firefox
214
+
215
+ # 跳过浏览器测试
216
+ node bin/pm.js test --no-browser
217
+
218
+ # 只运行包含特定关键词的测试
219
+ node bin/pm.js test --grep "undo"
220
+ ```
221
+
222
+ ---
223
+
224
+ ### 查看子模块状态
225
+
226
+ ```bash
227
+ node bin/pm.js status
228
+ ```
229
+
230
+ 显示所有子模块的 Git 状态,包括未提交的更改、未推送的提交等。
231
+
232
+ ---
233
+
234
+ ### 提交更改
235
+
236
+ ```bash
237
+ node bin/pm.js commit -m "你的提交信息"
238
+ ```
239
+
240
+ 自动在所有有更改的子模块中执行 Git 提交。
241
+
242
+ ---
243
+
244
+ ### 推送更改
245
+
246
+ ```bash
247
+ node bin/pm.js push
248
+ ```
249
+
250
+ 将所有子模块中已提交但未推送的更改推送到远程仓库。
251
+
252
+ ---
253
+
254
+ ### 搜索代码
255
+
256
+ ```bash
257
+ node bin/pm.js grep "关键词"
258
+ ```
259
+
260
+ 在所有子模块的源代码中搜索指定的正则表达式模式。
261
+
262
+ ---
263
+
264
+ ### 查看模块列表
265
+
266
+ ```bash
267
+ # 列出所有模块
268
+ node bin/pm.js modules
269
+
270
+ # 只列出核心模块
271
+ node bin/pm.js modules --core
272
+ ```
273
+
274
+ ---
275
+
276
+ ## 开发工作流程
277
+
278
+ ### 日常开发
279
+
280
+ 1. **启动开发服务器**
281
+ ```bash
282
+ node bin/pm.js dev-start
283
+ ```
284
+
285
+ 2. **访问 Demo 页面**
286
+ 打开浏览器访问:http://127.0.0.1:8080/demo/
287
+
288
+ 3. **修改代码**
289
+ - 修改各子模块的 TypeScript 源文件
290
+ - 保存后自动重建
291
+ - 刷新浏览器查看效果
292
+
293
+ 4. **停止服务器**
294
+ ```bash
295
+ node bin/pm.js dev-stop
296
+ ```
297
+
298
+ ### 修改特定模块
299
+
300
+ 假设要修改 `view` 模块:
301
+
302
+ 1. 找到对应的源文件,如 `view/src/view.ts`
303
+ 2. 修改代码并保存
304
+ 3. 如果开发服务器在运行,会自动重建
305
+ 4. 刷新浏览器查看效果
306
+
307
+ ### 提交更改
308
+
309
+ ```bash
310
+ # 1. 查看哪些模块有更改
311
+ node bin/pm.js status
312
+
313
+ # 2. 提交所有更改
314
+ node bin/pm.js commit -m "描述你的更改"
315
+
316
+ # 3. 推送到远程
317
+ node bin/pm.js push
318
+ ```
319
+
320
+ ---
321
+
322
+ ## 测试
323
+
324
+ ### 运行测试套件
325
+
326
+ ```bash
327
+ node bin/pm.js test
328
+ ```
329
+
330
+ 这会运行所有子模块中的非浏览器测试和浏览器测试。
331
+
332
+ ### 测试文件位置
333
+
334
+ 各模块的测试文件位于 `test/` 目录下,使用 `@marijn/testtool` 测试框架。
335
+
336
+ ### 单独运行某个模块的测试
337
+
338
+ ```bash
339
+ cd <模块目录>
340
+ # 依赖 test-builder 工具运行测试
341
+ ```
342
+
343
+ ---
344
+
345
+ ## CSS 文件说明
346
+
347
+ ### 为什么需要单独处理 CSS?
348
+
349
+ 1. `demo/index.html` 引用了 CSS 文件:
350
+ - `parent/view/style/prosemirror.css`
351
+ - `parent/menu/style/menu.css`
352
+ - 等...
353
+
354
+ 2. `parent` 原本是指向父目录的符号链接,使路径 `parent/view` 等价于项目根目录的 `view`。
355
+
356
+ 3. 在 Linux/macOS 上这没有问题,但在 Windows 上:
357
+ - 创建符号链接需要管理员权限
358
+ - 或者需要启用"开发者模式"
359
+ - 如果没有权限,符号链接无法正常工作
360
+
361
+ 4. 解决方案是直接将 CSS 文件复制到 `demo/` 下的对应目录中。
362
+
363
+ ### 需要复制的 CSS 文件
364
+
365
+ | 模块 | CSS 文件 | 目标目录 |
366
+ |------|----------|----------|
367
+ | view | prosemirror.css | demo/view/style/ |
368
+ | menu | menu.css | demo/menu/style/ |
369
+ | example-setup | style.css | demo/example-setup/style/ |
370
+ | gapcursor | gapcursor.css | demo/gapcursor/style/ |
371
+ | search | search.css | demo/search/style/ |
372
+
373
+ ---
374
+
375
+ ## 故障排除
376
+
377
+ ### 问题:子模块目录不存在
378
+
379
+ **错误信息:**
380
+ ```
381
+ module `view` is missing. Did you forget to run `pm install`?
382
+ ```
383
+
384
+ **解决方案:**
385
+ ```bash
386
+ node bin/pm.js install
387
+ ```
388
+
389
+ 如果 install 命令中的 npm 执行失败,手动执行:
390
+ ```bash
391
+ npm install
392
+ node bin/pm.js build
393
+ ```
394
+
395
+ ---
396
+
397
+ ### 问题:CSS 样式不生效
398
+
399
+ **症状:** 页面加载后没有样式或样式错乱。
400
+
401
+ **检查:**
402
+ 1. 确认 CSS 文件已复制到 `demo/` 下的对应目录
403
+ 2. 确认 `demo/index.html` 中的 CSS 路径正确
404
+ 3. 确认 `demo/view/style/prosemirror.css` 等文件存在
405
+
406
+ **解决方案(重新复制 CSS):**
407
+ ```bash
408
+ rm -rf demo/view demo/menu demo/example-setup demo/gapcursor demo/search
409
+ mkdir -p demo/view/style demo/menu/style demo/example-setup/style demo/gapcursor/style demo/search/style
410
+ cp view/style/*.css demo/view/style/
411
+ cp menu/style/*.css demo/menu/style/
412
+ cp example-setup/style/*.css demo/example-setup/style/
413
+ cp gapcursor/style/*.css demo/gapcursor/style/
414
+ cp search/style/*.css demo/search/style/
415
+ ```
416
+
417
+ ---
418
+
419
+ ### 问题:端口 8080 被占用
420
+
421
+ **错误信息:**
422
+ ```
423
+ Error: listen EADDRINUSE 127.0.0.1:8080
424
+ ```
425
+
426
+ **解决方案:**
427
+ 1. 停止占用 8080 端口的进程:
428
+ ```bash
429
+ # Windows
430
+ netstat -ano | findstr :8080
431
+ taskkill /PID <PID号> /F
432
+
433
+ # macOS/Linux
434
+ lsof -i :8080
435
+ kill -9 <PID>
436
+ ```
437
+
438
+ 2. 或使用环境变量指定其他端口:
439
+ ```bash
440
+ PORT=9090 node bin/pm.js dev-start
441
+ ```
442
+
443
+ ---
444
+
445
+ ### 问题:npm 命令找不到
446
+
447
+ **错误信息:**
448
+ ```
449
+ Error: spawnSync npm ENOENT
450
+ ```
451
+
452
+ **解决方案:**
453
+ 1. 确认 Node.js 和 npm 已正确安装:
454
+ ```bash
455
+ node --version
456
+ npm --version
457
+ ```
458
+
459
+ 2. 如果 npm 不在 PATH 中,尝试:
460
+ ```bash
461
+ # Windows: 使用完整路径
462
+ C:\Program Files\nodejs\npm.cmd install
463
+
464
+ # 或者先进入 Node.js 安装目录
465
+ cd C:\Program Files\nodejs
466
+ .\npm.cmd install
467
+ ```
468
+
469
+ 3. 或者先手动安装依赖:
470
+ ```bash
471
+ npm install
472
+ node bin/pm.js build
473
+ ```
474
+
475
+ ---
476
+
477
+ ### 问题:构建失败
478
+
479
+ **解决方案:**
480
+ 1. 清理并重新构建:
481
+ ```bash
482
+ rm -rf node_modules
483
+ npm install
484
+ node bin/pm.js build
485
+ ```
486
+
487
+ 2. 检查是否有 TypeScript 错误:
488
+ ```bash
489
+ node bin/pm.js build
490
+ ```
491
+ 查看错误输出信息。
492
+
493
+ ---
494
+
495
+ ### 问题:dev-stop 无法停止服务器
496
+
497
+ **症状:** 运行 `dev-stop` 后服务器仍在运行。
498
+
499
+ **解决方案:**
500
+ ```bash
501
+ # 手动杀死进程
502
+ # Windows
503
+ netstat -ano | findstr :8080
504
+ taskkill /PID <PID> /F
505
+
506
+ # 或者通过 PID 文件查找
507
+ cat bin/.pm-dev.pid
508
+ taskkill /PID <PID> /F
509
+ ```
510
+
511
+ ---
512
+
513
+ ## 附录:子模块简介
514
+
515
+ | 模块 | 说明 |
516
+ |------|------|
517
+ | `model` | ProseMirror 文档的数据模型定义 |
518
+ | `transform` | 文档的转换操作(如删除、插入、替换) |
519
+ | `state` | 编辑器的完整状态(包括文档、选择、事务) |
520
+ | `view` | 视图层,负责将状态渲染为 DOM |
521
+ | `keymap` | 键盘快捷键绑定 |
522
+ | `inputrules` | 输入规则(如自动补全、转换) |
523
+ | `history` | 历史记录管理(撤销/重做) |
524
+ | `collab` | 协作编辑支持 |
525
+ | `commands` | 编辑命令(如加粗、斜体) |
526
+ | `gapcursor` | 空隙光标显示 |
527
+ | `schema-basic` | 基础文档 Schema(段落、标题、引用等) |
528
+ | `schema-list` | 列表 Schema(有序列表、无序列表) |
529
+ | `menu` | 菜单栏组件 |
530
+ | `example-setup` | 示例配置和完整编辑器构建 |
531
+ | `markdown` | Markdown 格式解析 |
532
+ | `dropcursor` | 拖拽时的光标样式 |
533
+ | `search` | 搜索和替换功能 |
534
+ | `test-builder` | 测试构建工具 |
535
+ | `changeset` | 变更集实现 |