Files
components/excalidraw-demo.tsx
'use client';

import * as React from 'react';

import { ExcalidrawPlugin } from '@platejs/excalidraw/react';
import { Plate, usePlateEditor } from 'platejs/react';

import { EditorKit } from '@/components/editor/editor-kit';
import { excalidrawValue } from '@/registry/examples/values/excalidraw-value';
import { Editor, EditorContainer } from '@/components/ui/editor';
import { ExcalidrawElement } from '@/components/ui/excalidraw-node';

export default function ExcalidrawDemo() {
  const editor = usePlateEditor({
    plugins: [...EditorKit, ExcalidrawPlugin.withComponent(ExcalidrawElement)],
    value: excalidrawValue,
  });

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

功能特性

  • 集成 Excalidraw 库用于创建绘图和图表

安装

pnpm add @platejs/excalidraw

使用方式

import { ExcalidrawPlugin } from '@platejs/excalidraw/react';
 
const plugins = [
  // ...其他插件
  ExcalidrawPlugin,
];

插入工具栏按钮

可以将此项添加到插入工具栏按钮来插入 Excalidraw 元素:

{
  icon: <PenToolIcon />,
  label: 'Excalidraw',
  value: KEYS.excalidraw,
}

插件

ExcalidrawPlugin

Excalidraw 空元素插件。

API 接口

insertExcalidraw

向编辑器中插入 Excalidraw 元素。

Parameters

Collapse all

    Excalidraw 元素的属性参数

    插入 Excalidraw 元素的配置选项

钩子函数

useExcalidrawElement

Excalidraw 组件的行为钩子。

State

Collapse all

    Excalidraw 元素

    在 Excalidraw 组件中显示的库项目

    • 默认值: []

    是否滚动到 Excalidraw 组件内部内容

    • 默认值: true

Returnsobject

Collapse all

    Excalidraw 组件

    传递给 Excalidraw 组件的属性参数