@meta-1/editor 1.0.2 → 1.0.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/README.md
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
# @meta-1/editor
|
|
2
|
+
|
|
3
|
+
一个基于 [Tiptap](https://tiptap.dev) 构建的现代化富文本编辑器,提供类似 Notion 的编辑体验。
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@meta-1/editor)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
## ✨ 特性
|
|
9
|
+
|
|
10
|
+
- 🎨 **类 Notion 编辑体验** - 支持斜杠命令、拖拽排序、浮动工具栏
|
|
11
|
+
- 📝 **丰富的内容格式** - 标题、列表、引用、代码块、表格等
|
|
12
|
+
- 🖼️ **图片上传** - 内置图片上传组件,支持自定义上传函数
|
|
13
|
+
- 📊 **表格编辑** - 完整的表格支持,包括合并单元格、调整大小
|
|
14
|
+
- 🔢 **数学公式** - 支持 LaTeX 数学公式渲染
|
|
15
|
+
- 🎯 **多种输出格式** - 支持 JSON、HTML、Markdown 输出
|
|
16
|
+
- 🌐 **国际化** - 内置中文简体、中文繁体、英文语言包
|
|
17
|
+
- 🔄 **协作编辑** - 基于 Yjs 的实时协作支持
|
|
18
|
+
|
|
19
|
+
## 📦 安装
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pnpm add @meta-1/editor
|
|
23
|
+
# 或
|
|
24
|
+
npm install @meta-1/editor
|
|
25
|
+
# 或
|
|
26
|
+
yarn add @meta-1/editor
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Peer Dependencies
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pnpm add react-i18next i18next
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## 🚀 快速开始
|
|
36
|
+
|
|
37
|
+
### 基础用法
|
|
38
|
+
|
|
39
|
+
```tsx
|
|
40
|
+
import { Meta1Editor } from "@meta-1/editor";
|
|
41
|
+
import { useState } from "react";
|
|
42
|
+
|
|
43
|
+
function App() {
|
|
44
|
+
const [content, setContent] = useState({});
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<Meta1Editor
|
|
48
|
+
value={content}
|
|
49
|
+
onChange={setContent}
|
|
50
|
+
placeholder="输入内容..."
|
|
51
|
+
/>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### 使用 Editor 实例
|
|
57
|
+
|
|
58
|
+
```tsx
|
|
59
|
+
import { Meta1Editor } from "@meta-1/editor";
|
|
60
|
+
import { useState } from "react";
|
|
61
|
+
|
|
62
|
+
function App() {
|
|
63
|
+
const editor = Meta1Editor.useEditor();
|
|
64
|
+
const [content, setContent] = useState({});
|
|
65
|
+
|
|
66
|
+
const handleSave = () => {
|
|
67
|
+
const json = editor.getJSON();
|
|
68
|
+
const html = editor.getHTML();
|
|
69
|
+
const markdown = editor.getMarkdown();
|
|
70
|
+
console.log({ json, html, markdown });
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<>
|
|
75
|
+
<Meta1Editor
|
|
76
|
+
editor={editor}
|
|
77
|
+
value={content}
|
|
78
|
+
onChange={setContent}
|
|
79
|
+
placeholder="输入内容..."
|
|
80
|
+
/>
|
|
81
|
+
<button onClick={handleSave}>保存</button>
|
|
82
|
+
</>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### 配置图片上传
|
|
88
|
+
|
|
89
|
+
```tsx
|
|
90
|
+
import { Meta1Editor } from "@meta-1/editor";
|
|
91
|
+
|
|
92
|
+
function App() {
|
|
93
|
+
return (
|
|
94
|
+
<Meta1Editor
|
|
95
|
+
imageUpload={{
|
|
96
|
+
upload: async (file) => {
|
|
97
|
+
const formData = new FormData();
|
|
98
|
+
formData.append("file", file);
|
|
99
|
+
const response = await fetch("/api/upload", {
|
|
100
|
+
method: "POST",
|
|
101
|
+
body: formData,
|
|
102
|
+
});
|
|
103
|
+
const { url } = await response.json();
|
|
104
|
+
return url;
|
|
105
|
+
},
|
|
106
|
+
accept: "image/*",
|
|
107
|
+
maxSize: 5 * 1024 * 1024, // 5MB
|
|
108
|
+
limit: 3,
|
|
109
|
+
onError: (error) => console.error("上传失败:", error),
|
|
110
|
+
onSuccess: (url) => console.log("上传成功:", url),
|
|
111
|
+
}}
|
|
112
|
+
/>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### 设置内容类型
|
|
118
|
+
|
|
119
|
+
```tsx
|
|
120
|
+
// JSON 格式 (默认)
|
|
121
|
+
<Meta1Editor contentType="json" />
|
|
122
|
+
|
|
123
|
+
// HTML 格式
|
|
124
|
+
<Meta1Editor contentType="html" />
|
|
125
|
+
|
|
126
|
+
// Markdown 格式
|
|
127
|
+
<Meta1Editor contentType="markdown" />
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## 📖 API
|
|
131
|
+
|
|
132
|
+
### Meta1Editor Props
|
|
133
|
+
|
|
134
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
135
|
+
|------|------|--------|------|
|
|
136
|
+
| `value` | `string \| Record<string, unknown>` | - | 编辑器内容 |
|
|
137
|
+
| `onChange` | `(content: Meta1EditorValue) => void` | - | 内容变化回调 |
|
|
138
|
+
| `editor` | `Meta1EditorInstance` | - | 编辑器实例 |
|
|
139
|
+
| `placeholder` | `string` | - | 占位符文本 |
|
|
140
|
+
| `contentType` | `'json' \| 'html' \| 'markdown'` | `'json'` | 内容格式 |
|
|
141
|
+
| `editable` | `boolean` | `true` | 是否可编辑 |
|
|
142
|
+
| `imageUpload` | `ImageUploadOptions` | - | 图片上传配置 |
|
|
143
|
+
| `nodeExclude` | `string[]` | - | 输出时排除的节点类型 |
|
|
144
|
+
| `extensions` | `Extensions` | - | 额外的 Tiptap 扩展 |
|
|
145
|
+
| `className` | `string` | - | 自定义 CSS 类名 |
|
|
146
|
+
|
|
147
|
+
### Meta1EditorInstance 方法
|
|
148
|
+
|
|
149
|
+
| 方法 | 返回类型 | 说明 |
|
|
150
|
+
|------|----------|------|
|
|
151
|
+
| `getEditor()` | `Editor \| null` | 获取底层 Tiptap Editor 实例 |
|
|
152
|
+
| `getJSON()` | `Record<string, unknown> \| null` | 获取 JSON 格式内容 |
|
|
153
|
+
| `getHTML()` | `string \| null` | 获取 HTML 格式内容 |
|
|
154
|
+
| `getMarkdown()` | `string \| null` | 获取 Markdown 格式内容 |
|
|
155
|
+
| `focus()` | `void` | 聚焦编辑器 |
|
|
156
|
+
| `isEmpty()` | `boolean` | 检查编辑器是否为空 |
|
|
157
|
+
|
|
158
|
+
### ImageUploadOptions
|
|
159
|
+
|
|
160
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
161
|
+
|------|------|--------|------|
|
|
162
|
+
| `upload` | `(file: File) => Promise<string>` | - | 上传函数,返回图片 URL |
|
|
163
|
+
| `accept` | `string` | `'image/*'` | 接受的文件类型 |
|
|
164
|
+
| `maxSize` | `number` | `10MB` | 最大文件大小 (bytes) |
|
|
165
|
+
| `limit` | `number` | `3` | 最大同时上传数量 |
|
|
166
|
+
| `onError` | `(error: Error) => void` | - | 上传错误回调 |
|
|
167
|
+
| `onSuccess` | `(url: string) => void` | - | 上传成功回调 |
|
|
168
|
+
|
|
169
|
+
## 🌐 国际化
|
|
170
|
+
|
|
171
|
+
编辑器内置多语言支持,可通过以下方式导入语言包:
|
|
172
|
+
|
|
173
|
+
```tsx
|
|
174
|
+
import zhCN from "@meta-1/editor/locales/zh-CN";
|
|
175
|
+
import zhTW from "@meta-1/editor/locales/zh-TW";
|
|
176
|
+
import en from "@meta-1/editor/locales/en";
|
|
177
|
+
|
|
178
|
+
// 配置 i18next
|
|
179
|
+
i18n.init({
|
|
180
|
+
resources: {
|
|
181
|
+
"zh-CN": { editor: zhCN },
|
|
182
|
+
"zh-TW": { editor: zhTW },
|
|
183
|
+
en: { editor: en },
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## 🎨 内置功能
|
|
189
|
+
|
|
190
|
+
### 文本格式
|
|
191
|
+
- 粗体、斜体、下划线、删除线
|
|
192
|
+
- 文字颜色、背景高亮
|
|
193
|
+
- 上标、下标
|
|
194
|
+
- 行内代码
|
|
195
|
+
|
|
196
|
+
### 块级元素
|
|
197
|
+
- 标题 (H1-H6)
|
|
198
|
+
- 段落
|
|
199
|
+
- 有序列表、无序列表、任务列表
|
|
200
|
+
- 引用块
|
|
201
|
+
- 代码块
|
|
202
|
+
- 表格
|
|
203
|
+
- 分割线
|
|
204
|
+
- 图片
|
|
205
|
+
|
|
206
|
+
### 高级功能
|
|
207
|
+
- 斜杠命令菜单 (`/`)
|
|
208
|
+
- @ 提及功能
|
|
209
|
+
- 拖拽排序
|
|
210
|
+
- 浮动工具栏
|
|
211
|
+
- 数学公式 (LaTeX)
|
|
212
|
+
- 文本对齐
|
|
213
|
+
- 节点唯一 ID
|
|
214
|
+
|
|
215
|
+
## 📄 License
|
|
216
|
+
|
|
217
|
+
[MIT](https://opensource.org/licenses/MIT)
|
|
218
|
+
|
package/package.json
CHANGED
|
@@ -8,26 +8,21 @@
|
|
|
8
8
|
@apply relative;
|
|
9
9
|
color: inherit;
|
|
10
10
|
font-style: inherit;
|
|
11
|
-
|
|
12
|
-
&:first-child,
|
|
13
|
-
&:first-of-type {
|
|
14
|
-
@apply mt-0;
|
|
15
|
-
}
|
|
16
11
|
}
|
|
17
12
|
|
|
18
13
|
h1 {
|
|
19
|
-
@apply text-2xl font-bold
|
|
14
|
+
@apply text-2xl font-bold;
|
|
20
15
|
}
|
|
21
16
|
|
|
22
17
|
h2 {
|
|
23
|
-
@apply text-xl font-bold
|
|
18
|
+
@apply text-xl font-bold;
|
|
24
19
|
}
|
|
25
20
|
|
|
26
21
|
h3 {
|
|
27
|
-
@apply text-lg font-semibold
|
|
22
|
+
@apply text-lg font-semibold;
|
|
28
23
|
}
|
|
29
24
|
|
|
30
25
|
h4 {
|
|
31
|
-
@apply text-base font-semibold
|
|
26
|
+
@apply text-base font-semibold;
|
|
32
27
|
}
|
|
33
28
|
}
|