-
Notifications
You must be signed in to change notification settings - Fork 965
fix(ui): migrate remaining Monaco views to Shiki #10708
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
18 commits
Select commit
Hold shift + click to select a range
8e13b62
fix(ui): migrate remaining Monaco views to Shiki
luvkapur 25668ea
fix(ui): address Shiki migration review feedback
luvkapur 808b1e2
fix(diff): preserve source whitespace when matching lines
luvkapur 8519fa6
fix(api-reference): render symbol links as text
luvkapur aa439ac
fix(ui): align policy and preserve example indentation
luvkapur 9532a5f
fix(ui): preserve compare routing and rendering semantics
luvkapur afcee76
fix(compare): reset view for each selected file
luvkapur c27e3d4
fix(ui): consume released API renderer packages
luvkapur 92f31e9
fix(diff): keep long unified lines reachable
luvkapur 7e8884e
fix(ui): preserve static renderer compatibility
luvkapur 9546b02
test(ui): use node server renderer in capsules
luvkapur fdae28b
fix(compare): restore view-aware sidebar
luvkapur e1f7864
fix(ui): handle large and transient diff states
luvkapur 71a5d9d
fix(compare): align and synchronize sidebar
luvkapur 6f4ef21
fix(compare): make deferred selections reliable
luvkapur a883cd9
Merge remote-tracking branch 'origin/master' into fix/remove-remainin…
luvkapur e587b4f
fix(compare): preserve sidebar statuses and narrow layouts
luvkapur 4c67e39
fix(config-compare): register only canonical targets
luvkapur 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
This file was deleted.
Oops, something went wrong.
15 changes: 4 additions & 11 deletions
15
components/ui/code-compare/code-compare-editor/code-compare-editor.provider.tsx
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,21 +1,14 @@ | ||
| /* eslint-disable react/prop-types */ | ||
| import type { ReactNode } from 'react'; | ||
| import React, { createContext, useContext } from 'react'; | ||
|
|
||
| const CodeCompareEditorContext = createContext<any>(null); | ||
| import React from 'react'; | ||
|
|
||
| type CodeCompareEditorProviderProps = { | ||
| children: ReactNode; | ||
| }; | ||
|
|
||
| export const CodeCompareEditorProvider: React.FC<CodeCompareEditorProviderProps> = ({ children }) => { | ||
| const DiffEditor = React.lazy(() => { | ||
| return import('@monaco-editor/react').then((module) => ({ default: module.DiffEditor })); | ||
| }); | ||
|
|
||
| return <CodeCompareEditorContext.Provider value={DiffEditor}>{children}</CodeCompareEditorContext.Provider>; | ||
| return <>{children}</>; | ||
| }; | ||
|
|
||
| export const useCodeCompareEditor = () => { | ||
| return useContext(CodeCompareEditorContext); | ||
| }; | ||
| /** @deprecated the Shiki diff renderer no longer needs an injected editor component. */ | ||
| export const useCodeCompareEditor = () => null; |
106 changes: 44 additions & 62 deletions
106
components/ui/code-compare/code-compare-editor/code-compare-editor.tsx
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,88 +1,70 @@ | ||
| import React from 'react'; | ||
| import type { DiffEditorProps, DiffOnMount } from '@monaco-editor/react'; | ||
| import { loader } from '@monaco-editor/react'; | ||
| import { darkMode } from '@teambit/base-ui.theme.dark-theme'; | ||
| import React, { useEffect, useState } from 'react'; | ||
| import { DiffViewer } from '@teambit/code.ui.diff-viewer'; | ||
|
luvkapur marked this conversation as resolved.
|
||
| import type { EditorSettingsState } from '../code-compare-editor-settings'; | ||
|
|
||
| loader.config({ paths: { vs: 'https://cdn.jsdelivr.net/npm/monaco-editor@0.48.0/min/vs' } }); | ||
|
|
||
| export type CodeCompareEditorProps = { | ||
| language: string; | ||
| handleEditorDidMount: DiffOnMount; | ||
| language?: string; | ||
| handleEditorDidMount?: (...args: any[]) => void; | ||
| Loader: React.ReactNode; | ||
| modifiedFileContent?: string; | ||
| originalFileContent?: string; | ||
| originalPath: string; | ||
| modifiedPath: string; | ||
| DiffEditor: React.FC<DiffEditorProps>; | ||
| DiffEditor?: React.ComponentType<any> | null; | ||
| fullScreen?: boolean; | ||
| } & EditorSettingsState; | ||
|
|
||
| const REGULAR_DIFF_HEIGHT = 640; | ||
| const FULLSCREEN_CHROME_HEIGHT = 160; | ||
| const MIN_FULLSCREEN_DIFF_HEIGHT = 220; | ||
|
|
||
| function useDiffHeight(fullScreen?: boolean) { | ||
| const [height, setHeight] = useState(REGULAR_DIFF_HEIGHT); | ||
|
|
||
| useEffect(() => { | ||
| if (!fullScreen) { | ||
| setHeight(REGULAR_DIFF_HEIGHT); | ||
| return undefined; | ||
| } | ||
|
|
||
| const updateHeight = () => | ||
| setHeight(Math.max(MIN_FULLSCREEN_DIFF_HEIGHT, window.innerHeight - FULLSCREEN_CHROME_HEIGHT)); | ||
| updateHeight(); | ||
| window.addEventListener('resize', updateHeight); | ||
| return () => window.removeEventListener('resize', updateHeight); | ||
| }, [fullScreen]); | ||
|
|
||
| return height; | ||
| } | ||
|
|
||
| export function CodeCompareEditor({ | ||
| modifiedFileContent, | ||
| originalFileContent, | ||
| originalPath, | ||
| modifiedPath, | ||
| language, | ||
| handleEditorDidMount, | ||
| ignoreWhitespace, | ||
| wordWrap, | ||
| diffOnly, | ||
| editorViewMode, | ||
| Loader, | ||
| DiffEditor, | ||
| fullScreen, | ||
| }: CodeCompareEditorProps) { | ||
| const maxHeight = useDiffHeight(fullScreen); | ||
| return ( | ||
| <React.Suspense fallback={Loader ?? <></>}> | ||
| <DiffEditor | ||
| // need to force re-render when the editor view mode changes | ||
| key={`${originalPath}-${modifiedPath}-${editorViewMode}`} | ||
| modified={modifiedFileContent || undefined} | ||
| original={originalFileContent || undefined} | ||
| language={language} | ||
| originalModelPath={originalPath} | ||
| modifiedModelPath={modifiedPath} | ||
| onMount={handleEditorDidMount} | ||
| className={darkMode} | ||
| theme="vs-dark" | ||
| options={ | ||
| { | ||
| ignoreTrimWhitespace: ignoreWhitespace, | ||
| useInlineViewWhenSpaceIsLimited: false, | ||
| readOnly: true, | ||
| renderSideBySide: editorViewMode === 'split', | ||
| minimap: { enabled: false }, | ||
| scrollbar: { | ||
| alwaysConsumeMouseWheel: !wordWrap, | ||
| vertical: fullScreen ? 'auto' : 'hidden', | ||
| horizontal: 'hidden', | ||
| }, | ||
| hideUnchangedRegions: { | ||
| enabled: diffOnly, | ||
| revealLineCount: 20, | ||
| contextLineCount: 2, | ||
| minimumLineCount: 5, | ||
| }, | ||
| renderOverviewRuler: fullScreen, | ||
| scrollBeyondLastLine: false, | ||
| folding: false, | ||
| overviewRulerLanes: 0, | ||
| automaticLayout: true, | ||
| overviewRulerBorder: false, | ||
| diffWordWrap: (wordWrap && 'on') || 'off', | ||
| wordWrap: (wordWrap && 'on') || 'off', | ||
| wrappingStrategy: (wordWrap && 'advanced') || undefined, | ||
| fixedOverflowWidgets: true, | ||
| renderLineHighlight: 'none', | ||
| lineHeight: 20, | ||
| padding: { top: 8 }, | ||
| hover: { enabled: false }, | ||
| cursorBlinking: 'smooth', | ||
| } as any | ||
| } | ||
| loading={Loader} | ||
| /> | ||
| </React.Suspense> | ||
| <DiffViewer | ||
|
luvkapur marked this conversation as resolved.
|
||
| key={`${originalPath}-${modifiedPath}-${editorViewMode}`} | ||
|
luvkapur marked this conversation as resolved.
|
||
| fileName={modifiedPath || originalPath} | ||
| oldContent={originalFileContent || ''} | ||
|
luvkapur marked this conversation as resolved.
|
||
| newContent={modifiedFileContent || ''} | ||
| ignoreTrimWhitespace={ignoreWhitespace} | ||
| language={language} | ||
| view={editorViewMode === 'inline' ? 'unified' : 'split'} | ||
| contextLines={diffOnly ? 3 : Number.MAX_SAFE_INTEGER} | ||
|
luvkapur marked this conversation as resolved.
|
||
| maxHeight={maxHeight} | ||
| showHeader={false} | ||
| showViewToggle={false} | ||
| collapsible={false} | ||
| wrap={wordWrap} | ||
|
luvkapur marked this conversation as resolved.
|
||
| /> | ||
| ); | ||
| } | ||
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.