@haklex/rich-editor 0.0.65 → 0.0.66
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 +107 -300
- package/dist/AlertQuoteEditNode-AgVEMFEi.js +292 -0
- package/dist/KaTeXRenderer-C8jv_5xr.js +214 -0
- package/dist/LinkCardRenderer-QmkOlyXb.js +36 -0
- package/dist/{LinkFavicon-DpURZdO_.js → LinkFavicon-B9SOaYCR.js} +5 -24
- package/dist/MermaidPlugin-CIQbyjXF.js +97 -0
- package/dist/RubyRenderer-DbeobSoH.js +13 -0
- package/dist/SubmitShortcutPlugin-WQpet-vq.js +1512 -0
- package/dist/commands-entry.d.ts +9 -0
- package/dist/commands-entry.d.ts.map +1 -0
- package/dist/commands-entry.mjs +25 -0
- package/dist/components/ContentEditable.d.ts +2 -2
- package/dist/components/ContentEditable.d.ts.map +1 -1
- package/dist/components/CorePlugins.d.ts +2 -0
- package/dist/components/CorePlugins.d.ts.map +1 -0
- package/dist/components/LinkFavicon.d.ts.map +1 -1
- package/dist/components/RichEditor.d.ts +1 -1
- package/dist/components/RichEditor.d.ts.map +1 -1
- package/dist/components/RichEditorShell.d.ts +26 -0
- package/dist/components/RichEditorShell.d.ts.map +1 -0
- package/dist/components/decorators/AlertEditDecorator.d.ts +2 -2
- package/dist/components/decorators/AlertEditDecorator.d.ts.map +1 -1
- package/dist/components/decorators/BannerEditDecorator.d.ts +1 -1
- package/dist/components/decorators/BannerEditDecorator.d.ts.map +1 -1
- package/dist/components/decorators/CodeBlockEditDecorator.d.ts +2 -2
- package/dist/components/decorators/CodeBlockEditDecorator.d.ts.map +1 -1
- package/dist/components/decorators/GridEditDecorator.d.ts +2 -2
- package/dist/components/decorators/GridEditDecorator.d.ts.map +1 -1
- package/dist/components/renderers/AlertRenderer.d.ts +1 -1
- package/dist/components/renderers/AlertRenderer.d.ts.map +1 -1
- package/dist/components/renderers/AlertStaticDecorator.d.ts +1 -1
- package/dist/components/renderers/AlertStaticDecorator.d.ts.map +1 -1
- package/dist/components/renderers/BannerRenderer.d.ts +1 -1
- package/dist/components/renderers/BannerRenderer.d.ts.map +1 -1
- package/dist/components/renderers/BannerStaticDecorator.d.ts +1 -1
- package/dist/components/renderers/BannerStaticDecorator.d.ts.map +1 -1
- package/dist/components/renderers/CodeBlockRenderer.d.ts +5 -5
- package/dist/components/renderers/CodeBlockRenderer.d.ts.map +1 -1
- package/dist/components/renderers/FootnoteRenderer.d.ts.map +1 -1
- package/dist/components/renderers/FootnoteSectionEditRenderer.d.ts +1 -1
- package/dist/components/renderers/FootnoteSectionEditRenderer.d.ts.map +1 -1
- package/dist/components/renderers/FootnoteSectionRenderer.d.ts +1 -1
- package/dist/components/renderers/FootnoteSectionRenderer.d.ts.map +1 -1
- package/dist/components/renderers/FootnoteStaticRenderer.d.ts +1 -1
- package/dist/components/renderers/FootnoteStaticRenderer.d.ts.map +1 -1
- package/dist/components/renderers/GridStaticDecorator.d.ts +2 -2
- package/dist/components/renderers/GridStaticDecorator.d.ts.map +1 -1
- package/dist/components/renderers/ImageRenderer.d.ts +4 -4
- package/dist/components/renderers/ImageRenderer.d.ts.map +1 -1
- package/dist/components/renderers/KaTeXRenderer.d.ts +1 -1
- package/dist/components/renderers/KaTeXRenderer.d.ts.map +1 -1
- package/dist/components/renderers/LinkCardRenderer.d.ts +4 -4
- package/dist/components/renderers/LinkCardRenderer.d.ts.map +1 -1
- package/dist/components/renderers/MentionRenderer.d.ts +2 -2
- package/dist/components/renderers/MentionRenderer.d.ts.map +1 -1
- package/dist/components/renderers/RubyRenderer.d.ts +1 -1
- package/dist/components/renderers/RubyRenderer.d.ts.map +1 -1
- package/dist/components/renderers/VideoRenderer.d.ts +3 -3
- package/dist/components/renderers/VideoRenderer.d.ts.map +1 -1
- package/dist/config-QGdXDSW9.js +1235 -0
- package/dist/context/ImageUploadContext.d.ts.map +1 -1
- package/dist/context/RendererConfigContext.d.ts +1 -1
- package/dist/context/RendererConfigContext.d.ts.map +1 -1
- package/dist/favicon-BQgbXF_a.js +43 -0
- package/dist/index.d.ts +10 -80
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +151 -161
- package/dist/node-registry-CSRSWJ0q.js +765 -0
- package/dist/nodes/CodeBlockEditNode.d.ts +6 -6
- package/dist/nodes/DetailsNode.d.ts.map +1 -1
- package/dist/nodes/GridContainerNode.d.ts.map +1 -1
- package/dist/nodes/GridEditNode.d.ts.map +1 -1
- package/dist/nodes/ImageNode.d.ts +4 -4
- package/dist/nodes/ImageNode.d.ts.map +1 -1
- package/dist/nodes/LinkCardNode.d.ts +4 -4
- package/dist/nodes/LinkCardNode.d.ts.map +1 -1
- package/dist/nodes/VideoNode.d.ts +2 -2
- package/dist/nodes/VideoNode.d.ts.map +1 -1
- package/dist/nodes-entry.d.ts +28 -0
- package/dist/nodes-entry.d.ts.map +1 -0
- package/dist/nodes-entry.mjs +44 -0
- package/dist/plugins/AutoLinkPlugin.d.ts.map +1 -1
- package/dist/plugins/ImageUploadPlugin.d.ts +2 -2
- package/dist/plugins/ImageUploadPlugin.d.ts.map +1 -1
- package/dist/plugins/MarkdownPastePlugin.d.ts.map +1 -1
- package/dist/plugins/OnChangePlugin.d.ts +1 -1
- package/dist/plugins/OnChangePlugin.d.ts.map +1 -1
- package/dist/plugins/image-upload-command.d.ts.map +1 -1
- package/dist/plugins/image-upload.css.d.ts +1 -4
- package/dist/plugins/image-upload.css.d.ts.map +1 -1
- package/dist/plugins-entry.d.ts +22 -0
- package/dist/plugins-entry.d.ts.map +1 -0
- package/dist/plugins-entry.mjs +27 -0
- package/dist/renderers-entry.d.ts +23 -0
- package/dist/renderers-entry.d.ts.map +1 -0
- package/dist/renderers-entry.mjs +60 -0
- package/dist/rich-editor.css +1 -1
- package/dist/{utils-fpeaZV1R.js → shared.css-DNuMYx6Q.js} +4 -1
- package/dist/static-entry.mjs +23 -21
- package/dist/styles/article.css.d.ts.map +1 -1
- package/dist/styles-entry.mjs +1 -2
- package/dist/theme-CRza9nbF.js +924 -0
- package/dist/transformers/code-block.d.ts.map +1 -1
- package/dist/types/renderer-config.d.ts +6 -6
- package/dist/types/renderer-config.d.ts.map +1 -1
- package/dist/types/slash-menu.d.ts +6 -6
- package/dist/types/slash-menu.d.ts.map +1 -1
- package/dist/types.d.ts +18 -13
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/comment-anchor.d.ts +8 -8
- package/dist/utils/comment-anchor.d.ts.map +1 -1
- package/package.json +50 -33
- package/dist/RichEditor-EI3rR1-9.js +0 -2789
- package/dist/components/decorators/nested-doc-dialog.css.d.ts +0 -28
- package/dist/components/decorators/nested-doc-dialog.css.d.ts.map +0 -1
- package/dist/editor.d.ts +0 -6
- package/dist/editor.d.ts.map +0 -1
- package/dist/editor.mjs +0 -12
- package/dist/favicon-C6Esc0tp.js +0 -2470
- package/dist/shared.css-BqX4HjVE.js +0 -5
package/README.md
CHANGED
|
@@ -1,334 +1,141 @@
|
|
|
1
1
|
# @haklex/rich-editor
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
负责 `编辑态` 运行时、节点注册、插件装配、Markdown 快捷键与主题系统。
|
|
3
|
+
Core rich text editor based on Lexical. Provides the `RichEditor` component, all builtin and custom nodes, built-in plugins, and editor contexts.
|
|
5
4
|
|
|
6
|
-
##
|
|
7
|
-
|
|
8
|
-
- `@haklex/rich-editor`:编辑器核心(`RichEditor`)
|
|
9
|
-
- `@haklex/rich-static-renderer`:只读渲染引擎(`RichRenderer`)
|
|
10
|
-
- `@haklex/rich-renderers`:静态增强渲染器聚合(codeblock、image、video、mermaid...)
|
|
11
|
-
- `@haklex/rich-renderers-edit`:编辑增强渲染器与扩展插件聚合
|
|
12
|
-
- `@haklex/rich-kit-shiro`:一站式生产组合(编辑 + 渲染 + 常用扩展)
|
|
13
|
-
|
|
14
|
-
## 安装
|
|
5
|
+
## Installation
|
|
15
6
|
|
|
16
7
|
```bash
|
|
17
8
|
pnpm add @haklex/rich-editor lexical @lexical/react react react-dom
|
|
18
9
|
```
|
|
19
10
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
11
|
+
## Peer Dependencies
|
|
12
|
+
|
|
13
|
+
| Package | Version | Required |
|
|
14
|
+
| --- | --- | --- |
|
|
15
|
+
| `@base-ui/react` | `^1.1.0` | Yes |
|
|
16
|
+
| `@lexical/code` | `^0.41.0` | Yes |
|
|
17
|
+
| `@lexical/extension` | `^0.41.0` | Yes |
|
|
18
|
+
| `@lexical/link` | `^0.41.0` | Yes |
|
|
19
|
+
| `@lexical/list` | `^0.41.0` | Yes |
|
|
20
|
+
| `@lexical/markdown` | `^0.41.0` | Yes |
|
|
21
|
+
| `@lexical/react` | `^0.41.0` | Yes |
|
|
22
|
+
| `@lexical/rich-text` | `^0.41.0` | Yes |
|
|
23
|
+
| `@lexical/table` | `^0.41.0` | Yes |
|
|
24
|
+
| `lexical` | `^0.41.0` | Yes |
|
|
25
|
+
| `lucide-react` | `^0.574.0` | Yes |
|
|
26
|
+
| `react` | `>=19` | Yes |
|
|
27
|
+
| `react-dom` | `>=19` | Yes |
|
|
28
|
+
| `katex` | `>=0.16.0` | Optional |
|
|
29
|
+
| `shiki` | `^3.0.0` | Optional |
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
26
32
|
|
|
27
33
|
```tsx
|
|
28
34
|
import { RichEditor } from '@haklex/rich-editor'
|
|
29
|
-
import type { SerializedEditorState } from 'lexical'
|
|
30
|
-
import { useState } from 'react'
|
|
31
35
|
import '@haklex/rich-editor/style.css'
|
|
32
36
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
initialValue={value}
|
|
39
|
-
onChange={setValue}
|
|
40
|
-
variant="article"
|
|
41
|
-
theme="light"
|
|
42
|
-
placeholder="Write something..."
|
|
43
|
-
onSubmit={() => {
|
|
44
|
-
// Cmd/Ctrl + Enter
|
|
45
|
-
}}
|
|
46
|
-
/>
|
|
47
|
-
)
|
|
48
|
-
}
|
|
37
|
+
<RichEditor
|
|
38
|
+
variant="article"
|
|
39
|
+
initialValue={savedState}
|
|
40
|
+
onChange={(value) => save(value)}
|
|
41
|
+
/>
|
|
49
42
|
```
|
|
50
43
|
|
|
51
|
-
|
|
44
|
+
For read-only rendering, use `@haklex/rich-static-renderer` instead.
|
|
52
45
|
|
|
53
|
-
|
|
54
|
-
import { RichRenderer } from '@haklex/rich-static-renderer'
|
|
46
|
+
## Exports
|
|
55
47
|
|
|
56
|
-
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
## 数据格式
|
|
60
|
-
|
|
61
|
-
`onChange` 返回的是 `SerializedEditorState`(Lexical JSON),推荐直接落库。
|
|
62
|
-
`initialValue` 直接喂回这个 JSON,可以做到无损回显。
|
|
48
|
+
### Components
|
|
63
49
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
| 入口 | 说明 |
|
|
50
|
+
| Export | Description |
|
|
67
51
|
| --- | --- |
|
|
68
|
-
|
|
|
69
|
-
|
|
|
70
|
-
|
|
|
71
|
-
|
|
|
72
|
-
| `@haklex/rich-editor/style.css` | 打包后的编辑器样式 |
|
|
73
|
-
|
|
74
|
-
## RichEditor API
|
|
75
|
-
|
|
76
|
-
```ts
|
|
77
|
-
type RichEditorVariant = 'article' | 'comment' | 'note'
|
|
78
|
-
|
|
79
|
-
interface RichEditorProps {
|
|
80
|
-
initialValue?: SerializedEditorState
|
|
81
|
-
onChange?: (value: SerializedEditorState) => void
|
|
82
|
-
variant?: RichEditorVariant
|
|
83
|
-
theme?: 'light' | 'dark'
|
|
84
|
-
placeholder?: string
|
|
85
|
-
onSubmit?: () => void
|
|
86
|
-
autoFocus?: boolean
|
|
87
|
-
className?: string
|
|
88
|
-
contentClassName?: string
|
|
89
|
-
style?: React.CSSProperties
|
|
90
|
-
actions?: ReactNode
|
|
91
|
-
onEditorReady?: (editor: LexicalEditor | null) => void
|
|
92
|
-
extraNodes?: Array<Klass<LexicalNode>>
|
|
93
|
-
rendererConfig?: RendererConfig
|
|
94
|
-
imageUpload?: ImageUploadFn
|
|
95
|
-
debounceMs?: number
|
|
96
|
-
children?: ReactNode
|
|
97
|
-
}
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
关键字段说明:
|
|
101
|
-
|
|
102
|
-
- `extraNodes`:注册你自己的 Lexical 节点(扩展节点必配)
|
|
103
|
-
- `rendererConfig`:覆写默认渲染器(如 Image/CodeBlock/LinkCard)
|
|
104
|
-
- `actions`:插在编辑器底部 actions 区域(常用于 Slash 菜单)
|
|
105
|
-
- `children`:插件插槽(如 `EmbedPlugin`、`TldrawPlugin`)
|
|
106
|
-
- `imageUpload`:替换默认图片上传逻辑
|
|
107
|
-
- `debounceMs`:`onChange` 的防抖间隔(毫秒)
|
|
108
|
-
|
|
109
|
-
## RendererConfig API
|
|
110
|
-
|
|
111
|
-
```ts
|
|
112
|
-
interface RendererConfig {
|
|
113
|
-
Alert?: ComponentType<AlertRendererProps>
|
|
114
|
-
Banner?: ComponentType<BannerRendererProps>
|
|
115
|
-
CodeBlock?: ComponentType<CodeBlockRendererProps>
|
|
116
|
-
CodeSnippet?: ComponentType<CodeSnippetRendererProps>
|
|
117
|
-
Footnote?: ComponentType<FootnoteRendererProps>
|
|
118
|
-
FootnoteSection?: ComponentType<FootnoteSectionRendererProps>
|
|
119
|
-
Gallery?: ComponentType<GalleryRendererProps>
|
|
120
|
-
Image?: ComponentType<ImageRendererProps>
|
|
121
|
-
KaTeX?: ComponentType<KaTeXRendererProps>
|
|
122
|
-
LinkCard?: ComponentType<LinkCardRendererProps>
|
|
123
|
-
Mermaid?: ComponentType<MermaidRendererProps>
|
|
124
|
-
Mention?: ComponentType<MentionRendererProps>
|
|
125
|
-
Video?: ComponentType<VideoRendererProps>
|
|
126
|
-
}
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
示例:覆写图片与代码块渲染器
|
|
130
|
-
|
|
131
|
-
```tsx
|
|
132
|
-
import type { RendererConfig } from '@haklex/rich-editor'
|
|
133
|
-
|
|
134
|
-
const rendererConfig: RendererConfig = {
|
|
135
|
-
Image: MyImageRenderer,
|
|
136
|
-
CodeBlock: MyCodeBlockRenderer,
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
<RichEditor rendererConfig={rendererConfig} />
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
## 内置节点与插件
|
|
143
|
-
|
|
144
|
-
默认内置节点(`config.ts` / `config-edit.ts`):
|
|
145
|
-
|
|
146
|
-
- 内置 Lexical 节点:Heading、Quote、List、Link、Table、Code、HorizontalRule...
|
|
147
|
-
- 自定义节点:Spoiler、Mention、KaTeXInline、KaTeXBlock、Image、Alert、CodeBlock、Footnote、FootnoteSection、Video、LinkCard、Details、Grid、Banner、Mermaid
|
|
148
|
-
|
|
149
|
-
`RichEditor` 默认挂载插件:
|
|
150
|
-
|
|
151
|
-
- 历史/列表/链接/表格:`HistoryPlugin`、`ListPlugin`、`LinkPlugin`、`TablePlugin`
|
|
152
|
-
- 编辑增强:`MarkdownShortcutsPlugin`、`CheckListPlugin`、`AutoLinkPlugin`
|
|
153
|
-
- 内容能力:`ImagePlugin`、`ImageUploadPlugin`、`KaTeXPlugin`、`AlertPlugin`、`MermaidPlugin`、`HorizontalRulePlugin`
|
|
154
|
-
- 生命周期:`OnChangePlugin`、`EditorRefPlugin`、`SubmitShortcutPlugin`(Cmd/Ctrl+Enter)、`AutoFocusPlugin`
|
|
155
|
-
|
|
156
|
-
## 常用命令导出
|
|
157
|
-
|
|
158
|
-
```ts
|
|
159
|
-
INSERT_ALERT_COMMAND
|
|
160
|
-
INSERT_IMAGE_COMMAND
|
|
161
|
-
OPEN_IMAGE_UPLOAD_DIALOG_COMMAND
|
|
162
|
-
INSERT_KATEX_INLINE_COMMAND
|
|
163
|
-
INSERT_KATEX_BLOCK_COMMAND
|
|
164
|
-
INSERT_MERMAID_COMMAND
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
可在自定义插件中 `editor.dispatchCommand(...)` 触发。
|
|
168
|
-
|
|
169
|
-
## Markdown Transformer
|
|
170
|
-
|
|
171
|
-
导出:`ALL_TRANSFORMERS`(`src/transformers`)
|
|
172
|
-
|
|
173
|
-
覆盖能力包括:
|
|
174
|
-
|
|
175
|
-
- Inline:Spoiler、Mention、Footnote、`++underline++`、上/下标、KaTeX inline
|
|
176
|
-
- Block:FootnoteSection、Container(Banner/Details)、Git Alert、KaTeX block、Image/Video/CodeBlock/LinkCard/Mermaid/Grid/Table/HR + Lexical 默认 transformers
|
|
177
|
-
|
|
178
|
-
参考:`docs/export-format-summary.md`
|
|
179
|
-
|
|
180
|
-
## 设计模式
|
|
181
|
-
|
|
182
|
-
### 1) Static / Edit 节点分离
|
|
52
|
+
| `RichEditor` | Main editor component |
|
|
53
|
+
| `ColorSchemeProvider` | Context provider for light/dark theme |
|
|
54
|
+
| `FootnoteDefinitionsProvider` | Context provider for footnote definitions |
|
|
55
|
+
| `NestedContentRendererProvider` | Context provider for nested content rendering |
|
|
183
56
|
|
|
184
|
-
|
|
57
|
+
### Node Registries
|
|
185
58
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
节点内部通过 `createRendererDecoration(...)` 把渲染职责交给 `RendererConfig`,实现:
|
|
194
|
-
|
|
195
|
-
- 默认渲染器可直接用
|
|
196
|
-
- 业务侧可按 key 定向覆写
|
|
197
|
-
- 保持节点协议不变
|
|
198
|
-
|
|
199
|
-
### 3) Command + Plugin 模式
|
|
200
|
-
|
|
201
|
-
扩展插入动作统一走 `createCommand` + `registerCommand`,避免 UI 与文档结构硬耦合。
|
|
202
|
-
|
|
203
|
-
## 扩展编写与接入
|
|
204
|
-
|
|
205
|
-
下面是可直接复用的扩展落地流程。
|
|
206
|
-
|
|
207
|
-
### 步骤 1:定义 Node(静态)
|
|
208
|
-
|
|
209
|
-
```tsx
|
|
210
|
-
import type {
|
|
211
|
-
EditorConfig,
|
|
212
|
-
LexicalEditor,
|
|
213
|
-
LexicalNode,
|
|
214
|
-
NodeKey,
|
|
215
|
-
SerializedLexicalNode,
|
|
216
|
-
Spread,
|
|
217
|
-
} from 'lexical'
|
|
218
|
-
import { DecoratorNode } from 'lexical'
|
|
219
|
-
import type { ReactElement } from 'react'
|
|
220
|
-
import { createElement } from 'react'
|
|
221
|
-
|
|
222
|
-
import { PollRenderer } from './PollRenderer'
|
|
223
|
-
|
|
224
|
-
type SerializedPollNode = Spread<
|
|
225
|
-
{ question: string },
|
|
226
|
-
SerializedLexicalNode
|
|
227
|
-
>
|
|
228
|
-
|
|
229
|
-
export class PollNode extends DecoratorNode<ReactElement> {
|
|
230
|
-
__question: string
|
|
231
|
-
|
|
232
|
-
static getType() {
|
|
233
|
-
return 'poll'
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
static clone(node: PollNode) {
|
|
237
|
-
return new PollNode(node.__question, node.__key)
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
constructor(question: string, key?: NodeKey) {
|
|
241
|
-
super(key)
|
|
242
|
-
this.__question = question
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
createDOM(_config: EditorConfig) {
|
|
246
|
-
const el = document.createElement('div')
|
|
247
|
-
el.className = 'rich-poll-wrapper'
|
|
248
|
-
return el
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
updateDOM() {
|
|
252
|
-
return false
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
isInline() {
|
|
256
|
-
return false
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
static importJSON(json: SerializedPollNode) {
|
|
260
|
-
return new PollNode(json.question)
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
exportJSON(): SerializedPollNode {
|
|
264
|
-
return {
|
|
265
|
-
...super.exportJSON(),
|
|
266
|
-
type: 'poll',
|
|
267
|
-
question: this.__question,
|
|
268
|
-
version: 1,
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
decorate(_editor: LexicalEditor, _config: EditorConfig): ReactElement {
|
|
273
|
-
return createElement(PollRenderer, {
|
|
274
|
-
question: this.__question,
|
|
275
|
-
})
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
export function $isPollNode(
|
|
280
|
-
node: LexicalNode | null | undefined,
|
|
281
|
-
): node is PollNode {
|
|
282
|
-
return node instanceof PollNode
|
|
283
|
-
}
|
|
284
|
-
```
|
|
285
|
-
|
|
286
|
-
说明:`RendererConfig` 只能覆写预定义 key。
|
|
287
|
-
像 `Poll` 这种全新节点,一般采用“节点内直接渲染组件”或自定义 context 的方式。
|
|
288
|
-
|
|
289
|
-
### 步骤 2:可选编辑态 Node
|
|
290
|
-
|
|
291
|
-
如果编辑态需要重 UI,可以 `class PollEditNode extends PollNode` 并覆写 `decorate()`。
|
|
292
|
-
|
|
293
|
-
还可以定义 slash 菜单项:
|
|
294
|
-
|
|
295
|
-
```ts
|
|
296
|
-
static slashMenuItems = [
|
|
297
|
-
{
|
|
298
|
-
title: 'Poll',
|
|
299
|
-
description: 'Insert a poll block',
|
|
300
|
-
section: 'MEDIA',
|
|
301
|
-
onSelect: (editor) => { ... },
|
|
302
|
-
},
|
|
303
|
-
]
|
|
304
|
-
```
|
|
59
|
+
| Export | Description |
|
|
60
|
+
| --- | --- |
|
|
61
|
+
| `allNodes` | All static nodes (builtin + custom) |
|
|
62
|
+
| `builtinNodes` | Lexical builtin nodes only |
|
|
63
|
+
| `customNodes` | Custom static nodes only |
|
|
64
|
+
| `allEditNodes` | All edit-mode nodes (builtin + custom edit) |
|
|
65
|
+
| `customEditNodes` | Custom edit-mode nodes only |
|
|
305
66
|
|
|
306
|
-
###
|
|
67
|
+
### Node Classes
|
|
307
68
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
69
|
+
| Export | Description |
|
|
70
|
+
| --- | --- |
|
|
71
|
+
| `MermaidNode`, `$createMermaidNode`, `$isMermaidNode` | Mermaid diagram node |
|
|
72
|
+
| `RubyNode`, `$createRubyNode`, `$isRubyNode` | Ruby annotation node |
|
|
73
|
+
| `GridContainerNode`, `$createGridContainerNode`, `$isGridContainerNode` | Grid layout container |
|
|
74
|
+
| `FootnoteSectionNode`, `$createFootnoteSectionNode`, `$isFootnoteSectionNode` | Footnote section node |
|
|
75
|
+
| `FootnoteSectionEditNode` | Footnote section edit-mode node |
|
|
76
|
+
| `ImageNode`, `$createImageNode`, `$isImageNode` | Image node |
|
|
77
|
+
| `LinkCardNode`, `$createLinkCardNode`, `$isLinkCardNode` | Link card node |
|
|
78
|
+
| `KaTeXBlockNode`, `$isKaTeXBlockNode` | KaTeX block equation node |
|
|
79
|
+
| `KaTeXInlineNode`, `$isKaTeXInlineNode` | KaTeX inline equation node |
|
|
80
|
+
| `MentionNode`, `$createMentionNode`, `$isMentionNode` | Mention node |
|
|
81
|
+
|
|
82
|
+
### Plugins
|
|
83
|
+
|
|
84
|
+
| Export | Description |
|
|
85
|
+
| --- | --- |
|
|
86
|
+
| `AutoLinkPlugin` | Automatic link detection |
|
|
87
|
+
| `BlockExitPlugin` | Exit block nodes with Enter/arrow keys |
|
|
88
|
+
| `HorizontalRulePlugin` | Horizontal rule insertion |
|
|
89
|
+
| `ImagePlugin` | Image node handling |
|
|
90
|
+
| `ImageUploadPlugin` | Image upload dialog and logic |
|
|
91
|
+
| `KaTeXPlugin` | KaTeX equation insertion |
|
|
92
|
+
| `LinkFaviconPlugin` | Favicon resolution for links |
|
|
93
|
+
| `MarkdownShortcutsPlugin` | Markdown syntax shortcuts |
|
|
94
|
+
| `MermaidPlugin` | Mermaid diagram insertion |
|
|
95
|
+
| `FootnotePlugin` | Footnote insertion and management |
|
|
96
|
+
|
|
97
|
+
### Commands
|
|
98
|
+
|
|
99
|
+
| Export | Description |
|
|
100
|
+
| --- | --- |
|
|
101
|
+
| `INSERT_ALERT_COMMAND` | Insert an alert/callout block |
|
|
102
|
+
| `INSERT_IMAGE_COMMAND` | Insert an image node |
|
|
103
|
+
| `OPEN_IMAGE_UPLOAD_DIALOG_COMMAND` | Open the image upload dialog |
|
|
104
|
+
| `INSERT_KATEX_BLOCK_COMMAND` | Insert a KaTeX block equation |
|
|
105
|
+
| `INSERT_KATEX_INLINE_COMMAND` | Insert a KaTeX inline equation |
|
|
106
|
+
| `INSERT_MERMAID_COMMAND` | Insert a Mermaid diagram |
|
|
311
107
|
|
|
312
|
-
|
|
108
|
+
### Utilities
|
|
313
109
|
|
|
314
|
-
|
|
315
|
-
|
|
110
|
+
| Export | Description |
|
|
111
|
+
| --- | --- |
|
|
112
|
+
| `extractTextContent` | Extract plain text from editor state |
|
|
113
|
+
| `collectCommandItems` | Collect slash menu / toolbar command items |
|
|
114
|
+
| `computeImageMeta` | Compute thumbhash and dimensions for an image |
|
|
115
|
+
| `decodeThumbHash` | Decode a thumbhash string to a data URL |
|
|
116
|
+
| `createRendererDecoration` | Create a renderer decoration for decorator nodes |
|
|
117
|
+
| `getVariantClass` | Get the CSS class for a variant |
|
|
118
|
+
| `defaultImageUpload` | Default image upload implementation |
|
|
119
|
+
| `buildBlockAnchor`, `buildRangeAnchor` | Comment anchor utilities |
|
|
120
|
+
| `ALL_TRANSFORMERS` | All Markdown transformers (inline + block) |
|
|
316
121
|
|
|
317
|
-
###
|
|
122
|
+
### Types
|
|
318
123
|
|
|
319
|
-
|
|
320
|
-
import { createCommand } from 'lexical'
|
|
124
|
+
`RichEditorProps`, `RichEditorVariant`, `RendererConfig`, `ColorScheme`, `RendererMode`, `ImageUploadFn`, `ImageUploadResult`, `CommandItemConfig`, `SlashMenuItemConfig`, `ToolbarGroup`, `CommandPlacement`, and renderer prop types (`AlertRendererProps`, `ImageRendererProps`, `CodeBlockRendererProps`, etc.).
|
|
321
125
|
|
|
322
|
-
|
|
323
|
-
```
|
|
126
|
+
### Sub-path Exports
|
|
324
127
|
|
|
325
|
-
|
|
128
|
+
| Import Path | Description |
|
|
129
|
+
| --- | --- |
|
|
130
|
+
| `@haklex/rich-editor` | Full export (components, nodes, plugins, commands, contexts, types) |
|
|
131
|
+
| `@haklex/rich-editor/editor` | Editor-specific entry (RichEditor + node configs) |
|
|
132
|
+
| `@haklex/rich-editor/static` | Static/SSR utilities (for renderer and extension packages) |
|
|
133
|
+
| `@haklex/rich-editor/styles` | Style variables and variant class exports |
|
|
134
|
+
| `@haklex/rich-editor/style.css` | Compiled editor stylesheet |
|
|
326
135
|
|
|
327
|
-
##
|
|
136
|
+
## Part of Haklex
|
|
328
137
|
|
|
329
|
-
|
|
330
|
-
- 要增强编辑态:`@haklex/rich-renderers-edit`
|
|
331
|
-
- 想直接开箱即用:`@haklex/rich-kit-shiro`
|
|
138
|
+
This package is part of the [Haklex](../../README.md) rich editor ecosystem.
|
|
332
139
|
|
|
333
140
|
## License
|
|
334
141
|
|