docs/(plugins)/(styles)/indent.cn.mdx
indent 属性。添加缩进功能最快的方法是使用 IndentKit,它包含预配置的 IndentPlugin,针对段落、标题、引用块、代码块和切换元素。
Paragraph、Heading、Blockquote、CodeBlock 和 Toggle 元素以支持 indent 属性。24px。将 kit 添加到你的插件中:
import { createPlateEditor } from 'platejs/react';
import { IndentKit } from '@/components/editor/plugins/indent-kit';
const editor = createPlateEditor({
plugins: [
// ...otherPlugins,
...IndentKit,
],
});
npm install @platejs/indent
在创建编辑器时,将 IndentPlugin 包含在你的 Plate 插件数组中。
import { IndentPlugin } from '@platejs/indent/react';
import { createPlateEditor } from 'platejs/react';
const editor = createPlateEditor({
plugins: [
// ...otherPlugins,
IndentPlugin,
],
});
你可以配置 IndentPlugin 以针对特定元素并自定义缩进行为。
import { IndentPlugin } from '@platejs/indent/react';
import { KEYS } from 'platejs';
import { createPlateEditor } from 'platejs/react';
const editor = createPlateEditor({
plugins: [
// ...otherPlugins,
IndentPlugin.configure({
inject: {
nodeProps: {
styleKey: 'marginLeft',
},
targetPlugins: [...KEYS.heading, KEYS.p, KEYS.blockquote],
},
options: {
offset: 24,
unit: 'px',
indentMax: 10,
},
}),
],
});
inject.nodeProps.styleKey:将注入的属性映射到 CSS marginLeft 属性。inject.targetPlugins:一个插件键数组,指示哪些元素类型可以缩进。options.offset:缩进偏移量(像素)(默认:24)。options.unit:缩进值的单位(默认:'px')。options.indentMax:允许的最大缩进次数。你可以将 IndentToolbarButton 添加到你的工具栏中以控制缩进。
IndentPlugin用于缩进块级元素的插件。它向 inject.targetPlugins 指定的元素注入 indent 属性并应用 marginLeft 样式。
indent缩进编辑器中的选定块。
<API name="indent"> <APIOptions type="SetIndentOptions" optional> 用于缩进块的选项。 </APIOptions> </API>outdent减少选定块的缩进。
<API name="outdent"> <APIOptions type="SetIndentOptions" optional> 用于取消缩进块的选项。 </APIOptions> </API>setIndent为选定的块添加缩进偏移量。
<API name="setIndent"> <APIOptions type="SetIndentOptions"> <APIItem name="offset" type="number" optional> 在 `(offset * element.indent) + unit` 中使用的缩进偏移量。 - **默认值:** `1` </APIItem> <APIItem name="getNodesOptions" type="EditorNodesOptions" optional> 获取要缩进的节点的选项。 </APIItem> <APIItem name="setNodesProps" type="object" optional> 要设置到要缩进的节点上的其他属性。 </APIItem> <APIItem name="unsetNodesProps" type="string[]" optional> 要从未缩进的节点上取消设置的其他属性。 - **默认值:** `[]` </APIItem> </APIOptions> </API>SetIndentOptions用于提供设置文本块缩进的选项。
<API name="SetIndentOptions"> <APIOptions> <APIItem name="offset" type="number"> 缩进的变化(1 表示缩进,-1 表示取消缩进)。 - **默认值:** `1` </APIItem> <APIItem name="getNodesOptions" type="EditorNodesOptions<V>"> 额外的 `getNodes` 选项。 </APIItem> <APIItem name="setNodesProps" type="object"> 额外的 `setNodes` 选项。 </APIItem> <APIItem name="unsetNodesProps" type="string[]"> 当缩进为 0 时要取消设置的属性。 </APIItem> </APIOptions> </API>useIndentButton缩进按钮组件的行为 hook。
<API name="useIndentButton"> <APIReturns type="object"> <APIItem name="props" type="object"> 缩进按钮的属性。 <APISubList> <APISubListItem parent="props" name="onClick" type="function"> 处理点击事件的回调。缩进选定的内容并聚焦编辑器。 </APISubListItem> </APISubList> </APIItem> </APIReturns> </API>useOutdentButton取消缩进按钮组件的行为 hook。
<API name="useOutdentButton"> <APIReturns type="object"> <APIItem name="props" type="object"> 取消缩进按钮的属性。 <APISubList> <APISubListItem parent="props" name="onClick" type="function"> 处理点击事件的回调。取消选定内容的缩进并聚焦编辑器。 </APISubListItem> </APISubList> </APIItem> </APIReturns> </API>