-
Notifications
You must be signed in to change notification settings - Fork 3.8k
feat(files): render diff fences and theme mermaid diagrams #8543
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
bbad44b
improvement(files): theme mermaid diagrams with app tokens
TheodoreSpeaks d21378a
feat(files): render diff fences with source-checked state
TheodoreSpeaks e2458c1
improvement(files): frame diffs as cards with tinted change rows
TheodoreSpeaks 83a6378
improvement(files): render prose diffs as source excerpt cards and co…
TheodoreSpeaks b540a7d
improvement(files): put the open link beside the excerpt title
TheodoreSpeaks 4466242
improvement(files): render inline bold and code in prose diffs
TheodoreSpeaks 96de0bf
improvement(files): render edits as line diffs with softer change colors
TheodoreSpeaks 4e2c8ee
improvement(files): draw mermaid flowcharts like workflow blocks and …
TheodoreSpeaks daa963c
fix(files): keep mermaid labels inside their nodes and fork edges cle…
TheodoreSpeaks 3431935
improvement(files): drop diff source checks and split view, size tabl…
TheodoreSpeaks 9735ca8
improvement(files): keep the diff parser out of the editor bundle
TheodoreSpeaks 2602094
fix(files): parse multi-file and copy git diffs, cap word diffs, read…
TheodoreSpeaks 321d23a
fix(files): title renames by their new path and expand collapsed line…
TheodoreSpeaks 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
88 changes: 88 additions & 0 deletions
88
apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/mermaid-theme.ts
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,88 @@ | ||
| /** | ||
| * Mermaid `base` theme variables drawn from the app's tokens, so diagrams match the editor and | ||
| * charts instead of Mermaid's stock palette. Mermaid derives shades from these with its own colour | ||
| * library, so every token read here must resolve to a plain hex or rgb value. | ||
| */ | ||
| export function readMermaidThemeVariables( | ||
| element: Element, | ||
| darkMode: boolean | ||
| ): Record<string, string | boolean> { | ||
| const styles = getComputedStyle(element) | ||
| const token = (name: string) => { | ||
| const value = styles.getPropertyValue(name).trim() | ||
| if (!value) throw new Error(`Missing diagram theme token ${name}`) | ||
| return value | ||
| } | ||
| const background = token('--bg') | ||
| const node = token('--surface-2') | ||
| const muted = token('--surface-4') | ||
| const subtle = token('--surface-5') | ||
| const border = token('--border') | ||
| const text = token('--text-primary') | ||
| const body = token('--text-body') | ||
| const line = token('--text-icon') | ||
| return { | ||
| darkMode, | ||
| fontFamily: getComputedStyle(document.body).fontFamily, | ||
| fontSize: '14px', | ||
| background, | ||
| primaryColor: node, | ||
| primaryTextColor: text, | ||
| primaryBorderColor: border, | ||
| secondaryColor: muted, | ||
| secondaryTextColor: body, | ||
| secondaryBorderColor: border, | ||
| tertiaryColor: subtle, | ||
| tertiaryTextColor: body, | ||
| tertiaryBorderColor: border, | ||
| mainBkg: node, | ||
| nodeBorder: border, | ||
| textColor: body, | ||
| lineColor: token('--workflow-edge'), | ||
| clusterBkg: token('--surface-3'), | ||
| clusterBorder: border, | ||
| edgeLabelBackground: background, | ||
| noteBkgColor: muted, | ||
| noteTextColor: body, | ||
| noteBorderColor: border, | ||
| actorBkg: node, | ||
| actorBorder: border, | ||
| actorTextColor: text, | ||
| actorLineColor: line, | ||
| signalColor: line, | ||
| signalTextColor: body, | ||
| labelBoxBkgColor: subtle, | ||
| labelBoxBorderColor: border, | ||
| labelTextColor: body, | ||
| loopTextColor: body, | ||
| sequenceNumberColor: background, | ||
| pie1: body, | ||
| pie2: line, | ||
| pie3: token('--text-subtle'), | ||
| pie4: token('--text-muted'), | ||
| pieStrokeColor: background, | ||
| pieTitleTextColor: text, | ||
| pieSectionTextColor: background, | ||
| pieLegendTextColor: body, | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Flowcharts drawn like workflow canvas blocks and edges: rounded cards with a 1.5px outline, | ||
| * 1.5px edges without arrowheads, and subgraphs as rounded subflow containers. Labels are pinned | ||
| * to the font Mermaid measured them with; otherwise they inherit the surrounding document's font | ||
| * and line height and overflow their boxes. Edge rules are scoped to flowchart classes so sequence | ||
| * and other diagrams keep their arrows. | ||
| */ | ||
| export function mermaidWorkflowCss(fontFamily: string): string { | ||
| return ` | ||
| .label, .nodeLabel, .edgeLabel, .label p, .nodeLabel p, .edgeLabel p { | ||
| font-family: ${fontFamily}; font-size: 14px; line-height: 1.5; letter-spacing: normal; | ||
| } | ||
| .edgeLabel, .edgeLabel p { font-size: 12px; } | ||
| .node rect, .node polygon, .node circle, .node path { stroke-width: 1.5px; } | ||
| .node rect { rx: 10px; ry: 10px; } | ||
| .cluster rect { rx: 14px; ry: 14px; stroke-width: 1.5px; } | ||
| .flowchart-link { stroke-width: 1.5px; marker-end: none !important; } | ||
| ` | ||
| } | ||
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.
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.