Trailing Block

Ensure a trailing block is always present in the document.

Loading...
Files
components/demo.tsx
'use client';

import React from 'react';

import { Plate } from '@udecode/plate-common/react';

import { editorPlugins } from '@/components/editor/plugins/editor-plugins';
import { useCreateEditor } from '@/components/editor/use-create-editor';
import { Editor, EditorContainer } from '@/components/plate-ui/editor';

import { DEMO_VALUES } from './values/demo-values';

export default function Demo({ id }: { id: string }) {
  const editor = useCreateEditor({
    plugins: [...editorPlugins],
    value: DEMO_VALUES[id],
  });

  return (
    <Plate editor={editor}>
      <EditorContainer variant="demo">
        <Editor />
      </EditorContainer>
    </Plate>
  );
}

功能

  • 确保在文档末尾始终存在特定类型的块。

安装

npm install @udecode/plate-trailing-block

Usage

import { TrailingBlockPlugin } from '@udecode/plate-trailing-block';
const plugins = [
  // ...其他插件,
  TrailingBlockPlugin.configure({
    options: {
      level: 0,
      type: 'p',
    },
  }),
];

Plugins

TrailingBlockPlugin

Options

Collapse all

    尾随节点应该所在的层级,第一层为 0。

    • 默认值: 0 (根层级)

    尾随块的类型。

    • 默认值: editor.getType(ParagraphPlugin)

    匹配这些类型中任意一个的节点过滤器。

    • 默认值: [] (所有类型)

    不匹配这些类型中任意一个的节点过滤器。

    自定义过滤函数。