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: 7dca8db

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.

1 Skipped Deployment
Project Deployment Review Updated (UTC)
plate Ignored Ignored Preview Jan 28, 2026 0:16am

Request Review

@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.

@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
…age internal state

- Updated CodeDrawingTextareaProps from type to interface for better extensibility.
- Introduced internal state management for textarea value to handle external updates without losing user input.
- Updated event handling to use internal state for rendering and changes.
@electroluxcode electroluxcode marked this pull request as ready for review January 27, 2026 10:31
@electroluxcode electroluxcode changed the title [wip]feat: add code-drawing node feat: add code-drawing node Jan 27, 2026
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.

Thanks for the update! Left my last comments

… logic and toolbar

- Introduced a custom hook for managing code drawing element state, including debounced rendering and error handling.
- Replaced BaseCodeDrawingElement with PlateElement for improved integration.
- Added a toolbar for selecting drawing type and view mode, enhancing user interaction.
- Refactored CodeDrawingPreview and CodeDrawingTextarea components for better state management and responsiveness.
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Jan 28, 2026
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jan 28, 2026
@zbeyens zbeyens merged commit 7570286 into udecode:main Jan 28, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature request lgtm This PR has been approved by a maintainer size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants