@patternfly/react-code-editor 4.43.17 → 4.43.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## 4.43.18 (2022-04-08)
7
+
8
+ **Note:** Version bump only for package @patternfly/react-code-editor
9
+
10
+
11
+
12
+
13
+
6
14
  ## 4.43.17 (2022-04-08)
7
15
 
8
16
  **Note:** Version bump only for package @patternfly/react-code-editor
package/README.md CHANGED
@@ -51,3 +51,5 @@ Install peer deps
51
51
  "react-dom": "^16.8.0 || ^17.0.0",
52
52
  "react-monaco-editor": "^0.41.2"
53
53
  ```
54
+
55
+ To properly install the library `monaco-editor-webpack-plugin` be sure to follow the [plugin instructions](https://github.com/microsoft/monaco-editor/tree/main/webpack-plugin)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-code-editor",
3
- "version": "4.43.17",
3
+ "version": "4.43.18",
4
4
  "description": "This package provides a PatternFly wrapper for the Monaco code editor\n",
5
5
  "main": "dist/js/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -30,9 +30,9 @@
30
30
  "clean": "rimraf dist"
31
31
  },
32
32
  "dependencies": {
33
- "@patternfly/react-core": "^4.202.17",
34
- "@patternfly/react-icons": "^4.53.17",
35
- "@patternfly/react-styles": "^4.52.17",
33
+ "@patternfly/react-core": "^4.202.18",
34
+ "@patternfly/react-icons": "^4.53.18",
35
+ "@patternfly/react-styles": "^4.52.18",
36
36
  "react-dropzone": "9.0.0",
37
37
  "tslib": "^2.0.0"
38
38
  },
@@ -46,5 +46,5 @@
46
46
  "rimraf": "^2.6.2",
47
47
  "typescript": "^4.0.0"
48
48
  },
49
- "gitHead": "5b271e203e018bbeb24b5a854f155e06062c446b"
49
+ "gitHead": "fd2bf430267635cb2473b40153f591fa853b47ad"
50
50
  }
@@ -12,284 +12,30 @@ import { CodeEditor, CodeEditorControl, Language } from '@patternfly/react-code-
12
12
  import PlayIcon from '@patternfly/react-icons/dist/esm/icons/play-icon';
13
13
 
14
14
  ## Examples
15
+
15
16
  ### Basic
16
- ```js
17
- import React from 'react';
18
- import { CodeEditor, Language } from '@patternfly/react-code-editor';
19
- import { Checkbox } from '@patternfly/react-core';
20
17
 
