Skip to content

Commit c8babe0

Browse files
committed
chore: migrate to react-codemirror
Signed-off-by: Oleksii Orel <[email protected]>
1 parent 3b5b0d4 commit c8babe0

File tree

8 files changed

+296
-155
lines changed

8 files changed

+296
-155
lines changed

.deps/prod.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
| Packages | License | Resolved CQs |
44
| --- | --- | --- |
55
| [`@babel/[email protected]`](https://github.com/babel/babel.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/@babel/runtime/7.27.0) |
6+
| [`@codemirror/[email protected]`](https://github.com/codemirror/autocomplete.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/@codemirror/autocomplete/6.18.6) |
7+
| [`@codemirror/[email protected]`](https://github.com/codemirror/commands.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/@codemirror/commands/6.8.1) |
8+
| [`@codemirror/[email protected]`](git+https://github.com/codemirror/lang-yaml.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/@codemirror/lang-yaml/6.1.2) |
9+
| [`@codemirror/[email protected]`](https://github.com/codemirror/language.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/@codemirror/language/6.10.3) |
10+
| [`@codemirror/[email protected]`](https://github.com/codemirror/lint.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/@codemirror/lint/6.8.5) |
11+
| [`@codemirror/[email protected]`](https://github.com/codemirror/search.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/@codemirror/search/6.5.6) |
12+
| [`@codemirror/[email protected]`](https://github.com/codemirror/state.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/@codemirror/state/6.5.2) |
13+
| [`@codemirror/[email protected]`](https://github.com/codemirror/theme-one-dark.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/@codemirror/theme-one-dark/6.1.2) |
14+
| [`@codemirror/[email protected]`](https://github.com/codemirror/view.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/@codemirror/view/6.37.1) |
615
| [`@devfile/[email protected]`](https://github.com/devfile/api) | Apache-2.0 | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/@devfile/api/2.3.0-1746644330) |
716
| [`@eclipse-che/[email protected]`](git+https://github.com/devfile/devworkspace-generator.git) | EPL-2.0 | ecd.che |
817
| [`@fastify/[email protected]`](git+https://github.com/fastify/accept-negotiator.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/@fastify/accept-negotiator/1.1.0) |
@@ -40,7 +49,10 @@
4049
| [`@kubernetes/[email protected]`](https://github.com/kubernetes-client/javascript.git) | Apache-2.0 | #17950 |
4150
| [`@lezer/[email protected]`](https://github.com/lezer-parser/common.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/@lezer/common/1.2.3) |
4251
| [`@lezer/[email protected]`](https://github.com/lezer-parser/highlight.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/@lezer/highlight/1.2.1) |
52+
| [`@lezer/[email protected]`](https://github.com/lezer-parser/lr.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/@lezer/lr/1.4.2) |
53+
| [`@lezer/[email protected]`](https://github.com/lezer-parser/yaml.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/@lezer/yaml/1.0.3) |
4354
| `@lukeed/[email protected]` | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/@lukeed/ms/2.0.2) |
55+
| [`@marijn/[email protected]`](git+https://github.com/marijnh/find-cluster-break.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/@marijn/find-cluster-break/1.0.2) |
4456
| [`@npmcli/[email protected]`](https://github.com/npm/agent.git) | ISC | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/@npmcli/agent/2.2.2) |
4557
| [`@npmcli/[email protected]`](https://github.com/npm/fs.git) | ISC | #14656 |
4658
| [`@patternfly/[email protected]`](https://github.com/patternfly/patternfly-react.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/@patternfly/react-core/4.278.0) |
@@ -63,6 +75,8 @@
6375
| [`@types/[email protected]`](https://github.com/DefinitelyTyped/DefinitelyTyped.git) | MIT | #10798 |
6476
| [`@types/[email protected]`](https://github.com/DefinitelyTyped/DefinitelyTyped.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/@types/use-sync-external-store/0.0.3) |
6577
| [`@types/[email protected]`](https://github.com/DefinitelyTyped/DefinitelyTyped.git) | MIT | #6016 |
78+
| [`@uiw/[email protected]`](https://github.com/uiwjs/react-codemirror.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/@uiw/codemirror-extensions-basic-setup/4.23.5) |
79+
| [`@uiw/[email protected]`](https://github.com/uiwjs/react-codemirror.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/@uiw/react-codemirror/4.23.5) |
6680
| [`[email protected]`](https://github.com/npm/abbrev-js.git) | ISC | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/abbrev/2.0.0) |
6781
| [`[email protected]`](git+https://github.com/mysticatea/abort-controller.git) | MIT | #7592 |
6882
| [`[email protected]`](git+https://github.com/jsumners/abstract-logging.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/abstract-logging/2.0.1) |
@@ -118,7 +132,7 @@
118132
| [`[email protected]`](git://github.com/isaacs/chownr.git) | BlueOak-1.0.0 | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/chownr/3.0.0) |
119133
| [`[email protected]`](git+https://github.com/crypto-browserify/cipher-base.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/cipher-base/1.0.6) |
120134
| `[email protected]` | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/clean-stack/2.2.0) |
121-
| [`codemirror@5.65.18`](https://github.com/codemirror/CodeMirror.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/codemirror/5.65.18) |
135+
| [`codemirror@6.0.1`](https://github.com/codemirror/basic-setup.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/codemirror/6.0.1) |
122136
| `[email protected]` | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/color-convert/1.9.3) |
123137
| `[email protected]` | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/color-convert/2.0.1) |
124138
| [`[email protected]`]([email protected]:dfcreative/color-name.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/color-name/1.1.3) |
@@ -135,6 +149,7 @@
135149
| [`[email protected]`]([email protected]:crypto-browserify/createHash.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/create-hash/1.1.3) |
136150
| [`[email protected]`]([email protected]:crypto-browserify/createHash.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/create-hash/1.2.0) |
137151
| [`[email protected]`](https://github.com/crypto-browserify/createHmac.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/create-hmac/1.1.7) |
152+
| [`[email protected]`](git+https://github.com/marijnh/crelt.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/crelt/1.0.6) |
138153
| [`[email protected]`]([email protected]:moxystudio/node-cross-spawn.git) | MIT | #17146 |
139154
| [`[email protected]`](git://github.com/crypto-browserify/crypto-browserify.git) | MIT | #1033 |
140155
| [`[email protected]`](git://github.com/trentm/node-dashdash.git) | MIT | #14596 |
@@ -454,6 +469,7 @@
454469
| `[email protected]` | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/strip-ansi/6.0.1) |
455470
| `[email protected]` | MIT | #8735 |
456471
| `[email protected]` | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/strip-json-comments/3.1.1) |
472+
| [`[email protected]`](git+https://github.com/marijnh/style-mod.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/style-mod/4.1.2) |
457473
| `[email protected]` | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/supports-color/5.5.0) |
458474
| [`[email protected]`](git+https://github.com/focus-trap/tabbable.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/tabbable/5.3.3) |
459475
| [`[email protected]`](https://github.com/isaacs/node-tar.git) | ISC | #10508 |
@@ -490,6 +506,7 @@
490506
| [`[email protected]`](https://github.com/uuidjs/uuid.git) | MIT | #57 |
491507
| `[email protected]` | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/value-equal/1.0.1) |
492508
| [`[email protected]`](git://github.com/davepacheco/node-verror.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/verror/1.10.0) |
509+
| [`[email protected]`](git+https://github.com/marijnh/w3c-keyname.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/w3c-keyname/2.2.8) |
493510
| [`[email protected]`](https://github.com/BerkeleyTrue/warning.git) | MIT | CQ22359 |
494511
| `[email protected]` | BSD-2-Clause | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/webidl-conversions/3.0.1) |
495512
| `[email protected]` | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/whatwg-url/5.0.0) |

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
"@babel/helpers": "^7.26.10",
4343
"@babel/runtime": "^7.26.10",
4444
"@adobe/css-tools": "^4.3.2",
45+
"@codemirror/language": "6.10.3",
46+
"@codemirror/search": "6.5.6",
4547
"@hapi/hoek": "^10.0.1",
4648
"axios": "^1.8.2",
4749
"bn.js": "^5.2.0",

packages/dashboard-frontend/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,16 @@
3232
"test:watch": "yarn test --watch"
3333
},
3434
"dependencies": {
35+
"@codemirror/lang-yaml": "^6.1.1",
36+
"@codemirror/language": "^6.10.3",
37+
"@codemirror/view": "^6.36.2",
3538
"@lezer/highlight": "^1.2.1",
3639
"@patternfly/react-core": "^4.276.11",
3740
"@patternfly/react-icons": "^4.93.7",
3841
"@patternfly/react-table": "^4.113.3",
3942
"@reduxjs/toolkit": "^2.2.7",
43+
"@uiw/react-codemirror": "4.23.5",
4044
"buffer": "^6.0.3",
41-
"codemirror": "^5.65.18",
4245
"crypto-browserify": "^3.12.0",
4346
"date-fns": "^3.5.0",
4447
"detect-browser": "^5.3.0",

packages/dashboard-frontend/src/components/BasicViewer/index.tsx

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Red Hat, Inc. - initial API and implementation
1111
*/
1212

13-
import CodeMirror from 'codemirror';
13+
import CodeMirror from '@uiw/react-codemirror';
1414
import React from 'react';
1515

1616
import styles from '@/components/BasicViewer/index.module.css';
@@ -21,36 +21,15 @@ export type Props = {
2121
};
2222

2323
export class BasicViewer extends React.PureComponent<Props> {
24-
private editor: CodeMirror.Editor | undefined;
25-
26-
public componentDidMount(): void {
27-
const parent = window.document.querySelector(`#${this.props.id}`);
28-
if (parent) {
29-
this.editor = CodeMirror.fromTextArea(parent as HTMLTextAreaElement, {
30-
lineNumbers: false,
31-
lineWrapping: false,
32-
readOnly: true,
33-
value: this.props.value,
34-
});
35-
}
36-
}
37-
38-
componentDidUpdate(): void {
39-
if (this.editor) {
40-
this.editor.setValue(this.props.value);
41-
this.editor.refresh();
42-
}
43-
}
44-
4524
public render(): React.ReactElement {
4625
return (
4726
<div className={styles.basicViewer}>
48-
<textarea
27+
<CodeMirror
4928
id={this.props.id}
50-
data-testid={this.props.id}
51-
value={this.props.value}
5229
readOnly={true}
53-
></textarea>
30+
basicSetup={false}
31+
value={this.props.value}
32+
/>
5433
</div>
5534
);
5635
}

packages/dashboard-frontend/src/components/DevfileViewer/index.module.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@
2121
height: 100%;
2222
border: 1px solid var(--pf-global--BorderColor--100);
2323
}
24+
25+
.devfileViewer .codeMirror > div {
26+
height: 100%;
27+
}

packages/dashboard-frontend/src/components/DevfileViewer/index.tsx

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
* Red Hat, Inc. - initial API and implementation
1111
*/
1212

13-
import 'codemirror/mode/yaml/yaml';
14-
import 'codemirror/lib/codemirror.css';
15-
import '@/components/DevfileViewer/theme/eclipse-che.css';
16-
17-
import CodeMirror from 'codemirror';
13+
import { yaml } from '@codemirror/lang-yaml';
14+
import { HighlightStyle, syntaxHighlighting } from '@codemirror/language';
15+
import { EditorView } from '@codemirror/view';
16+
import { tags as t } from '@lezer/highlight';
17+
import CodeMirror from '@uiw/react-codemirror';
1818
import React from 'react';
1919

2020
import styles from '@/components/DevfileViewer/index.module.css';
@@ -27,37 +27,50 @@ export type Props = {
2727
};
2828

2929
export class DevfileViewer extends React.PureComponent<Props> {
30-
private editor: CodeMirror.Editor | undefined;
31-
32-
constructor(props: Props) {
33-
super(props);
34-
}
30+
public static theme = EditorView.theme(
31+
{
32+
'&': {
33+
color: '#2e3440',
34+
backgroundColor: '#fff',
35+
},
36+
'.cm-activeLine': {
37+
backgroundColor: 'inherit',
38+
},
39+
'.cm-gutters': {
40+
backgroundColor: '#f7f7f7',
41+
color: '#999',
42+
},
43+
'.cm-activeLineGutter': {
44+
backgroundColor: '#f7f7f7',
45+
},
46+
},
47+
{ dark: false },
48+
);
3549

36-
public componentDidMount(): void {
37-
const parent = window.document.querySelector(`#${this.props.id}`);
38-
if (parent) {
39-
this.editor = CodeMirror.fromTextArea(parent as HTMLTextAreaElement, {
40-
mode: 'yaml',
41-
theme: 'eclipse-che',
42-
lineNumbers: true,
43-
lineWrapping: true,
44-
readOnly: true,
45-
value: this.props.value,
46-
});
47-
}
48-
}
49-
50-
componentDidUpdate(): void {
51-
if (this.editor) {
52-
this.editor.setValue(this.props.value);
53-
this.editor.refresh();
54-
}
55-
}
50+
public static highlightStyle = HighlightStyle.define([
51+
{ tag: t.keyword, color: '#5e81ac' },
52+
{ tag: [t.string], color: '#5e81ac' },
53+
{ tag: [t.variableName], color: '#008080' },
54+
{
55+
tag: [t.name, t.deleted, t.character, t.propertyName, t.macroName],
56+
color: '#008080',
57+
},
58+
]);
5659

5760
public render(): React.ReactElement {
5861
return (
5962
<div className={styles.devfileViewer}>
60-
<textarea id={this.props.id} value={this.props.value} readOnly={true}></textarea>
63+
<CodeMirror
64+
className={styles.codeMirror}
65+
readOnly={true}
66+
id={this.props.id}
67+
value={this.props.value}
68+
extensions={[
69+
DevfileViewer.theme,
70+
syntaxHighlighting(DevfileViewer.highlightStyle),
71+
yaml(),
72+
]}
73+
/>
6174
</div>
6275
);
6376
}

packages/dashboard-frontend/src/components/DevfileViewer/theme/eclipse-che.css

Lines changed: 0 additions & 89 deletions
This file was deleted.

0 commit comments

Comments
 (0)