Skip to content
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

chore: Upgrade CodeMirror to v6 #1245

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .deps/dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@
| `mimic-fn@2.1.0` | MIT | clearlydefined |
| `mimic-fn@4.0.0` | MIT | clearlydefined |
| `min-indent@1.0.1` | MIT | clearlydefined |
| [`mini-css-extract-plugin@2.9.0`](https://github.com/webpack-contrib/mini-css-extract-plugin) | MIT | clearlydefined |
| [`mini-css-extract-plugin@2.9.0`](https://github.com/webpack-contrib/mini-css-extract-plugin) | MIT | #17035 |
| [`minimatch@3.1.2`](git://github.com/isaacs/minimatch.git) | ISC | clearlydefined |
| `minimist-options@4.1.0` | MIT | clearlydefined |
| [`mkdirp@0.5.6`](https://github.com/substack/node-mkdirp.git) | MIT | clearlydefined |
Expand Down
14 changes: 12 additions & 2 deletions .deps/prod.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
| --- | --- | --- |
| [`@babel/runtime@7.23.2`](https://github.com/babel/babel.git) | MIT | #10718 |
| [`@babel/runtime@7.24.5`](https://github.com/babel/babel.git) | MIT | #13900 |
| [`@codemirror/autocomplete@6.18.1`](https://github.com/codemirror/autocomplete.git) | MIT | clearlydefined |
| [`@codemirror/lang-yaml@6.1.1`](git+https://github.com/codemirror/lang-yaml.git) | MIT | clearlydefined |
| [`@codemirror/language@6.10.3`](https://github.com/codemirror/language.git) | MIT | clearlydefined |
| [`@codemirror/state@6.4.1`](https://github.com/codemirror/state.git) | MIT | clearlydefined |
| [`@codemirror/view@6.34.2`](https://github.com/codemirror/view.git) | MIT | clearlydefined |
| [`@devfile/api@2.3.0-1721400636`](https://github.com/GIT_USER_ID/GIT_REPO_ID.git) | Apache-2.0 | clearlydefined |
| [`@eclipse-che/che-devworkspace-generator@7.90.0-next-4510df7`](git+https://github.com/devfile/devworkspace-generator.git) | EPL-2.0 | ecd.che |
| [`@fastify/accept-negotiator@1.1.0`](git+https://github.com/fastify/accept-negotiator.git) | MIT | clearlydefined |
Expand Down Expand Up @@ -34,6 +39,10 @@
| [`@jsep-plugin/assignment@1.2.1`](EricSmekens/jsep) | MIT | clearlydefined |
| [`@jsep-plugin/regex@1.0.3`](EricSmekens/jsep) | MIT | clearlydefined |
| [`@kubernetes/client-node@0.22.1`](https://github.com/kubernetes-client/javascript.git) | Apache-2.0 | clearlydefined |
| [`@lezer/common@1.2.3`](https://github.com/lezer-parser/common.git) | MIT | clearlydefined |
| [`@lezer/highlight@1.2.1`](https://github.com/lezer-parser/highlight.git) | MIT | clearlydefined |
| [`@lezer/lr@1.4.2`](https://github.com/lezer-parser/lr.git) | MIT | clearlydefined |
| [`@lezer/yaml@1.0.3`](https://github.com/lezer-parser/yaml.git) | MIT | clearlydefined |
| `@lukeed/ms@2.0.2` | MIT | clearlydefined |
| [`@npmcli/agent@2.2.2`](https://github.com/npm/agent.git) | ISC | clearlydefined |
| [`@npmcli/fs@3.1.0`](https://github.com/npm/fs.git) | ISC | #14656 |
Expand Down Expand Up @@ -128,7 +137,6 @@
| [`chownr@3.0.0`](git://github.com/isaacs/chownr.git) | BlueOak-1.0.0 | clearlydefined |
| [`cipher-base@1.0.4`](git+https://github.com/crypto-browserify/cipher-base.git) | MIT | clearlydefined |
| `clean-stack@2.2.0` | MIT | clearlydefined |
| [`codemirror@5.65.16`](https://github.com/codemirror/CodeMirror.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/codemirror/5.65.16) |
| `color-convert@1.9.3` | MIT | clearlydefined |
| `color-convert@2.0.1` | MIT | clearlydefined |
| [`color-name@1.1.3`](git@github.com:dfcreative/color-name.git) | MIT | clearlydefined |
Expand Down Expand Up @@ -167,7 +175,7 @@
| [`domhandler@5.0.3`](git://github.com/fb55/domhandler.git) | BSD-2-Clause | clearlydefined |
| [`domutils@3.1.0`](git://github.com/fb55/domutils.git) | BSD-2-Clause | #8391 |
| [`duplexify@4.1.3`](git://github.com/mafintosh/duplexify) | MIT | clearlydefined |
| [`ecc-jsbn@0.1.2`](https://github.com/quartzjer/ecc-jsbn.git) | MIT | clearlydefined |
| [`ecc-jsbn@0.1.2`](https://github.com/quartzjer/ecc-jsbn.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/ecc-jsbn/0.1.2) |
| [`elliptic@6.5.7`](git@github.com:indutny/elliptic) | MIT | [CQ23022](https://dev.eclipse.org/ipzilla/show_bug.cgi?id=23022) |
| [`emoji-regex@8.0.0`](https://github.com/mathiasbynens/emoji-regex.git) | MIT | clearlydefined |
| `encoding@0.1.13` | MIT | #1016 |
Expand Down Expand Up @@ -497,6 +505,7 @@
| `strip-ansi@6.0.1` | MIT | clearlydefined |
| `strip-ansi@7.1.0` | MIT | #8735 |
| `strip-json-comments@3.1.1` | MIT | clearlydefined |
| [`style-mod@4.1.2`](git+https://github.com/marijnh/style-mod.git) | MIT | clearlydefined |
| [`style-to-object@1.0.8`](https://github.com/remarkablemark/style-to-object) | MIT | #16187 |
| `supports-color@5.5.0` | MIT | clearlydefined |
| [`tabbable@5.3.3`](git+https://github.com/focus-trap/tabbable.git) | MIT | clearlydefined |
Expand Down Expand Up @@ -541,6 +550,7 @@
| [`verror@1.10.0`](git://github.com/davepacheco/node-verror.git) | MIT | clearlydefined |
| `vfile-message@4.0.2` | MIT | clearlydefined |
| `vfile@6.0.3` | MIT | clearlydefined |
| [`w3c-keyname@2.2.8`](git+https://github.com/marijnh/w3c-keyname.git) | MIT | clearlydefined |
| [`warning@4.0.3`](https://github.com/BerkeleyTrue/warning.git) | MIT | [CQ22359](https://dev.eclipse.org/ipzilla/show_bug.cgi?id=22359) |
| `webidl-conversions@3.0.1` | BSD-2-Clause | clearlydefined |
| `whatwg-url@5.0.0` | MIT | clearlydefined |
Expand Down
236 changes: 118 additions & 118 deletions .yarn/releases/yarn-3.8.3.cjs → .yarn/releases/yarn-3.8.6.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ packageExtensions:
dependencies:
prop-types: "*"

yarnPath: .yarn/releases/yarn-3.8.3.cjs
yarnPath: .yarn/releases/yarn-3.8.6.cjs
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
},
"resolutions": {
"@adobe/css-tools": "^4.3.2",
"@codemirror/autocomplete": "6.18.1",
"@hapi/hoek": "^10.0.1",
"axios": "^1.7.4",
"braces": "^3.0.3",
Expand Down
6 changes: 5 additions & 1 deletion packages/dashboard-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@
"test:watch": "yarn test --watch"
},
"dependencies": {
"@codemirror/lang-yaml": "^6.1.1",
"@codemirror/language": "^6.10.3",
"@codemirror/state": "^6.4.1",
"@codemirror/view": "^6.34.1",
"@lezer/highlight": "^1.2.1",
"@patternfly/react-core": "^4.276.11",
"@patternfly/react-icons": "^4.93.7",
"@patternfly/react-table": "^4.113.3",
"axios": "^1.7.0",
"buffer": "^6.0.3",
"codemirror": "^5.65.16",
"crypto-browserify": "^3.12.0",
"date-fns": "^3.5.0",
"detect-browser": "^5.3.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
width: 100%;
height: 100%;
min-height: 50vh;
border: 1px solid var(--pf-global--BorderColor--100);
}

.devfileViewer .CodeMirror-lines {
margin-top: -4px;
font-size: 12px;
font-weight: normal;
line-height: 18px;
.devfileViewer > div {
overflow: auto;
height: 100%;
border: 1px solid var(--pf-global--BorderColor--100);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,58 @@
* Red Hat, Inc. - initial API and implementation
*/

import 'codemirror/mode/yaml/yaml';
import 'codemirror/lib/codemirror.css';
import '@/components/DevfileViewer/theme/eclipse-che.css';

import { fromTextArea as CMEditor } from 'codemirror';
import { yaml } from '@codemirror/lang-yaml';
import {
defaultHighlightStyle,
foldGutter,
HighlightStyle,
syntaxHighlighting,
} from '@codemirror/language';
import { EditorState, Extension } from '@codemirror/state';
import { EditorView, lineNumbers } from '@codemirror/view';
import { tags as t } from '@lezer/highlight';
import React from 'react';

import styles from '@/components/DevfileViewer/index.module.css';

const base00 = '#2e3440'; // black
const base01 = '#999'; // grey
const base02 = '#f7f7f7'; // white
const base03 = '#5e81ac'; // deep blue
const base04 = '#008080'; // teal
const base05 = '#fff'; // white
export const basicLightTheme = EditorView.theme(
{
'&': {
color: base00,
backgroundColor: base05,
},
'.cm-gutters': {
backgroundColor: base02,
color: base01,
},
'.cm-activeLineGutter': {
backgroundColor: base02,
},
},
{ dark: false },
);
const basicLightHighlightStyle = HighlightStyle.define([
{ tag: t.keyword, color: base03 },
{ tag: [t.string], color: base03 },
{ tag: [t.variableName], color: base04 },
{
tag: [t.name, t.deleted, t.character, t.propertyName, t.macroName],
color: base04,
},
]);
const basicLight: Extension = [basicLightTheme, syntaxHighlighting(basicLightHighlightStyle)];
const minimalSetup: Extension = (() => [
lineNumbers(),
foldGutter(),
syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
])();

export type Props = {
isActive: boolean;
isExpanded: boolean;
Expand All @@ -27,46 +70,47 @@ export type Props = {
};

export class DevfileViewer extends React.PureComponent<Props> {
private editor: CMEditor | undefined;
private editor: EditorView | undefined;

constructor(props: Props) {
super(props);
}

public componentDidMount(): void {
const element = window.document.querySelector(
`.${styles.devfileViewer} textarea#${this.props.id}`,
);
if (element !== null) {
const editor = new CMEditor(element, {
mode: 'yaml',
theme: 'eclipse-che',
lineNumbers: true,
lineWrapping: true,
readOnly: true,
autoRefresh: true,
const parent = window.document.querySelector(`#${this.props.id}`);
if (parent) {
const state = this.getEditorState();
this.editor = new EditorView({
state,
parent,
});
editor.setSize(`100%`, `100%`);
editor.setValue(this.props.value);
}
}

this.editor = editor;
public componentWillUnmount(): void {
if (this.editor) {
this.editor.destroy();
}
}

public componentDidUpdate(): void {
if (!this.editor) {
return;
componentDidUpdate(prevProps: Readonly<Props>): void {
if (this.editor && this.props.value !== prevProps.value) {
const state = this.getEditorState();
this.editor.setState(state);
}
}

this.editor.setValue(this.props.value);
this.editor.refresh();
this.editor.focus();
private getEditorState(): EditorState {
return EditorState.create({
doc: this.props.value,
extensions: [minimalSetup, EditorState.readOnly.of(true), yaml(), basicLight],
});
}

public render(): React.ReactElement {
return (
<div className={styles.devfileViewer}>
<textarea id={this.props.id}></textarea>
<div id={this.props.id}></div>
</div>
);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export class EditorSelectorEntry extends React.PureComponent<Props, State> {
};
}

// TODO temporary solution for making links open in a new browser tab (should be fixed with https://github.com/eclipse-che/che/issues/23219)
private setAttribute(
widgetId: string,
querySelector: string = 'a',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { dump } from 'js-yaml';
import { cloneDeep } from 'lodash';
import React from 'react';

import { DevfileEditorTab, prepareDevfile } from '@/pages/WorkspaceDetails/DevfileEditorTab';
import DevfileEditorTab, { prepareDevfile } from '@/pages/WorkspaceDetails/DevfileEditorTab';
import getComponentRenderer, { screen } from '@/services/__mocks__/getComponentRenderer';
import devfileApi from '@/services/devfileApi';
import { constructWorkspace, Workspace } from '@/services/workspace-adapter';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export type State = {
copied?: boolean;
};

export class DevfileEditorTab extends React.PureComponent<Props, State> {
export default class DevfileEditorTab extends React.PureComponent<Props, State> {
constructor(props: Props) {
super(props);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,13 @@ describe('Workspace Details page', () => {
});

describe('Tabs', () => {
it('should activate the Overview tab by default', () => {
it('should activate the Overview tab by default', async () => {
const workspace = constructWorkspace(devWorkspaceBuilder.build());
renderComponent({
workspace,
});

const tabpanel = screen.queryByRole('tabpanel', { name: 'Overview' });
expect(tabpanel).not.toBeNull();
expect(await screen.findByRole('tabpanel', { name: 'Overview' })).not.toBeNull();
});

it('should have four tabs visible', () => {
Expand Down
Loading
Loading