-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: add Excalidraw diagram editor widget #3479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AlexKlim
wants to merge
1
commit into
wavetermdev:main
Choose a base branch
from
AlexKlim:pr/excalidraw-widget
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,7 @@ storybook-static/ | |
| test-results.xml | ||
|
|
||
| docsite/ | ||
| public/excalidraw/ | ||
|
|
||
| .kilo-format-temp-* | ||
| .superpowers | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,191 @@ | ||
| // Copyright 2026, Command Line Inc. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package cmd | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
| "io" | ||
| "os" | ||
| "path/filepath" | ||
|
|
||
| "github.com/google/uuid" | ||
| "github.com/spf13/cobra" | ||
| "github.com/wavetermdev/waveterm/pkg/waveobj" | ||
| "github.com/wavetermdev/waveterm/pkg/wshrpc" | ||
| "github.com/wavetermdev/waveterm/pkg/wshrpc/wshclient" | ||
| ) | ||
|
|
||
| var excalidrawMagnified bool | ||
|
|
||
| var excalidrawCmd = &cobra.Command{ | ||
| Use: "excalidraw [file]", | ||
| Short: "open an Excalidraw diagram", | ||
| Args: cobra.MaximumNArgs(1), | ||
| RunE: excalidrawRun, | ||
| PreRunE: preRunSetupRpcClient, | ||
| } | ||
|
|
||
| var excalidrawPushCmd = &cobra.Command{ | ||
| Use: "push <blockid> [file]", | ||
| Short: "push Excalidraw JSON into a block's scene", | ||
| Args: cobra.RangeArgs(1, 2), | ||
| RunE: excalidrawPushRun, | ||
| PreRunE: preRunSetupRpcClient, | ||
| } | ||
|
|
||
| var excalidrawMermaidCmd = &cobra.Command{ | ||
| Use: "mermaid [blockid] [file]", | ||
| Short: "open or push a Mermaid diagram as Excalidraw", | ||
| Args: cobra.RangeArgs(0, 2), | ||
| RunE: excalidrawMermaidRun, | ||
| PreRunE: preRunSetupRpcClient, | ||
| } | ||
|
|
||
| func init() { | ||
| excalidrawCmd.Flags().BoolVarP(&excalidrawMagnified, "magnified", "m", false, "open in magnified mode") | ||
| excalidrawCmd.AddCommand(excalidrawPushCmd) | ||
| excalidrawCmd.AddCommand(excalidrawMermaidCmd) | ||
| rootCmd.AddCommand(excalidrawCmd) | ||
| } | ||
|
|
||
| func excalidrawRun(cmd *cobra.Command, args []string) (rtnErr error) { | ||
| defer func() { | ||
| sendActivity("excalidraw", rtnErr == nil) | ||
| }() | ||
| tabId := getTabIdFromEnv() | ||
| if tabId == "" { | ||
| return fmt.Errorf("no WAVETERM_TABID env var set") | ||
| } | ||
| meta := map[string]any{ | ||
| waveobj.MetaKey_View: "excalidraw", | ||
| } | ||
| if len(args) > 0 { | ||
| absFile, err := filepath.Abs(args[0]) | ||
| if err != nil { | ||
| return fmt.Errorf("getting absolute path: %w", err) | ||
| } | ||
| meta[waveobj.MetaKey_File] = absFile | ||
| } | ||
| if RpcContext.Conn != "" { | ||
| meta[waveobj.MetaKey_Connection] = RpcContext.Conn | ||
| } | ||
| wshCmd := &wshrpc.CommandCreateBlockData{ | ||
| TabId: tabId, | ||
| BlockDef: &waveobj.BlockDef{ | ||
| Meta: meta, | ||
| }, | ||
| Magnified: excalidrawMagnified, | ||
| Focused: true, | ||
| } | ||
| _, err := wshclient.CreateBlockCommand(RpcClient, *wshCmd, &wshrpc.RpcOpts{Timeout: 2000}) | ||
| if err != nil { | ||
| return fmt.Errorf("creating excalidraw block: %w", err) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func excalidrawPushRun(cmd *cobra.Command, args []string) (rtnErr error) { | ||
| defer func() { | ||
| sendActivity("excalidraw:push", rtnErr == nil) | ||
| }() | ||
| blockId := args[0] | ||
| var jsonData []byte | ||
| var err error | ||
| if len(args) > 1 { | ||
| jsonData, err = os.ReadFile(args[1]) | ||
| } else { | ||
| jsonData, err = io.ReadAll(io.LimitReader(os.Stdin, MaxFileSize+1)) | ||
| } | ||
| if err != nil { | ||
| return fmt.Errorf("reading input: %w", err) | ||
| } | ||
| if len(jsonData) > MaxFileSize { | ||
| return fmt.Errorf("input exceeds maximum size of %d bytes", MaxFileSize) | ||
| } | ||
| var sceneData any | ||
| if err := json.Unmarshal(jsonData, &sceneData); err != nil { | ||
| return fmt.Errorf("invalid JSON: %w", err) | ||
| } | ||
| pushData := wshrpc.CommandExcalidrawPushData{ | ||
| BlockId: blockId, | ||
| SceneData: sceneData, | ||
| } | ||
| err = wshclient.ExcalidrawPushCommand(RpcClient, pushData, &wshrpc.RpcOpts{Timeout: 5000}) | ||
| if err != nil { | ||
| return fmt.Errorf("push failed: %w", err) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func excalidrawMermaidRun(cmd *cobra.Command, args []string) (rtnErr error) { | ||
| defer func() { | ||
| sendActivity("excalidraw:mermaid", rtnErr == nil) | ||
| }() | ||
| var blockId string | ||
| var mermaidData []byte | ||
| var err error | ||
| switch len(args) { | ||
| case 0: | ||
| mermaidData, err = io.ReadAll(io.LimitReader(os.Stdin, MaxFileSize+1)) | ||
| if err != nil { | ||
| return fmt.Errorf("reading stdin: %w", err) | ||
| } | ||
| case 1: | ||
| mermaidData, err = os.ReadFile(args[0]) | ||
| if err != nil { | ||
| if !os.IsNotExist(err) { | ||
| return fmt.Errorf("reading file: %w", err) | ||
| } | ||
| if _, uuidErr := uuid.Parse(args[0]); uuidErr != nil { | ||
| return fmt.Errorf("file not found: %s", args[0]) | ||
| } | ||
| blockId = args[0] | ||
| mermaidData, err = io.ReadAll(io.LimitReader(os.Stdin, MaxFileSize+1)) | ||
| if err != nil { | ||
| return fmt.Errorf("reading stdin: %w", err) | ||
| } | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| case 2: | ||
| blockId = args[0] | ||
| mermaidData, err = os.ReadFile(args[1]) | ||
| if err != nil { | ||
| return fmt.Errorf("reading file: %w", err) | ||
| } | ||
| } | ||
| if len(mermaidData) > MaxFileSize { | ||
| return fmt.Errorf("input exceeds maximum size of %d bytes", MaxFileSize) | ||
| } | ||
| if blockId == "" { | ||
| tabId := getTabIdFromEnv() | ||
| if tabId == "" { | ||
| return fmt.Errorf("no WAVETERM_TABID env var set") | ||
| } | ||
| createData := &wshrpc.CommandCreateBlockData{ | ||
| TabId: tabId, | ||
| BlockDef: &waveobj.BlockDef{ | ||
| Meta: map[string]any{ | ||
| waveobj.MetaKey_View: "excalidraw", | ||
| }, | ||
| }, | ||
| Magnified: excalidrawMagnified, | ||
| Focused: true, | ||
| } | ||
| oref, err := wshclient.CreateBlockCommand(RpcClient, *createData, &wshrpc.RpcOpts{Timeout: 2000}) | ||
| if err != nil { | ||
| return fmt.Errorf("creating excalidraw block: %w", err) | ||
| } | ||
| blockId = oref.OID | ||
| } | ||
| pushData := wshrpc.CommandExcalidrawPushData{ | ||
| BlockId: blockId, | ||
| SceneData: string(mermaidData), | ||
| Format: "mermaid", | ||
| } | ||
| err = wshclient.ExcalidrawPushCommand(RpcClient, pushData, &wshrpc.RpcOpts{Timeout: 5000}) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| if err != nil { | ||
| return fmt.Errorf("mermaid push failed: %w", err) | ||
| } | ||
| return nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.