@4399ywkf/editor 0.1.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/README.md ADDED
@@ -0,0 +1,114 @@
1
+ # @4399ywkf/editor
2
+
3
+ 4399 多格式文档编辑器。一个包覆盖 **doc / sheet / pdf**,引擎按需下载。
4
+
5
+ ```bash
6
+ pnpm add @4399ywkf/editor
7
+ ```
8
+
9
+ ```tsx
10
+ import { DocumentView, detectFormat } from "@4399ywkf/editor"
11
+ import "@4399ywkf/editor/styles"
12
+
13
+ <DocumentView format={detectFormat("年度报告.docx")} content={html} />
14
+ ```
15
+
16
+ ## 格式与能力
17
+
18
+ | 格式 | 引擎 | 编辑 | AI 可操作 | 协同 | 依赖 |
19
+ |---|---|---|---|---|---|
20
+ | **doc**(含云文档) | tiptap | ✅ | ✅ | ✅ | 内置 |
21
+ | **sheet** | Univer OSS 核心 | ✅ | ✅ | ✕ | 可选 peer `@univerjs/presets` |
22
+ | **pdf** | pdf.js | ✕ 只读 | ✕ | ✕ | 可选 peer `pdfjs-dist` |
23
+ | **pptx** | — | — | — | — | 需宿主自行注册(见下) |
24
+
25
+ 云文档与本地 doc 是**同一套 tiptap**,不做区分。
26
+
27
+ ## 为什么引擎是懒加载的
28
+
29
+ 主入口只有 **3KB**(格式路由),tiptap 的 698KB 在独立 chunk 里,Univer / pdf.js 是可选 peer。
30
+ `import "@4399ywkf/editor"` 不会把任何引擎拉进你的主包 —— 只有真的渲染到某种格式时才下载。
31
+
32
+ Univer sheets 核心 gzip 后 871KB;无条件打进主包会直接毁掉阅读侧首屏。
33
+
34
+ ## 子路径
35
+
36
+ ```ts
37
+ import { NotionEditor, ArticleViewer } from "@4399ywkf/editor/doc"
38
+ import { ImportDocx, ExportDocx } from "@4399ywkf/editor/docx"
39
+ import { SheetView } from "@4399ywkf/editor/sheet"
40
+ import { PdfView } from "@4399ywkf/editor/pdf"
41
+ import "@4399ywkf/editor/styles"
42
+ ```
43
+
44
+ ## docx 导入导出
45
+
46
+ API 形态对齐 `@tiptap-pro/extension-import-docx` / `-export-docx`,但**在本地解析**,
47
+ 文档不出内网,不需要 `token` / `endpoint`。
48
+
49
+ ```tsx
50
+ import { ImportDocx, ExportDocx } from "@4399ywkf/editor/docx"
51
+
52
+ new Editor({ extensions: [StarterKit, ImportDocx, ExportDocx] })
53
+
54
+ editor.chain().importDocx({ file, onImport(ctx) { ctx.setEditorContent(ctx.content) } }).run()
55
+ editor.chain().exportDocx({ onCompleteExport: (blob) => save(blob) }).run()
56
+ ```
57
+
58
+ 相对官方能力矩阵的增量 —— 这几项官方明确标 ✕:
59
+
60
+ | | 官方 | 本包 |
61
+ |---|---|---|
62
+ | 域(SEQ / TOC / PAGE) | ✕ 只留静态文字 | ✅ 保代码 + 缓存值,可往返 |
63
+ | 墨迹手写 | ✕ | ✅ 保矢量 XML + 位图回退 |
64
+ | 浮动 / 环绕定位 | ~ | ✅ `wrapNone` 绝对定位、不占布局 |
65
+ | 样式定义里的字符格式 | ✅ | ✅ 含 `w:basedOn` 继承链 |
66
+ | 文档不出内网 | ✕ | ✅ |
67
+
68
+ 已知缺口:`fldChar` 复杂域、修订痕迹、页眉页脚 / 脚注、超链接导出未建外部关系。
69
+
70
+ ## 注册自有格式
71
+
72
+ pptx 刻意不内置 —— Univer Slides 官方标注「请勿用于生产环境」,开源世界没有第二个
73
+ 可用的前端 pptx 引擎;真要做只有 OnlyOffice / Collabora 那一档(AGPL,需法务口径)。
74
+ 与其假装支持,不如把口子留给宿主:
75
+
76
+ ```ts
77
+ import { registerFormat } from "@4399ywkf/editor"
78
+
79
+ registerFormat({
80
+ format: "pptx",
81
+ label: "演示文稿",
82
+ extensions: [".ppt", ".pptx"],
83
+ capabilities: {
84
+ editable: false, aiOperable: false, collaborative: false,
85
+ importExtensions: [], exportFormats: [],
86
+ },
87
+ load: () => import("./MyOnlyOfficeSlideView"),
88
+ })
89
+ ```
90
+
91
+ ## 样式
92
+
93
+ 必须显式引入一次:
94
+
95
+ ```ts
96
+ import "@4399ywkf/editor/styles" // dist/style.css,168KB
97
+ ```
98
+
99
+ 包内 55 个 scss 在构建期编译并拼成单文件,JS 产物里**不残留任何 scss 导入** ——
100
+ 消费方无需配置 sass loader,SSR 也不会因为 `import "x.scss"` 报错。
101
+
102
+ ## 协同
103
+
104
+ `doc` 走 yjs。注入扩展时注意:**所有客户端必须注入同一组扩展**,
105
+ schema 不一致时一端产生的节点到另一端会被 y-prosemirror 当非法内容静默丢弃。
106
+
107
+ ## 开发
108
+
109
+ ```bash
110
+ pnpm install
111
+ pnpm build # tsup + 样式编译
112
+ pnpm test # 38 个用例
113
+ pnpm typecheck
114
+ ```
@@ -0,0 +1,18 @@
1
+ import { EditorConfigProvider, NotionEditor } from './chunk-G6WM2PSU.js';
2
+ import { jsx } from 'react/jsx-runtime';
3
+
4
+ function DocView({ content, readOnly, room, className, onReady }) {
5
+ return /* @__PURE__ */ jsx("div", { className, children: /* @__PURE__ */ jsx(EditorConfigProvider, { config: {}, children: /* @__PURE__ */ jsx(
6
+ NotionEditor,
7
+ {
8
+ room: room ?? "default",
9
+ content,
10
+ readOnly,
11
+ onEditorReady: (editor) => onReady?.(editor)
12
+ }
13
+ ) }) });
14
+ }
15
+
16
+ export { DocView as default };
17
+ //# sourceMappingURL=DocView-5KS7B4DA.js.map
18
+ //# sourceMappingURL=DocView-5KS7B4DA.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/views/DocView.tsx"],"names":[],"mappings":";;;AAMe,SAAR,QAAyB,EAAE,OAAA,EAAS,UAAU,IAAA,EAAM,SAAA,EAAW,SAAQ,EAAsB;AAClG,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,QAAA;AAAA,MACA,aAAA,EAAe,CAAC,MAAA,KAAmB,OAAA,GAAU,MAAM;AAAA;AAAA,KAEvD,CAAA,EACF,CAAA;AAEJ","file":"DocView-5KS7B4DA.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, 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 readOnly={readOnly}\n onEditorReady={(editor: Editor) => onReady?.(editor)}\n />\n </EditorConfigProvider>\n </div>\n )\n}\n"]}
@@ -0,0 +1,3 @@
1
+ export { PdfView as default } from './chunk-IRALXCLP.js';
2
+ //# sourceMappingURL=PdfView-JDCHTG7Y.js.map
3
+ //# sourceMappingURL=PdfView-JDCHTG7Y.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"PdfView-JDCHTG7Y.js"}
@@ -0,0 +1,3 @@
1
+ export { SheetView as default } from './chunk-RJUDOUEZ.js';
2
+ //# sourceMappingURL=SheetView-2EID6B2I.js.map
3
+ //# sourceMappingURL=SheetView-2EID6B2I.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"SheetView-2EID6B2I.js"}