21
- class BasicCodeEditor extends React.Component {
22
- constructor(props) {
23
- super(props);
24
- this.state = {
25
- isDarkTheme: false,
26
- isLineNumbersVisible: true,
27
- isReadOnly: false,
28
- isMinimapVisible: true
29
- };
30
-
31
- this.toggleDarkTheme = checked => {
32
- this.setState({
33
- isDarkTheme: checked
34
- });
35
- };
36
- this.toggleLineNumbers = checked => {
37
- this.setState({
38
- isLineNumbersVisible: checked
39
- });
40
- };
41
- this.toggleReadOnly = checked => {
42
- this.setState({
43
- isReadOnly: checked
44
- });
45
- };
46
- this.toggleMinimap = checked => {
47
- this.setState({
48
- isMinimapVisible: checked
49
- })
50
- };
51
-
52
- this.onEditorDidMount = (editor, monaco) => {
53
- console.log(editor.getValue());
54
- editor.layout();
55
- editor.focus();
56
- monaco.editor.getModels()[0].updateOptions({ tabSize: 5 });
57
- };
58
-
59
- this.onChange = value => {
60
- console.log(value);
61
- };
62
- }
63
-
64
- render() {
65
- const { isDarkTheme, isLineNumbersVisible, isReadOnly, isMinimapVisible } = this.state;
66
-
67
- return (
68
- <>
69
- <Checkbox
70
- label="Dark theme"
71
- isChecked={isDarkTheme}
72
- onChange={this.toggleDarkTheme}
73
- aria-label="dark theme checkbox"
74
- id="toggle-theme"
75
- name="toggle-theme"
76
- />
77
- <Checkbox
78
- label="Line numbers"
79
- isChecked={isLineNumbersVisible}
80
- onChange={this.toggleLineNumbers}
81
- aria-label="line numbers checkbox"
82
- id="toggle-line-numbers"
83
- name="toggle-line-numbers"
84
- />
85
- <Checkbox
86
- label="Read only"
87
- isChecked={isReadOnly}
88
- onChange={this.toggleReadOnly}
89
- aria-label="read only checkbox"
90
- id="toggle-read-only"
91
- name="toggle-read-only"
92
- />
93
- <Checkbox
94
- label="Minimap"
95
- isChecked={isMinimapVisible}
96
- onChange={this.toggleMinimap}
97
- aria-label="display minimap checkbox"
98
- id="toggle-minimap"
99
- name="toggle-minimap"
100
- />
101
- <CodeEditor
102
- isDarkTheme={isDarkTheme}
103
- isLineNumbersVisible={isLineNumbersVisible}
104
- isReadOnly={isReadOnly}
105
- isMinimapVisible={isMinimapVisible}
106
- isLanguageLabelVisible
107
- code="Some example content"
108
- onChange={this.onChange}
109
- language={Language.javascript}
110
- onEditorDidMount={this.onEditorDidMount}
111
- height='400px'
112
- />
113
- </>
114
- );
115
- }
116
- }
18
+ ```ts file="./CodeEditorBasic.tsx"
117
19
  ```
118
20
 
119
21
  ### With sizeToFit height, height will grow/shrink with content
120
- ```js
121
- import React from 'react';
122
- import { CodeEditor, Language } from '@patternfly/react-code-editor';
123
22
 
124
- class BasicCodeEditor extends React.Component {
125
- constructor(props) {
126
- super(props);
127
-
128
- this.onEditorDidMount = (editor, monaco) => {
129
- console.log(editor.getValue());
130
- editor.layout();
131
- editor.focus();
132
- monaco.editor.getModels()[0].updateOptions({ tabSize: 5 });
133
- };
134
-
135
- this.onChange = value => {
136
- console.log(value);
137
- };
138
- }
139
-
140
- render() {
141
- return (
142
- <CodeEditor
143
- code="Some example content"
144
- onChange={this.onChange}
145
- language={Language.javascript}
146
- onEditorDidMount={this.onEditorDidMount}
147
- height='sizeToFit'
148
- />
149
- );
150
- }
151
- }
23
+ ```ts file="./CodeEditorSizeToFit.tsx"
152
24
  ```
153
25
 
154
- ### With shortcut menu and main header content.
26
+ ### With shortcut menu and main header content
27
+
155
28
  These examples below are the shortcuts that we recommend describing in the popover since they are monaco features.
156
- ```js
157
- import React from 'react';
158
- import { CodeEditor, Language } from '@patternfly/react-code-editor';
159
- import { Checkbox, Grid, GridItem, Chip } from '@patternfly/react-core';
160
29
 
