Skip to content

Conversation

@electroluxcode
Copy link
Collaborator

@electroluxcode electroluxcode commented Jan 11, 2026

Checklist

  • yarn typecheck
  • yarn lint:fix
  • yarn test
  • yarn brl
  • yarn changeset
  • ui changelog

Design

Refer to the text drawing nodes in Feishu documents, but they include more library renderings than those.such as PlantUML , Graphviz, and Flowchart

Core Features

  1. Multiple Drawing Types: Supports four diagram types
    • Mermaid: Flowcharts, sequence diagrams, Gantt charts, and more
    • PlantUML: UML diagrams, sequence diagrams, and other structured diagrams
    • Graphviz: Graph visualization using DOT language
    • Flowchart: Flowchart diagrams
  2. Inline Editing Experience: Code editing area and preview area are displayed side-by-side (horizontal layout on desktop, vertical on mobile), allowing real-time preview without popups or dialogs
  3. Multiple View Modes: Supports three view mode switches for flexible display
    • Both: Display both code editor and preview simultaneously
    • Code: Display only the code editor
    • Image: Display only the rendered diagram result
  4. Real-time Preview: Uses debouncing (500ms) to optimize rendering performance and avoid frequent API requests
  5. Unified Data Structure: Stores drawingType, drawingMode, and code uniformly in element.data for consistent data management

ui

image

data example

{
    "children": [
        {
            "text": ""
        }
    ],
    data:{
        "drawingMode": "Both",
        "drawingType": "Mermaid",
        "code": `classDiagram
      Animal <|-- Duck
      Animal <|-- Fish
      Animal <|-- Zebra
      Animal : +int age
      Animal : +String gender
      Animal: +isMammal()
      Animal: +mate()
      class Duck{
        +String beakColor
        +swim()
        +quack()
      }
      class Fish{
        -int sizeInFeet
        -canEat()
      }
      class Zebra{
        +bool is_wild
        +run()
      } 
      `
      },
      "type": "code_drawing",
      
  },  

Reference

The design is primarily inspired by Feishu (Lark) Document's text drawing component:

  • Inline editing without popups
  • Code and preview displayed side-by-side
  • Support for switching between multiple diagram types
  • Real-time preview updates

Technical Implementation

  • Uses lodash/debounce for debounced rendering
  • Reuses code-block's pre + code wrapper structure to maintain visual consistency with code editors
  • Toolbar appears on hover to reduce UI clutter
  • Supports SSR with static rendering component to avoid hydration mismatches

Add support for rendering PlantUML, Graphviz, Flowchart, and Mermaid diagrams in Plate editor. Includes:
- Core plugin implementation with base plugin and transforms
- React components for rendering and preview
- Floating toolbar for diagram editing
- Support for multiple view modes (code/preview)
- Utilities for rendering different diagram types
- Add CodeDrawingKit to editor plugin configuration
- Create custom CodeDrawingElement component with UI controls
- Add code-drawing option to insert toolbar, slash menu, and block context menu
- Add example code-drawing content to playground
- Improve rendering performance with debounced updates in useCodeDrawingElement hook
…tion

- Register code-drawing-node in registry-ui with static component
- Add code-drawing-node-static.tsx for SSR support
- Fix insertCodeDrawing transform to align with Plate insertion patterns
- Add hcodedrawing JSX tag support in test-utils
- Add code-drawing documentation and demo examples
- Update registry configurations and build outputs
…ayout

- Split CodeDrawingPreview into CodeDrawingTextarea, CodeDrawingPreviewArea, CodeDrawingToolbar
- Mobile: preview on top, textarea on bottom
- Add border separator in Both mode
- Fix select background to bg-muted/50
- Toolbar: always visible on mobile, hover on desktop
@codesandbox
Copy link

codesandbox bot commented Jan 11, 2026

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@changeset-bot
Copy link

changeset-bot bot commented Jan 11, 2026

🦋 Changeset detected

Latest commit: dc3c963

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@platejs/code-drawing Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@dosubot dosubot bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Jan 11, 2026
@vercel
Copy link

vercel bot commented Jan 11, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
plate Ready Ready Preview, Comment Jan 12, 2026 3:06am

@electroluxcode electroluxcode marked this pull request as draft January 11, 2026 17:38
Copy link
Member

@zbeyens zbeyens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome PR! Left a few comments.

@@ -0,0 +1,11 @@
'use client';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

base-kits can't use client and React import. See another one for reference.

title: Code Drawing Node
---

<ComponentPreview name="code-drawing-demo" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this doc is missing from the sidebar

Comment on lines +17 to +35
renderPopover?: (props: {
children: React.ReactNode;
onRemove: () => void;
onDownload?: () => void;
open: boolean;
}) => React.ReactNode;
renderDrawingTypeSelect?: (props: {
value: CodeDrawingType;
onChange: (value: CodeDrawingType) => void;
}) => React.ReactNode;
renderDrawingModeSelect?: (props: {
value: ViewMode;
onChange: (value: ViewMode) => void;
onOpenChange?: (open: boolean) => void;
}) => React.ReactNode;
renderTextarea?: (props: {
value: string;
onChange: (e: React.ChangeEvent<HTMLTextAreaElement>) => void;
}) => React.ReactNode;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an anti-pattern. We should have components defined directly in the registry without such props.

}) => React.ReactNode;
}

export function CodeDrawingFloatingToolbar({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, to registry

}) => React.ReactNode;
}

export function CodeDrawingPreview({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, to registry

toolbar?: React.ReactNode;
}

export function CodeDrawingPreviewArea({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, to registry

toolbar?: React.ReactNode;
}

export function CodeDrawingTextarea({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, to registry

}) => React.ReactNode;
}

export function CodeDrawingToolbar({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, to registry

import * as React from 'react';

import {
CodeDrawingElement as BaseCodeDrawingElement,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To move to this component

@felixfeng33
Copy link
Collaborator

Nice working!

@electroluxcode electroluxcode changed the title feat: add code-drawing node [wip]feat: add code-drawing node Jan 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature request size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants