generated from openmcp-project/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Changed component to display YAML files to Monaco Editor #308
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 18 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
c6578bf
init
lucasgoral cfb88ac
init
lucasgoral c72cfe8
fix
lucasgoral 551137c
fixes
lucasgoral 2c26168
Create YamlDiffEditor.tsx
lucasgoral 74b20cf
fix
lucasgoral f0f6d7a
fix
lucasgoral a7d1fe5
Create remove-me.yaml
lucasgoral 761f2b6
fix
lucasgoral 2f8fbac
Delete remove-me.yaml
lucasgoral b7b3c66
fix
lucasgoral 9cab399
Merge branch 'main' into resources-yaml-edit
lucasgoral de46380
Update YamlViewer.tsx
lucasgoral d303b4a
Update YamlLoader.tsx
lucasgoral eb5a125
fix
lucasgoral 0e1fe63
Update YamlViewer.tsx
lucasgoral 2d5d9f6
fix
lucasgoral 4694584
Delete generate-github-themes.ts
lucasgoral 3110aeb
fix
lucasgoral eb04c0e
Update monaco.ts
lucasgoral f8a59fd
merge
lucasgoral a937eef
fix
lucasgoral 442bd02
Merge branch 'main' into resources-yaml-edit
lucasgoral 33d4d0d
fixes
lucasgoral a7e6cb8
fix
lucasgoral a8428a4
fix
lucasgoral 198714f
fix
lucasgoral 6bc59d2
Update monaco.ts
lucasgoral 736aac4
Revert "Update monaco.ts"
lucasgoral 64412df
Update WorkspacesList.module.css
lucasgoral cd88b8e
Merge branch 'main' into resources-yaml-edit
lucasgoral eb98bcc
Update src/components/Yaml/YamlPanel.tsx
lucasgoral 6e226d4
Update src/components/Yaml/YamlViewer.tsx
lucasgoral 7dcf2e8
Update YamlViewer.tsx
lucasgoral b6ae075
Merge branch 'resources-yaml-edit' of https://github.com/openmcp-proj…
lucasgoral 51cf3f0
Update monaco.ts
lucasgoral 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
.container { | ||
width: 100%; | ||
} | ||
position: relative; | ||
|
||
.added { | ||
background-color: rgba(56, 142, 60, 0.18); | ||
} | ||
|
||
.removed { | ||
background-color: rgba(211, 47, 47, 0.18); | ||
width: 100%; | ||
height: 100%; | ||
max-height: 100%; | ||
max-width: 100%; | ||
overflow: hidden; | ||
} |
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 |
---|---|---|
@@ -1,56 +1,16 @@ | ||
import { FC, useMemo } from 'react'; | ||
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'; | ||
import { materialLight, materialDark } from 'react-syntax-highlighter/dist/esm/styles/prism'; | ||
import { diffLines } from 'diff'; | ||
import styles from './YamlDiff.module.css'; | ||
import { useTheme } from '../../hooks/useTheme.ts'; | ||
import { FC } from 'react'; | ||
|
||
import { YamlDiffEditor } from '../YamlEditor/YamlDiffEditor.tsx'; | ||
import styles from './YamlDiff.module.css'; | ||
type YamlDiffProps = { | ||
originalYaml: string; | ||
modifiedYaml: string; | ||
}; | ||
|
||
export const YamlDiff: FC<YamlDiffProps> = ({ originalYaml, modifiedYaml }) => { | ||
const { isDarkTheme } = useTheme(); | ||
|
||
const hunks = useMemo(() => diffLines(originalYaml ?? '', modifiedYaml ?? ''), [originalYaml, modifiedYaml]); | ||
|
||
const { content, lineKinds } = useMemo(() => { | ||
const lines: string[] = []; | ||
const kinds: ('added' | 'removed' | 'context')[] = []; | ||
hunks.forEach((part) => { | ||
const prefix = part.added ? '+' : part.removed ? '-' : ' '; | ||
const kind: 'added' | 'removed' | 'context' = part.added ? 'added' : part.removed ? 'removed' : 'context'; | ||
const partLines = part.value.replace(/\n$/, '').split('\n'); | ||
partLines.forEach((line) => { | ||
lines.push(`${prefix}${line}`); | ||
kinds.push(kind); | ||
}); | ||
}); | ||
return { content: lines.join('\n'), lineKinds: kinds }; | ||
}, [hunks]); | ||
|
||
const lineNumberStyle = useMemo(() => ({ paddingRight: '20px', minWidth: '40px', textAlign: 'right' as const }), []); | ||
|
||
return ( | ||
<div className={styles.container}> | ||
<SyntaxHighlighter | ||
language="diff" | ||
style={isDarkTheme ? materialDark : materialLight} | ||
showLineNumbers | ||
wrapLongLines | ||
lineNumberStyle={lineNumberStyle} | ||
lineProps={(lineNumber) => { | ||
const kind = lineKinds[lineNumber - 1]; | ||
if (kind === 'added') return { className: styles.added }; | ||
if (kind === 'removed') return { className: styles.removed }; | ||
return {}; | ||
}} | ||
customStyle={{ margin: 0, padding: '20px', borderRadius: '4px', fontSize: '1rem', background: 'transparent' }} | ||
codeTagProps={{ style: { whiteSpace: 'pre-wrap' } }} | ||
> | ||
{content} | ||
</SyntaxHighlighter> | ||
<YamlDiffEditor original={originalYaml} modified={modifiedYaml} /> | ||
</div> | ||
); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.wrapper { | ||
width: 100%; | ||
height: 100%; | ||
max-height: 100%; | ||
max-width: 100%; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { DiffEditor } from '@monaco-editor/react'; | ||
import type { ComponentProps } from 'react'; | ||
import { useTheme } from '../../hooks/useTheme'; | ||
import { GITHUB_DARK_DEFAULT, GITHUB_LIGHT_DEFAULT } from '../../lib/monaco.ts'; | ||
|
||
// Reuse all props from the underlying Monaco DiffEditor component, except language (we force YAML) | ||
export type YamlDiffEditorProps = Omit< | ||
ComponentProps<typeof DiffEditor>, | ||
'language' | 'defaultLanguage' | 'originalLanguage' | 'modifiedLanguage' | ||
>; | ||
|
||
// Simple wrapper that forwards all props to Monaco DiffEditor | ||
export const YamlDiffEditor = (props: YamlDiffEditorProps) => { | ||
const { isDarkTheme } = useTheme(); | ||
const { theme, options, ...rest } = props; | ||
const computedTheme = theme ?? (isDarkTheme ? GITHUB_DARK_DEFAULT : GITHUB_LIGHT_DEFAULT); | ||
|
||
const simplifiedOptions = { | ||
// Start from consumer-provided options, then enforce our simplified look | ||
...options, | ||
scrollbar: { | ||
...(options?.scrollbar ?? {}), | ||
useShadows: false, | ||
vertical: 'auto' as const, | ||
horizontal: 'auto' as const, | ||
alwaysConsumeMouseWheel: false, | ||
}, | ||
lineNumbers: 'off' as const, | ||
minimap: { enabled: false }, | ||
glyphMargin: false, | ||
renderLineHighlight: 'none' as const, | ||
folding: false, | ||
renderOverviewRuler: false, | ||
scrollBeyondLastLine: false, | ||
renderMarginRevertIcon: false, | ||
automaticLayout: true, | ||
}; | ||
|
||
return ( | ||
<div style={{ width: '100%', height: '100%', minHeight: '50vh' }}> | ||
<DiffEditor | ||
{...rest} | ||
theme={computedTheme} | ||
options={simplifiedOptions} | ||
height="90vh" | ||
lucasgoral marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
// Force YAML language for both panes | ||
language="yaml" | ||
/> | ||
</div> | ||
); | ||
}; |
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.