161
- class BasicCodeEditor extends React.Component {
162
- constructor(props) {
163
- super(props);
164
-
165
- this.onEditorDidMount = (editor, monaco) => {
166
- console.log(editor.getValue());
167
- editor.layout();
168
- editor.focus();
169
- monaco.editor.getModels()[0].updateOptions({ tabSize: 5 });
170
- };
171
-
172
- this.onChange = value => {
173
- console.log(value);
174
- };
175
- }
176
-
177
- render() {
178
- const shortcuts = [
179
- {
180
- keys: ["Opt","F1"],
181
- description: "Accessibility helps",
182
- },
183
- {
184
- keys: ["F1"],
185
- description: "View all editor shortcuts",
186
- },
187
- {
188
- keys: ["Ctrl", "Space"],
189
- description: "Activate auto complete",
190
- },
191
- {
192
- keys: ["Cmd", "S"],
193
- description: "Save",
194
- },
195
- ];
196
- const shortcutsPopoverProps = {
197
- bodyContent:
198
- <Grid span={6} hasGutter>
199
- {shortcuts.map(s => (
200
- <>
201
- <GridItem style={{ textAlign: 'right', marginRight: '1em' }}>
202
- {s.keys
203
- .map(k => (
204
- <Chip key={k} isReadOnly>
205
- {k}
206
- </Chip>
207
- ))
208
- .reduce((prev, curr) => [prev, ' + ', curr])}
209
- </GridItem>
210
- <GridItem>{s.description}</GridItem>
211
- </>
212
- ))}
213
- </Grid>,
214
- 'aria-label': "Shortcuts",
215
- }
216
-
217
- return (
218
- <>
219
- <CodeEditor
220
- headerMainContent="Shortcut Example"
221
- shortcutsPopoverProps={shortcutsPopoverProps}
222
- isLanguageLabelVisible
223
- code="Some example content"
224
- onChange={this.onChange}
225
- language={Language.javascript}
226
- onEditorDidMount={this.onEditorDidMount}
227
- height='400px'
228
- />
229
- </>
230
- );
231
- }
232
- }
30
+ ```ts file="./CodeEditorShortcutMainHeader.tsx"
233
31
  ```
234
32
 
235
33
  ### With actions
236
- ```js
237
- import React from 'react';
238
- import { CodeEditor } from '@patternfly/react-code-editor';
239
34
 
240
- <CodeEditor
241
- isUploadEnabled
242
- isDownloadEnabled
243
- isCopyEnabled
244
- isLanguageLabelVisible
245
- height='400px'
246
- />
35
+ ```ts file="./CodeEditorWithActions.tsx"
247
36
  ```
248
37
 
249
38
  ### With custom control
250
- ```js
251
- import React from 'react';
252
- import { CodeEditor, CodeEditorControl } from '@patternfly/react-code-editor';
253
- import PlayIcon from '@patternfly/react-icons/dist/esm/icons/play-icon';
254
39
 
255
- class customControlExample extends React.Component {
256
- constructor(props) {
257
- super(props);
258
- this.state = {
259
- code: ''
260
- };
261
-
262
- this.onChange = code => {
263
- this.setState({ code })
264
- };
265
-
266
- this.onExecuteCode = (code) => {
267
- console.log(code);
268
- };
269
- }
270
-
271
- render() {
272
- const customControl = (
273
- <CodeEditorControl
274
- icon={<PlayIcon/>}
275
- aria-label="Execute code"
276
- toolTipText="Execute code"
277
- onClick={this.onExecuteCode}
278
- isVisible={this.state.code !== ''}
279
- />);
280
-
281
- return (
282
- <>
283
- <CodeEditor
284
- isDownloadEnabled
285
- isCopyEnabled
286
- height='400px'
287
- customControls={customControl}
288
- code={this.state.code}
289
- onChange={this.onChange}
290
- />
291
- </>
292
- );
293
- }
294
- }
40
+ ```ts file="CodeEditorCustomControl.tsx"
295
41
  ```
