API
createPlateEditor
生成一个新的 PlateEditor
实例,使用一组插件及其配置进行初始化。
id optional any
编辑器的唯一标识符。
editor optional E
未应用
withPlate
的初始编辑器。plugins optional P[]
编辑器插件数组。
value optional V
编辑器的初始值。
autoSelect optional 'end' | 'start' | boolean
初始化后是否选中编辑器。
- 默认值:
false
true
| 'end': 选中编辑器末尾false
: 不选中任何内容'start'
: 选中编辑器开头
- 默认值:
maxLength optional number
指定编辑器中允许的最大字符数。
nodeId optional object | boolean
自动节点 ID 生成和管理的配置。
selection optional TSelection
编辑器的初始选区。
shouldNormalizeEditor optional boolean
当
true
时,将规范化传递给editor
的初始value
。- 默认值:
false
- 默认值:
rootPlugin optional (plugin: AnyPlatePlugin) => AnyPlatePlugin
配置根插件的函数。
api optional object
编辑器的 API 方法。
decorate optional function
编辑器的装饰函数。
extendEditor optional function
扩展编辑器的函数。
handlers optional object
编辑器的事件处理器。
inject optional object
编辑器的注入配置。
normalizeInitialValue optional function
规范化初始值的函数。
options optional object
编辑器的附加选项。
override optional object
编辑器的覆盖配置。
priority optional number
编辑器插件的优先级。
readOnly optional boolean
编辑器的只读初始状态。对于动态值,使用
Plate.readOnly
属性。render optional object
编辑器的渲染函数。
shortcuts optional object
编辑器的键盘快捷键。
transforms optional object
编辑器的转换函数。
useHooks optional function
与编辑器一起使用的钩子。
有关编辑器配置的更多详情,请参阅编辑器配置指南。
createPlatePlugin
使用给定配置创建一个新的 Plate 插件,支持扩展、嵌套插件操作和运行时配置。
config PlatePluginConfig | ((editor: PlateEditor) => PlatePluginConfig)
插件的配置对象,或返回配置的函数。如果提供函数,将在解析插件时使用编辑器执行该函数。
有关
PlatePluginConfig
类型的详情,请参阅PlatePlugin API。
createTPlatePlugin
createPlatePlugin
的显式类型版本。
config TPlatePluginConfig<C> | ((editor: PlateEditor) => TPlatePluginConfig<C>)
插件的配置对象,或返回配置的函数。此版本需要显式类型参数
C
扩展AnyPluginConfig
。有关
TPlatePluginConfig
类型的详情,请参阅PlatePlugin API。
toPlatePlugin
扩展 SlatePlugin 以创建 React PlatePlugin。
toTPlatePlugin
toPlatePlugin
的显式类型版本。
useEditorContainerRef
useEditorScrollRef
useScrollRef
useEditorPlugin
获取编辑器和插件上下文。
useEditorRef
获取 Plate 编辑器引用而不重新渲染。返回的编辑器对象增强了 store
属性,提供对 Plate 存储的访问。
useEditorSelector
订阅编辑器的特定属性。
useEditorState
获取带重新渲染的 Plate 编辑器引用。
useEditorComposing
获取编辑器的 composing
状态。
useEditorReadOnly
获取编辑器的 readOnly
状态。
useEditorMounted
获取编辑器的 isMounted
状态。
useEditorSelection
获取编辑器的选区。已记忆化,如果范围相同则不会重新渲染。
useEditorVersion
获取编辑器值的版本。每次编辑器更改时该版本都会递增。
useSelectionVersion
获取编辑器选区的版本。每次选区更改(范围不同)时该版本都会递增。
useSelectionCollapsed
useSelectionExpanded
useSelectionWithinBlock
useSelectionAcrossBlocks
useSelectionFragment
返回当前选区的片段,可选择解构结构节点。
useSelectionFragmentProp
返回从当前选区片段派生的属性值。
useNodePath
返回编辑器中节点的路径。
usePath
获取最近元素的记忆化路径。
usePluginOption
用于从插件存储访问插件选项的 Hook。用于 <Plate>
内部。
// 访问简单选项
const value = usePluginOption(plugin, 'value');
// 使用参数访问选择器
const doubleValue = usePluginOption(plugin, 'doubleValue', 2);
// 使用相等函数访问
const value = usePluginOption(plugin, 'value', (a, b) => a === b);
// 访问整个状态
const state = usePluginOption(plugin, 'state');
useEditorPluginOption
用于从插件存储访问插件选项的 Hook。用于 <Plate>
外部。
// 访问简单选项
const value = useEditorPluginOption(editor, plugin, 'value');
// 使用参数访问选择器
const doubleValue = useEditorPluginOption(editor, plugin, 'doubleValue', 2);
// 使用相等函数访问
const value = useEditorPluginOption(editor, plugin, 'value', (a, b) => a === b);
// 访问整个状态
const state = useEditorPluginOption(editor, plugin, 'state');
useElement
通过插件键获取元素。
核心插件
DebugPlugin
提供具有可配置日志级别和错误处理功能的调试功能。
查看调试了解更多详情。
SlateExtensionPlugin & SlateReactExtensionPlugin
扩展核心 API 并改进默认功能。
DOMPlugin & ReactPlugin
将 React 特定功能集成到编辑器中。
HistoryPlugin
为编辑器启用撤销和重做功能。
InlineVoidPlugin
管理编辑器中的内联和空元素。
ParserPlugin
处理编辑器内容的解析。
LengthPlugin
强制执行编辑器内容的最大长度限制。
HtmlPlugin
启用 HTML 序列化和反序列化。
AstPlugin
处理编辑器的抽象语法树(AST)操作。
ParagraphPlugin
提供段落格式化功能。
EventEditorPlugin
管理编辑器事件,如焦点和失焦。
工具函数
isType
检查节点是否匹配提供的类型。
组件
<PlateElement>
用于渲染元素的通用组件。
<PlateLeaf>
用于渲染叶节点的通用组件。
<PlateText>
用于渲染文本的通用组件。
On This Page
APIcreatePlateEditor
createPlatePlugin
createTPlatePlugin
toPlatePlugin
toTPlatePlugin
useEditorContainerRef
useEditorScrollRef
useScrollRef
useEditorPlugin
useEditorRef
useEditorSelector
useEditorState
useEditorComposing
useEditorReadOnly
useEditorMounted
useEditorSelection
useEditorVersion
useSelectionVersion
useSelectionCollapsed
useSelectionExpanded
useSelectionWithinBlock
useSelectionAcrossBlocks
useSelectionFragment
useSelectionFragmentProp
useNodePath
usePath
usePluginOption
useEditorPluginOption
useElement
核心插件DebugPlugin
SlateExtensionPlugin & SlateReactExtensionPlugin
DOMPlugin & ReactPlugin
HistoryPlugin
InlineVoidPlugin
ParserPlugin
LengthPlugin
HtmlPlugin
AstPlugin
ParagraphPlugin
EventEditorPlugin
工具函数isType
组件<PlateElement>
<PlateLeaf>
<PlateText>