@4399ywkf/editor 0.7.0 → 0.8.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/README.md CHANGED
@@ -249,6 +249,87 @@ csv / tsv 两处有立场的处理:
249
249
  - **类型推断保守**:前导零(`0123`)和超过 15 位有效数字的「数字」保留为强制文本 ——
250
250
  转成 number 会失真,宁可留原文也不悄悄改值。订单号、身份证号就是这么被毁掉的。
251
251
 
252
+ ## 代码块与代码分组(Shiki)
253
+
254
+ 代码块用 [Shiki](https://shiki.style) 高亮:默认 `github-light` / `github-dark` 随 `.dark`
255
+ 切换,语言按需加载,不需要任何配置。高亮通过 ProseMirror Decoration 着色,正文仍由
256
+ ProseMirror 管理 —— 不改文档、不进撤销历史、不广播给协作者。
257
+
258
+ **代码分组**:在正文里输入或粘贴 `::: code-group` 语法,得到一个可切换标签、可编辑、
259
+ 可复制的分组;也可以用 `contentFormat="markdown"` 直接载入:
260
+
261
+ ```tsx
262
+ import { NotionEditor } from "@4399ywkf/editor/doc"
263
+
264
+ const codeGroupMarkdown = `
265
+ ::: code-group
266
+ \`\`\`bash [curl]
267
+ curl https://api.example.com/v1/chat
268
+ \`\`\`
269
+
270
+ \`\`\`python [python]
271
+ import requests
272
+ \`\`\`
273
+ :::
274
+ `
275
+
276
+ <NotionEditor
277
+ room="api-example"
278
+ contentFormat="markdown"
279
+ content={codeGroupMarkdown}
280
+ onEditorReady={(editor) => save(editor.getJSON())}
281
+ />
282
+ ```
283
+
284
+ - `contentFormat` 可选 `"json" | "html" | "markdown"`。**不传时沿用旧规则:对象按 JSON、
285
+ 字符串按 HTML**。`"json"` 只接受对象,不会去解析 JSON 文本;格式与内容类型不匹配时
286
+ console.error 一条 `[editor]` 信息,当前文档不动。`ArticleViewer` 与 `DocumentView`
287
+ 的 doc 通道接受同样的 `contentFormat`。
288
+ - fence 的 info 按 `语言 [标签]` 解析:`bash [curl]` → 语言 `bash`、标签 `curl`;只写
289
+ `python` 则标签栏显示语言名。标签允许空格与 `\[` `\]` `\\` 转义。
290
+ - 组内只允许完整的 fenced code 与空行;没闭合或混进正文的组保持普通文本,可继续编辑。
291
+ 代码里的 `:::` 不会关闭组。
292
+ - 输出:`editor.getJSON()`(规范结构,`codeGroup` 只含 `codeBlock+`)、`editor.getHTML()`
293
+ (语义 HTML:`<div data-code-group><pre data-language data-label>…`)、
294
+ `getEditorMarkdown(editor)`(`::: code-group` 语法;等价于 `editor.getMarkdown()`,
295
+ 但不需要引 `@tiptap/markdown` 的类型扩充)。`renderHighlightedHTML(editor)` 异步导出
296
+ 调用时刻文档快照的静态 Shiki HTML,所有标签的代码都在、不嵌脚本。
297
+ - 活动标签是 NodeView 本地状态,不写进 JSON / Yjs。本期不提供标签的新增 / 删除 / 排序 /
298
+ 重命名,也不会执行任何代码。
299
+ - `codeBlock` prop 可覆盖主题 / 别名 / 额外语言:`{ shikiTheme, languageAliases, languages }`。
300
+
301
+ ## 折叠块、提示框与 API 参数
302
+
303
+ 三种可折叠块容器,Markdown 都是 VitePress 风格的 `:::` 容器(前两种与 VitePress 原样兼容):
304
+
305
+ ```md
306
+ ::: details 点击查看
307
+ 藏起来的内容
308
+ :::
309
+
310
+ ::: warning 注意
311
+ 不可与 instructions 字段一起使用。
312
+ :::
313
+
314
+ :::: param caching `object`
315
+ 上下文缓存
316
+
317
+ 是否为本次请求开启上下文缓存。
318
+
319
+ ::: param prefix `boolean` 默认 `false`
320
+ 仅写缓存
321
+ :::
322
+ ::::
323
+ ```
324
+
325
+ - 提示框类型:`info` / `tip` / `warning` / `danger`,冒号后的文字是标题(可空,空时显示 信息 / 提示 / 注意 / 危险)。
326
+ - `param` 信息串:第一个词是参数名,反引号里是类型(允许 `string / object[]`),`必选`(或 `required`),`默认 值`(或 `default 值`,值带空格用反引号)。正文第一段是折叠行右边那句短描述,其余段落展开后才显示。
327
+ - 嵌套:外层用更多冒号(`::::`)。代码 fence 里的 `:::` 不会关闭容器;没闭合的容器保持普通文本。
328
+ - 展开 / 收起不进文档:读者打开时全部收起,编辑态光标进入隐藏正文时自动展开。
329
+ - 编辑态头部字段(标题、参数名、类型、必选、默认值、短描述)就地改,失焦或回车提交(一步撤销),Esc 还原;slash 菜单有"折叠块 / 提示框 / 参数"三项;在段落里输入 `::: warning 注意` 回车也能当场生成。
330
+ - `getHTML()` 输出原生 `<details>`(无脚本也能折叠)与 `<div data-callout>`;docx 按顺序摊平为"标题 + 正文",嵌套缩进递增;LiteXML 里是 `<details>` / `<callout>` / `<param>`。
331
+ - 载入:`<NotionEditor contentFormat="markdown" content={markdown} />`。OpenAPI / JSON Schema 导入是后续子项目,参数节点的 JSON 结构就是它的目标形态。
332
+
252
333
  ## docx 导入导出
253
334
 
254
335
  API 形态对齐 `@tiptap-pro/extension-import-docx` / `-export-docx`,但**在本地解析**,
@@ -336,6 +417,19 @@ import "@4399ywkf/editor/styles" // dist/style.css,168KB
336
417
  包内 55 个 scss 在构建期编译并拼成单文件,JS 产物里**不残留任何 scss 导入** ——
337
418
  消费方无需配置 sass loader,SSR 也不会因为 `import "x.scss"` 报错。
338
419
 
420
+ ## 依赖版本:`@tiptap/*` 必须同版本
421
+
422
+ Tiptap 各包之间用**精确版本**的 peerDependencies 互相钉死,本包把全部 `@tiptap/*`
423
+ 统一声明为同一个范围(当前 `^3.30.0`,由 `src/tiptap-versions.test.ts` 守着)。
424
+ 业务仓库自己也引了 `@tiptap/core` / `@tiptap/react` 时,版本必须落在同一个范围里,
425
+ 否则 pnpm 会把一部分去重到你锁文件里的旧版本、给另一部分另拉新版本,构建时报
426
+ `Export attrsEqual doesn't exist in target module` 这类错。升级本包后在业务仓库跑:
427
+
428
+ ```bash
429
+ pnpm update -r "@tiptap/*" # 整个 tiptap 家族对齐到一个版本
430
+ pnpm ls -r "@tiptap/core" # 只应出现一个版本
431
+ ```
432
+
339
433
  ## 协同
340
434
 
341
435
  `doc` 走 yjs。注入扩展时注意:**所有客户端必须注入同一组扩展**,
@@ -1,13 +1,15 @@
1
- import { EditorConfigProvider, NotionEditor } from './chunk-IUDLMN53.js';
1
+ import { EditorConfigProvider, NotionEditor } from './chunk-SGLNT6Z2.js';
2
2
  import './chunk-QMYT5WXO.js';
3
+ import './chunk-ZY5KLA7T.js';
3
4
  import { jsx } from 'react/jsx-runtime';
4
5
 
5
- function DocView({ content, readOnly, room, className, onReady }) {
6
+ function DocView({ content, contentFormat, readOnly, room, className, onReady }) {
6
7
  return /* @__PURE__ */ jsx("div", { className, children: /* @__PURE__ */ jsx(EditorConfigProvider, { config: {}, children: /* @__PURE__ */ jsx(
7
8
  NotionEditor,
8
9
  {
9
10
  room: room ?? "default",
10
11
  content,
12
+ contentFormat,
11
13
  readOnly,
12
14
  onEditorReady: (editor) => onReady?.(editor)
13
15
  }
@@ -15,5 +17,5 @@ function DocView({ content, readOnly, room, className, onReady }) {
15
17
  }
16
18
 
17
19
  export { DocView as default };
18
- //# sourceMappingURL=DocView-XQMJUUVK.js.map
19
- //# sourceMappingURL=DocView-XQMJUUVK.js.map
20
+ //# sourceMappingURL=DocView-WEKRSKRU.js.map
21
+ //# sourceMappingURL=DocView-WEKRSKRU.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/views/DocView.tsx"],"names":[],"mappings":";;;;;AAMe,SAAR,OAAA,CAAyB,EAAE,OAAA,EAAS,aAAA,EAAe,UAAU,IAAA,EAAM,SAAA,EAAW,SAAQ,EAAsB;AACjH,EAAA,2BACG,KAAA,EAAA,EAAI,SAAA,EACH,8BAAC,oBAAA,EAAA,EAAqB,MAAA,EAAQ,EAAC,EAC7B,QAAA,kBAAA,GAAA;AAAA,IAAC,YAAA;AAAA,IAAA;AAAA,MACC,MAAM,IAAA,IAAQ,SAAA;AAAA,MACd,OAAA;AAAA,MACA,aAAA;AAAA,MACA,QAAA;AAAA,MACA,aAAA,EAAe,CAAC,MAAA,KAAmB,OAAA,GAAU,MAAM;AAAA;AAAA,KAEvD,CAAA,EACF,CAAA;AAEJ","file":"DocView-WEKRSKRU.js","sourcesContent":["import type { Editor } from \"@tiptap/react\"\nimport { EditorConfigProvider } from \"../contexts/editor-config-context\"\nimport { NotionEditor } from \"../components/tiptap-templates/notion-like/notion-like-editor\"\nimport type { DocumentViewProps } from \"../registry\"\n\n/** doc 通道:云文档与本地 doc 是同一套 tiptap,不做区分 */\nexport default function DocView({ content, contentFormat, readOnly, room, className, onReady }: DocumentViewProps) {\n return (\n <div className={className}>\n <EditorConfigProvider config={{}}>\n <NotionEditor\n room={room ?? \"default\"}\n content={content as string}\n contentFormat={contentFormat}\n readOnly={readOnly}\n onEditorReady={(editor: Editor) => onReady?.(editor)}\n />\n </EditorConfigProvider>\n </div>\n )\n}\n"]}