@@ -0,0 +1,86 @@
1
+ import React from 'react';
2
+ import { CodeEditor, Language } from '@patternfly/react-code-editor';
3
+ import { Checkbox } from '@patternfly/react-core';
4
+
5
+ export const CodeEditorBasic: React.FunctionComponent = () => {
6
+ const [isDarkTheme, setIsDarkTheme] = React.useState(false);
7
+ const [isLineNumbersVisible, setIsLineNumbersVisible] = React.useState(true);
8
+ const [isReadOnly, setIsReadOnly] = React.useState(false);
9
+ const [isMinimapVisible, setIsMinimapVisible] = React.useState(false);
10
+
11
+ const toggleDarkTheme = checked => {
12
+ setIsDarkTheme(checked);
13
+ };
14
+
15
+ const toggleLineNumbers = checked => {
16
+ setIsLineNumbersVisible(checked);
17
+ };
18
+ const toggleReadOnly = checked => {
19
+ setIsReadOnly(checked);
20
+ };
21
+ const toggleMinimap = checked => {
22
+ setIsMinimapVisible(checked);
23
+ };
24
+
25
+ const onEditorDidMount = (editor, monaco) => {
26
+ // eslint-disable-next-line no-console
27
+ console.log(editor.getValue());
28
+ editor.layout();
29
+ editor.focus();
30
+ monaco.editor.getModels()[0].updateOptions({ tabSize: 5 });
31
+ };
32
+
33
+ const onChange = value => {
34
+ // eslint-disable-next-line no-console
35
+ console.log(value);
36
+ };
37
+
38
+ return (
39
+ <>
40
+ <Checkbox
41
+ label="Dark theme"
42
+ isChecked={isDarkTheme}
43
+ onChange={toggleDarkTheme}
44
+ aria-label="dark theme checkbox"
45
+ id="toggle-theme"
46
+ name="toggle-theme"
47
+ />
48
+ <Checkbox
49
+ label="Line numbers"
50
+ isChecked={isLineNumbersVisible}
51
+ onChange={toggleLineNumbers}
52
+ aria-label="line numbers checkbox"
53
+ id="toggle-line-numbers"
54
+ name="toggle-line-numbers"
55
+ />
56
+ <Checkbox
57
+ label="Read only"
58
+ isChecked={isReadOnly}
59
+ onChange={toggleReadOnly}
60
+ aria-label="read only checkbox"
61
+ id="toggle-read-only"
62
+ name="toggle-read-only"
63
+ />
64
+ <Checkbox
65
+ label="Minimap"
66
+ isChecked={isMinimapVisible}
67
+ onChange={toggleMinimap}
68
+ aria-label="display minimap checkbox"
69
+ id="toggle-minimap"
70
+ name="toggle-minimap"
71
+ />
72
+ <CodeEditor
73
+ isDarkTheme={isDarkTheme}
74
+ isLineNumbersVisible={isLineNumbersVisible}
75
+ isReadOnly={isReadOnly}
76
+ isMinimapVisible={isMinimapVisible}
77
+ isLanguageLabelVisible
78
+ code="Some example content"
79
+ onChange={onChange}
80
+ language={Language.javascript}
81
+ onEditorDidMount={onEditorDidMount}
82
+ height="400px"
83
+ />
84
+ </>
85
+ );
86
+ };
@@ -0,0 +1,37 @@
1
+ import React from 'react';
2
+ import { CodeEditor, CodeEditorControl } from '@patternfly/react-code-editor';
3
+ import PlayIcon from '@patternfly/react-icons/dist/esm/icons/play-icon';
4
+
5
+ export const CodeEditorCustomControl: React.FunctionComponent = () => {
6
+ const [code, setCode] = React.useState('');
7
+
8
+ const onChange = code => {
9
+ setCode(code);
10
+ };
11
+
12
+ const onExecuteCode = code => {
13
+ // eslint-disable-next-line no-console
14
+ console.log(code);
15
+ };
16
+
17
+ const customControl = (
18
+ <CodeEditorControl
19
+ icon={<PlayIcon />}
20
+ aria-label="Execute code"
21
+ toolTipText="Execute code"
22
+ onClick={onExecuteCode}
23
+ isVisible={code !== ''}
24
+ />
25
+ );
26
+
27
+ return (
28
+ <CodeEditor
29
+ isDownloadEnabled
30
+ isCopyEnabled
31
+ height="400px"
32
+ customControls={customControl}
33
+ code={code}
34
+ onChange={onChange}
35
+ />
36
+ );
37
+ };
@@ -0,0 +1,73 @@
1
+ import React from 'react';
2
+ import { CodeEditor, Language } from '@patternfly/react-code-editor';
3
+ import { Grid, GridItem, Chip } from '@patternfly/react-core';
4
+
5
+ export const CodeEditorShortcutMainHeader: React.FunctionComponent = () => {
6
+ const onEditorDidMount = (editor, monaco) => {
7
+ // eslint-disable-next-line no-console
8
+ console.log(editor.getValue());
9
+ editor.layout();
10
+ editor.focus();
11
+ monaco.editor.getModels()[0].updateOptions({ tabSize: 5 });
12
+ };
13
+
14
+ const onChange = value => {
15
+ // eslint-disable-next-line no-console
16
+ console.log(value);
17
+ };
18
+
19
+ const shortcuts = [
20
+ {
21
+ keys: ['Opt', 'F1'],
22
+ description: 'Accessibility helps'
23
+ },
24
+ {
25
+ keys: ['F1'],
26
+ description: 'View all editor shortcuts'
27
+ },
28
+ {
29
+ keys: ['Ctrl', 'Space'],
30
+ description: 'Activate auto complete'
31
+ },
32
+ {
33
+ keys: ['Cmd', 'S'],
34
+ description: 'Save'
35
+ }
36
+ ];
37
+ const shortcutsPopoverProps = {
38
+ bodyContent: (
39
+ <Grid span={6} hasGutter>
40
+ {shortcuts.map(s => (
41
+ <>
42
+ <GridItem style={{ textAlign: 'right', marginRight: '1em' }}>
43
+ {s.keys
44
+ .map(k => (
45
+ <Chip key={k} isReadOnly>
46
+ {k}
47
+ </Chip>
48
+ ))
49
+ .reduce((prev, curr) => (
50
+ <>{[prev, ' + ', curr]}</>
51
+ ))}
52
+ </GridItem>
53
+ <GridItem>{s.description}</GridItem>
54
+ </>
55
+ ))}
56
+ </Grid>
57
+ ),
58
+ 'aria-label': 'Shortcuts'
59
+ };
60
+
61
+ return (
62
+ <CodeEditor
63
+ headerMainContent="Shortcut Example"
64
+ shortcutsPopoverProps={shortcutsPopoverProps}
65
+ isLanguageLabelVisible
66
+ code="Some example content"
67
+ onChange={onChange}
68
+ language={Language.javascript}
69
+ onEditorDidMount={onEditorDidMount}
70
+ height="400px"
71
+ />
72
+ );
73
+ };
@@ -0,0 +1,27 @@
1
+ import React from 'react';
2
+ import { CodeEditor, Language } from '@patternfly/react-code-editor';
3
+
4
+ export const CodeEditorSizeToFit: React.FunctionComponent = () => {
5
+ const onEditorDidMount = (editor, monaco) => {
6
+ // eslint-disable-next-line no-console
7
+ console.log(editor.getValue());
8
+ editor.layout();
9
+ editor.focus();
10
+ monaco.editor.getModels()[0].updateOptions({ tabSize: 5 });
11
+ };
12
+
13
+ const onChange = value => {
14
+ // eslint-disable-next-line no-console
15
+ console.log(value);
16
+ };
17
+
18
+ return (
19
+ <CodeEditor
20
+ code="Some example content"
21
+ onChange={onChange}
22
+ language={Language.javascript}
23
+ onEditorDidMount={onEditorDidMount}
24
+ height="sizeToFit"
25
+ />
26
+ );
27
+ };
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import { CodeEditor } from '@patternfly/react-code-editor';
3
+
4
+ export const CodeEditorWithActions: React.FunctionComponent = () => (
5
+ <CodeEditor isUploadEnabled isDownloadEnabled isCopyEnabled isLanguageLabelVisible height="400px" />
6
+ );