@haklex/rich-editor 0.0.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/LICENSE +28 -0
- package/README.md +164 -0
- package/dist/RichEditor-DeRWrU51.js +1125 -0
- package/dist/RichRenderer-BmM4j0fv.js +95 -0
- package/dist/components/ContentEditable.d.ts +7 -0
- package/dist/components/ContentEditable.d.ts.map +1 -0
- package/dist/components/RendererWrapper.d.ts +31 -0
- package/dist/components/RendererWrapper.d.ts.map +1 -0
- package/dist/components/RichEditor.d.ts +3 -0
- package/dist/components/RichEditor.d.ts.map +1 -0
- package/dist/components/RichRenderer.d.ts +3 -0
- package/dist/components/RichRenderer.d.ts.map +1 -0
- package/dist/components/decorators/AlertEditDecorator.d.ts +10 -0
- package/dist/components/decorators/AlertEditDecorator.d.ts.map +1 -0
- package/dist/components/decorators/BannerEditDecorator.d.ts +10 -0
- package/dist/components/decorators/BannerEditDecorator.d.ts.map +1 -0
- package/dist/components/decorators/CodeBlockEditDecorator.d.ts +8 -0
- package/dist/components/decorators/CodeBlockEditDecorator.d.ts.map +1 -0
- package/dist/components/decorators/GridEditDecorator.d.ts +10 -0
- package/dist/components/decorators/GridEditDecorator.d.ts.map +1 -0
- package/dist/components/renderers/AlertReadOnlyDecorator.d.ts +9 -0
- package/dist/components/renderers/AlertReadOnlyDecorator.d.ts.map +1 -0
- package/dist/components/renderers/AlertRenderer.d.ts +9 -0
- package/dist/components/renderers/AlertRenderer.d.ts.map +1 -0
- package/dist/components/renderers/BannerReadOnlyDecorator.d.ts +9 -0
- package/dist/components/renderers/BannerReadOnlyDecorator.d.ts.map +1 -0
- package/dist/components/renderers/BannerRenderer.d.ts +9 -0
- package/dist/components/renderers/BannerRenderer.d.ts.map +1 -0
- package/dist/components/renderers/CodeBlockRenderer.d.ts +9 -0
- package/dist/components/renderers/CodeBlockRenderer.d.ts.map +1 -0
- package/dist/components/renderers/FootnoteRenderer.d.ts +5 -0
- package/dist/components/renderers/FootnoteRenderer.d.ts.map +1 -0
- package/dist/components/renderers/FootnoteSectionEditRenderer.d.ts +6 -0
- package/dist/components/renderers/FootnoteSectionEditRenderer.d.ts.map +1 -0
- package/dist/components/renderers/FootnoteSectionRenderer.d.ts +6 -0
- package/dist/components/renderers/FootnoteSectionRenderer.d.ts.map +1 -0
- package/dist/components/renderers/GridReadOnlyDecorator.d.ts +9 -0
- package/dist/components/renderers/GridReadOnlyDecorator.d.ts.map +1 -0
- package/dist/components/renderers/ImageRenderer.d.ts +11 -0
- package/dist/components/renderers/ImageRenderer.d.ts.map +1 -0
- package/dist/components/renderers/KaTeXRenderer.d.ts +6 -0
- package/dist/components/renderers/KaTeXRenderer.d.ts.map +1 -0
- package/dist/components/renderers/LinkCardRenderer.d.ts +11 -0
- package/dist/components/renderers/LinkCardRenderer.d.ts.map +1 -0
- package/dist/components/renderers/MentionRenderer.d.ts +7 -0
- package/dist/components/renderers/MentionRenderer.d.ts.map +1 -0
- package/dist/components/renderers/MermaidRenderer.d.ts +6 -0
- package/dist/components/renderers/MermaidRenderer.d.ts.map +1 -0
- package/dist/components/renderers/VideoRenderer.d.ts +8 -0
- package/dist/components/renderers/VideoRenderer.d.ts.map +1 -0
- package/dist/components/utils.d.ts +5 -0
- package/dist/components/utils.d.ts.map +1 -0
- package/dist/config-edit.d.ts +4 -0
- package/dist/config-edit.d.ts.map +1 -0
- package/dist/config.d.ts +5 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/context/ColorSchemeContext.d.ts +8 -0
- package/dist/context/ColorSchemeContext.d.ts.map +1 -0
- package/dist/context/FootnoteDefinitionsContext.d.ts +12 -0
- package/dist/context/FootnoteDefinitionsContext.d.ts.map +1 -0
- package/dist/context/RendererConfigContext.d.ts +12 -0
- package/dist/context/RendererConfigContext.d.ts.map +1 -0
- package/dist/editor.d.ts +6 -0
- package/dist/editor.d.ts.map +1 -0
- package/dist/editor.mjs +12 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +79 -0
- package/dist/node-registry.d.ts +4 -0
- package/dist/node-registry.d.ts.map +1 -0
- package/dist/nodes/AlertQuoteEditNode.d.ts +9 -0
- package/dist/nodes/AlertQuoteEditNode.d.ts.map +1 -0
- package/dist/nodes/AlertQuoteNode.d.ts +31 -0
- package/dist/nodes/AlertQuoteNode.d.ts.map +1 -0
- package/dist/nodes/BannerEditNode.d.ts +9 -0
- package/dist/nodes/BannerEditNode.d.ts.map +1 -0
- package/dist/nodes/BannerNode.d.ts +32 -0
- package/dist/nodes/BannerNode.d.ts.map +1 -0
- package/dist/nodes/CodeBlockEditNode.d.ts +9 -0
- package/dist/nodes/CodeBlockEditNode.d.ts.map +1 -0
- package/dist/nodes/CodeBlockNode.d.ts +28 -0
- package/dist/nodes/CodeBlockNode.d.ts.map +1 -0
- package/dist/nodes/DetailsNode.d.ts +28 -0
- package/dist/nodes/DetailsNode.d.ts.map +1 -0
- package/dist/nodes/FootnoteNode.d.ts +22 -0
- package/dist/nodes/FootnoteNode.d.ts.map +1 -0
- package/dist/nodes/FootnoteSectionEditNode.d.ts +10 -0
- package/dist/nodes/FootnoteSectionEditNode.d.ts.map +1 -0
- package/dist/nodes/FootnoteSectionNode.d.ts +25 -0
- package/dist/nodes/FootnoteSectionNode.d.ts.map +1 -0
- package/dist/nodes/GridContainerNode.d.ts +34 -0
- package/dist/nodes/GridContainerNode.d.ts.map +1 -0
- package/dist/nodes/GridEditNode.d.ts +9 -0
- package/dist/nodes/GridEditNode.d.ts.map +1 -0
- package/dist/nodes/HorizontalRuleNode.d.ts +19 -0
- package/dist/nodes/HorizontalRuleNode.d.ts.map +1 -0
- package/dist/nodes/ImageNode.d.ts +43 -0
- package/dist/nodes/ImageNode.d.ts.map +1 -0
- package/dist/nodes/KaTeXBlockNode.d.ts +24 -0
- package/dist/nodes/KaTeXBlockNode.d.ts.map +1 -0
- package/dist/nodes/KaTeXInlineNode.d.ts +22 -0
- package/dist/nodes/KaTeXInlineNode.d.ts.map +1 -0
- package/dist/nodes/LinkCardNode.d.ts +49 -0
- package/dist/nodes/LinkCardNode.d.ts.map +1 -0
- package/dist/nodes/MentionNode.d.ts +27 -0
- package/dist/nodes/MentionNode.d.ts.map +1 -0
- package/dist/nodes/MermaidNode.d.ts +24 -0
- package/dist/nodes/MermaidNode.d.ts.map +1 -0
- package/dist/nodes/SpoilerNode.d.ts +16 -0
- package/dist/nodes/SpoilerNode.d.ts.map +1 -0
- package/dist/nodes/TaskListItemNode.d.ts +21 -0
- package/dist/nodes/TaskListItemNode.d.ts.map +1 -0
- package/dist/nodes/VideoNode.d.ts +36 -0
- package/dist/nodes/VideoNode.d.ts.map +1 -0
- package/dist/nodes/index.d.ts +30 -0
- package/dist/nodes/index.d.ts.map +1 -0
- package/dist/nodes/shared.d.ts +3 -0
- package/dist/nodes/shared.d.ts.map +1 -0
- package/dist/plugins/AlertPlugin.d.ts +4 -0
- package/dist/plugins/AlertPlugin.d.ts.map +1 -0
- package/dist/plugins/AutoFocusPlugin.d.ts +2 -0
- package/dist/plugins/AutoFocusPlugin.d.ts.map +1 -0
- package/dist/plugins/AutoLinkPlugin.d.ts +7 -0
- package/dist/plugins/AutoLinkPlugin.d.ts.map +1 -0
- package/dist/plugins/DragDropPlugin.d.ts +2 -0
- package/dist/plugins/DragDropPlugin.d.ts.map +1 -0
- package/dist/plugins/EditorRefPlugin.d.ts +7 -0
- package/dist/plugins/EditorRefPlugin.d.ts.map +1 -0
- package/dist/plugins/FootnotePlugin.d.ts +4 -0
- package/dist/plugins/FootnotePlugin.d.ts.map +1 -0
- package/dist/plugins/HeadingAnchorPlugin.d.ts +2 -0
- package/dist/plugins/HeadingAnchorPlugin.d.ts.map +1 -0
- package/dist/plugins/ImagePlugin.d.ts +5 -0
- package/dist/plugins/ImagePlugin.d.ts.map +1 -0
- package/dist/plugins/ImageUploadPlugin.d.ts +14 -0
- package/dist/plugins/ImageUploadPlugin.d.ts.map +1 -0
- package/dist/plugins/KaTeXPlugin.d.ts +4 -0
- package/dist/plugins/KaTeXPlugin.d.ts.map +1 -0
- package/dist/plugins/MarkdownShortcutsPlugin.d.ts +2 -0
- package/dist/plugins/MarkdownShortcutsPlugin.d.ts.map +1 -0
- package/dist/plugins/MermaidPlugin.d.ts +3 -0
- package/dist/plugins/MermaidPlugin.d.ts.map +1 -0
- package/dist/plugins/OnChangePlugin.d.ts +8 -0
- package/dist/plugins/OnChangePlugin.d.ts.map +1 -0
- package/dist/plugins/SubmitShortcutPlugin.d.ts +6 -0
- package/dist/plugins/SubmitShortcutPlugin.d.ts.map +1 -0
- package/dist/plugins/index.d.ts +16 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/renderer.d.ts +3 -0
- package/dist/renderer.d.ts.map +1 -0
- package/dist/renderer.mjs +4 -0
- package/dist/rich-editor.css +1328 -0
- package/dist/styles/article.css.d.ts +3 -0
- package/dist/styles/article.css.d.ts.map +1 -0
- package/dist/styles/comment.css.d.ts +3 -0
- package/dist/styles/comment.css.d.ts.map +1 -0
- package/dist/styles/details.css.d.ts +2 -0
- package/dist/styles/details.css.d.ts.map +1 -0
- package/dist/styles/grid.css.d.ts +2 -0
- package/dist/styles/grid.css.d.ts.map +1 -0
- package/dist/styles/index.d.ts +7 -0
- package/dist/styles/index.d.ts.map +1 -0
- package/dist/styles/katex.css.d.ts +2 -0
- package/dist/styles/katex.css.d.ts.map +1 -0
- package/dist/styles/note.css.d.ts +3 -0
- package/dist/styles/note.css.d.ts.map +1 -0
- package/dist/styles/shared.css.d.ts +2 -0
- package/dist/styles/shared.css.d.ts.map +1 -0
- package/dist/styles/theme.d.ts +3 -0
- package/dist/styles/theme.d.ts.map +1 -0
- package/dist/styles/vars.css.d.ts +8 -0
- package/dist/styles/vars.css.d.ts.map +1 -0
- package/dist/transformers/alert.d.ts +3 -0
- package/dist/transformers/alert.d.ts.map +1 -0
- package/dist/transformers/container.d.ts +3 -0
- package/dist/transformers/container.d.ts.map +1 -0
- package/dist/transformers/footnote.d.ts +10 -0
- package/dist/transformers/footnote.d.ts.map +1 -0
- package/dist/transformers/index.d.ts +10 -0
- package/dist/transformers/index.d.ts.map +1 -0
- package/dist/transformers/insert.d.ts +6 -0
- package/dist/transformers/insert.d.ts.map +1 -0
- package/dist/transformers/katex.d.ts +4 -0
- package/dist/transformers/katex.d.ts.map +1 -0
- package/dist/transformers/mention.d.ts +3 -0
- package/dist/transformers/mention.d.ts.map +1 -0
- package/dist/transformers/spoiler.d.ts +3 -0
- package/dist/transformers/spoiler.d.ts.map +1 -0
- package/dist/transformers/tasklist.d.ts +11 -0
- package/dist/transformers/tasklist.d.ts.map +1 -0
- package/dist/types/renderer-config.d.ts +67 -0
- package/dist/types/renderer-config.d.ts.map +1 -0
- package/dist/types/slash-menu.d.ts +11 -0
- package/dist/types/slash-menu.d.ts.map +1 -0
- package/dist/types.d.ts +32 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/lucide-dom.d.ts +4 -0
- package/dist/utils/lucide-dom.d.ts.map +1 -0
- package/dist/utils/shiki.d.ts +6 -0
- package/dist/utils/shiki.d.ts.map +1 -0
- package/dist/utils/thumbhash.d.ts +7 -0
- package/dist/utils/thumbhash.d.ts.map +1 -0
- package/dist/utils-CctLX9nj.js +2702 -0
- package/package.json +88 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Innei
|
|
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
|
+
|
|
23
|
+
|
|
24
|
+
Additional Terms and Conditions
|
|
25
|
+
|
|
26
|
+
----------------
|
|
27
|
+
|
|
28
|
+
Use of this software is governed by the terms of MIT and, in addition, by the terms and conditions described in the additional file (ADDITIONAL_TERMS.md). By using this software, you agree to abide by these additional terms and conditions.
|
package/README.md
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# @haklex/rich-editor
|
|
2
|
+
|
|
3
|
+
基于 [Lexical](https://lexical.dev/) 的富文本编辑器,支持自定义节点、插件和 Markdown 快捷键。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @haklex/rich-editor lexical @lexical/react
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 使用
|
|
12
|
+
|
|
13
|
+
### 编辑器模式
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { RichEditor } from '@haklex/rich-editor'
|
|
17
|
+
import type { SerializedEditorState } from 'lexical'
|
|
18
|
+
|
|
19
|
+
function Editor() {
|
|
20
|
+
const [state, setState] = useState<SerializedEditorState | undefined>()
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<RichEditor
|
|
24
|
+
initialValue={state}
|
|
25
|
+
onChange={setState}
|
|
26
|
+
variant="article"
|
|
27
|
+
placeholder="开始写作..."
|
|
28
|
+
/>
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### 渲染器模式(只读)
|
|
34
|
+
|
|
35
|
+
```tsx
|
|
36
|
+
import { RichRenderer } from '@haklex/rich-editor/renderer'
|
|
37
|
+
import type { SerializedEditorState } from 'lexical'
|
|
38
|
+
|
|
39
|
+
function Renderer({ content }: { content: SerializedEditorState }) {
|
|
40
|
+
return (
|
|
41
|
+
<RichRenderer
|
|
42
|
+
value={content}
|
|
43
|
+
variant="article"
|
|
44
|
+
/>
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## 导出入口
|
|
50
|
+
|
|
51
|
+
| 路径 | 说明 |
|
|
52
|
+
|------|------|
|
|
53
|
+
| `@haklex/rich-editor` | 完整导出 |
|
|
54
|
+
| `@haklex/rich-editor/editor` | 仅 `RichEditor` |
|
|
55
|
+
| `@haklex/rich-editor/renderer` | 仅 `RichRenderer` |
|
|
56
|
+
| `@haklex/rich-editor/style.css` | 样式文件 |
|
|
57
|
+
|
|
58
|
+
## API
|
|
59
|
+
|
|
60
|
+
### RichEditorProps
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
interface RichEditorProps {
|
|
64
|
+
initialValue?: SerializedEditorState // 初始状态
|
|
65
|
+
onChange?: (value: SerializedEditorState) => void
|
|
66
|
+
variant?: 'article' | 'comment' | 'note' // 显示变体
|
|
67
|
+
theme?: 'light' | 'dark'
|
|
68
|
+
placeholder?: string
|
|
69
|
+
onSubmit?: () => void
|
|
70
|
+
autoFocus?: boolean
|
|
71
|
+
className?: string
|
|
72
|
+
contentClassName?: string
|
|
73
|
+
actions?: ReactNode
|
|
74
|
+
onEditorReady?: (editor: LexicalEditor | null) => void
|
|
75
|
+
extraNodes?: Array<Klass<LexicalNode>>
|
|
76
|
+
rendererConfig?: RendererConfig
|
|
77
|
+
debounceMs?: number
|
|
78
|
+
children?: ReactNode
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### RichRendererProps
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
interface RichRendererProps {
|
|
86
|
+
value: SerializedEditorState
|
|
87
|
+
variant?: 'article' | 'comment' | 'note'
|
|
88
|
+
theme?: 'light' | 'dark'
|
|
89
|
+
className?: string
|
|
90
|
+
as?: React.ElementType
|
|
91
|
+
rendererConfig?: RendererConfig
|
|
92
|
+
extraNodes?: Array<Klass<LexicalNode>>
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## 变体
|
|
97
|
+
|
|
98
|
+
| 变体 | 字体 | 字号 | 行高 | 用途 |
|
|
99
|
+
|------|------|------|------|------|
|
|
100
|
+
| `article` | 系统无衬线 | 16px | 1.7 | 博客文章 |
|
|
101
|
+
| `note` | 思源宋体 | 16px | 1.8 | 个人笔记 |
|
|
102
|
+
| `comment` | 系统无衬线 | 14px | 1.5 | 评论 |
|
|
103
|
+
|
|
104
|
+
## 自定义渲染器
|
|
105
|
+
|
|
106
|
+
```tsx
|
|
107
|
+
import type { RendererConfig } from '@haklex/rich-editor'
|
|
108
|
+
|
|
109
|
+
const customConfig: RendererConfig = {
|
|
110
|
+
Image: CustomImageRenderer,
|
|
111
|
+
CodeBlock: CustomCodeRenderer,
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
<RichRenderer value={content} rendererConfig={customConfig} />
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## 自定义节点
|
|
118
|
+
|
|
119
|
+
```tsx
|
|
120
|
+
import { RichEditor } from '@haklex/rich-editor'
|
|
121
|
+
import { MyCustomNode } from './nodes'
|
|
122
|
+
|
|
123
|
+
<RichEditor extraNodes={[MyCustomNode]} />
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## 主要导出
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
// 组件
|
|
130
|
+
export { RichEditor } from './components/RichEditor'
|
|
131
|
+
export { RichRenderer } from './components/RichRenderer'
|
|
132
|
+
|
|
133
|
+
// 节点配置
|
|
134
|
+
export { allNodes, builtinNodes, customNodes } from './config'
|
|
135
|
+
export { allEditNodes, customEditNodes } from './config-edit'
|
|
136
|
+
|
|
137
|
+
// Context
|
|
138
|
+
export { ColorSchemeProvider, useColorScheme } from './context/ColorSchemeContext'
|
|
139
|
+
export { useRendererConfig } from './context/RendererConfigContext'
|
|
140
|
+
|
|
141
|
+
// 类型
|
|
142
|
+
export type { RichEditorProps, RichRendererProps, RichEditorVariant } from './types'
|
|
143
|
+
export type { RendererConfig } from './types/renderer-config'
|
|
144
|
+
export type { SlashMenuItemConfig } from './types/slash-menu'
|
|
145
|
+
|
|
146
|
+
// 工具函数
|
|
147
|
+
export { createRendererDecoration } from './components/RendererWrapper'
|
|
148
|
+
export { getVariantClass } from './components/utils'
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## 依赖
|
|
152
|
+
|
|
153
|
+
```json
|
|
154
|
+
{
|
|
155
|
+
"lexical": "^0.39.0",
|
|
156
|
+
"@lexical/react": "^0.39.0",
|
|
157
|
+
"react": ">=19",
|
|
158
|
+
"react-dom": ">=19"
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## License
|
|
163
|
+
|
|
164
|
+
MIT
|