@patternfly/react-code-editor 6.2.1-prerelease.3 → 6.2.1-prerelease.4

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,10 @@
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
+ ## [6.2.1-prerelease.4](https://github.com/patternfly/patternfly-react/compare/@patternfly/react-code-editor@6.2.1-prerelease.3...@patternfly/react-code-editor@6.2.1-prerelease.4) (2025-04-14)
7
+
8
+ **Note:** Version bump only for package @patternfly/react-code-editor
9
+
6
10
  ## [6.2.1-prerelease.3](https://github.com/patternfly/patternfly-react/compare/@patternfly/react-code-editor@6.2.1-prerelease.2...@patternfly/react-code-editor@6.2.1-prerelease.3) (2025-04-11)
7
11
 
8
12
  **Note:** Version bump only for package @patternfly/react-code-editor
@@ -1,9 +1,8 @@
1
- import { Component } from 'react';
1
+ import { HTMLProps, ReactNode } from 'react';
2
2
  import { PopoverProps } from '@patternfly/react-core/dist/esm/components/Popover';
3
3
  import { TooltipPosition } from '@patternfly/react-core/dist/esm/components/Tooltip';
4
4
  import { EditorProps, Monaco } from '@monaco-editor/react';
5
5
  import type { editor } from 'monaco-editor';
6
- import { FileRejection } from 'react-dropzone';
7
6
  export type ChangeHandler = (value: string, event: editor.IModelContentChangedEvent) => void;
8
7
  export type EditorDidMount = (editor: editor.IStandaloneCodeEditor, monaco: Monaco) => void;
9
8
  export interface Shortcut {
@@ -88,7 +87,7 @@ export declare enum Language {
88
87
  yaml = "yaml"
89
88
  }
90
89
  /** The main code editor component. */
91
- export interface CodeEditorProps extends Omit<React.HTMLProps<HTMLDivElement>, 'onChange'> {
90
+ export interface CodeEditorProps extends Omit<HTMLProps<HTMLDivElement>, 'onChange'> {
92
91
  /** Additional classes added to the code editor. */
93
92
  className?: string;
94
93
  /** Code displayed in code editor. */
@@ -102,7 +101,7 @@ export interface CodeEditorProps extends Omit<React.HTMLProps<HTMLDivElement>, '
102
101
  /** A single node or array of nodes - ideally the code editor controls component - to display
103
102
  * above code editor.
104
103
  */
105
- customControls?: React.ReactNode | React.ReactNode[];
104
+ customControls?: ReactNode | ReactNode[];
106
105
  /** Accessible label for the download button. */
107
106
  downloadButtonAriaLabel?: string;
108
107
  /** Text to display in the tooltip on the download button. */
@@ -112,15 +111,15 @@ export interface CodeEditorProps extends Omit<React.HTMLProps<HTMLDivElement>, '
112
111
  /** Additional props to pass to the monaco editor. */
113
112
  editorProps?: EditorProps;
114
113
  /** Content to display in space of the code editor when there is no code to display. */
115
- emptyState?: React.ReactNode;
114
+ emptyState?: ReactNode;
116
115
  /** Override default empty state body text. */
117
- emptyStateBody?: React.ReactNode;
116
+ emptyStateBody?: ReactNode;
118
117
  /** Override default empty state button text. */
119
- emptyStateButton?: React.ReactNode;
118
+ emptyStateButton?: ReactNode;
120
119
  /** Override default empty state link text. */
121
- emptyStateLink?: React.ReactNode;
120
+ emptyStateLink?: ReactNode;
122
121
  /** Override default empty state title text. */
123
- emptyStateTitle?: React.ReactNode;
122
+ emptyStateTitle?: ReactNode;
124
123
  /** Editor header main content title. */
125
124
  headerMainContent?: string;
126
125
  /** Height of code editor. 'sizeToFit' will automatically change the height
@@ -151,13 +150,16 @@ export interface CodeEditorProps extends Omit<React.HTMLProps<HTMLDivElement>, '
151
150
  /** Language displayed in the editor. */
152
151
  language?: Language;
153
152
  /** The loading screen before the editor will be loaded. Defaults to 'loading...'. */
154
- loading?: React.ReactNode;
153
+ loading?: ReactNode;
155
154
  /** Function which fires each time the content of the code editor is manually changed. Does
156
155
  * not fire when a file is uploaded.
157
156
  */
158
157
  onChange?: ChangeHandler;
159
158
  /** Function which fires each time the code changes in the code editor. */
160
159
  onCodeChange?: (value: string) => void;
160
+ /** Function which fires when the code is downloaded. Defaults to a function that
161
+ * downloads the current editor content. */
162
+ onDownload?: (value: string, fileName: string) => void;
161
163
  /** Callback which fires after the code editor is mounted containing a reference to the
162
164
  * monaco editor and the monaco instance.
163
165
  */
@@ -167,17 +169,17 @@ export interface CodeEditorProps extends Omit<React.HTMLProps<HTMLDivElement>, '
167
169
  /** Refer to Monaco interface {monaco.editor.IEditorOverrideServices}. */
168
170
  overrideServices?: editor.IEditorOverrideServices;
169
171
  /** Text to show in the button to open the shortcut popover. */
170
- shortcutsPopoverButtonText: string;
172
+ shortcutsPopoverButtonText?: string;
171
173
  /** Properties for the shortcut popover. */
172
174
  shortcutsPopoverProps?: PopoverProps;
173
175
  /** Flag to show the editor. */
174
176
  showEditor?: boolean;
175
177
  /** The delay before tooltip fades after code copied. */
176
- toolTipCopyExitDelay: number;
178
+ toolTipCopyExitDelay?: number;
177
179
  /** The entry and exit delay for all tooltips. */
178
- toolTipDelay: number;
180
+ toolTipDelay?: number;
179
181
  /** The max width of the tooltips on all button. */
180
- toolTipMaxWidth: string;
182
+ toolTipMaxWidth?: string;
181
183
  /** The position of tooltips on all buttons. */
182
184
  toolTipPosition?: TooltipPosition | 'auto' | 'top' | 'bottom' | 'left' | 'right' | 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end' | 'left-start' | 'left-end' | 'right-start' | 'right-end';
183
185
  /** Accessible label for the upload button. */
@@ -187,46 +189,8 @@ export interface CodeEditorProps extends Omit<React.HTMLProps<HTMLDivElement>, '
187
189
  /** Width of code editor. Defaults to 100%. */
188
190
  width?: string;
189
191
  }
190
- interface CodeEditorState {
191
- height: string;
192
- prevPropsCode: string;
193
- value: string;
194
- filename: string;
195
- isLoading: boolean;
196
- showEmptyState: boolean;
197
- copied: boolean;
198
- }
199
- declare class CodeEditor extends Component<CodeEditorProps, CodeEditorState> {
200
- static displayName: string;
201
- private editor;
202
- private wrapperRef;
203
- private ref;
204
- private timer;
205
- private observer;
206
- static defaultProps: CodeEditorProps;
207
- static getExtensionFromLanguage(language: Language): string;
208
- constructor(props: CodeEditorProps);
209
- setHeightToFitContent(): void;
210
- onChange: ChangeHandler;
211
- static getDerivedStateFromProps(nextProps: CodeEditorProps, prevState: CodeEditorState): {
212
- value: string;
213
- prevPropsCode: string;
214
- };
215
- handleResize: () => void;
216
- componentDidMount(): void;
217
- componentWillUnmount(): void;
218
- handleGlobalKeys: (event: KeyboardEvent) => void;
219
- editorDidMount: EditorDidMount;
220
- handleFileChange: (value: string, filename: string) => void;
221
- handleFileReadStarted: () => void;
222
- handleFileReadFinished: () => void;
223
- readFile(fileHandle: Blob): Promise<string>;
224
- onDropAccepted: (acceptedFiles: File[]) => void;
225
- onDropRejected: (rejectedFiles: FileRejection[]) => void;
226
- copyCode: () => void;
227
- download: () => void;
228
- toggleEmptyState: () => void;
229
- render(): import("react/jsx-runtime").JSX.Element;
230
- }
231
- export { CodeEditor };
192
+ export declare const CodeEditor: {
193
+ ({ className, code, copyButtonAriaLabel, copyButtonSuccessTooltipText, copyButtonToolTipText, customControls, downloadButtonAriaLabel, downloadButtonToolTipText, downloadFileName, editorProps, emptyState, emptyStateBody, emptyStateButton, emptyStateLink, emptyStateTitle, headerMainContent, height, isCopyEnabled, isDarkTheme, isDownloadEnabled, isFullHeight, isHeaderPlain, isLanguageLabelVisible, isLineNumbersVisible, isMinimapVisible, isReadOnly, isUploadEnabled, language, loading, onChange, onCodeChange, onDownload, onEditorDidMount, options, overrideServices, shortcutsPopoverButtonText, shortcutsPopoverProps, showEditor, toolTipCopyExitDelay, toolTipDelay, toolTipMaxWidth, toolTipPosition, uploadButtonAriaLabel, uploadButtonToolTipText, width }: CodeEditorProps): import("react/jsx-runtime").JSX.Element;
194
+ displayName: string;
195
+ };
232
196
  //# sourceMappingURL=CodeEditor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CodeEditor.d.ts","sourceRoot":"","sources":["../../../../src/components/CodeEditor/CodeEditor.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAuB,MAAM,OAAO,CAAC;AAYvD,OAAO,EAAW,YAAY,EAAE,MAAM,oDAAoD,CAAC;AAC3F,OA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AC;IACtD,yEAAyE;IACzE,gBAAgB,CAAC,EAAE,MAAM,CAAC,uBAAuB,CAAC;IAClD,+DAA+D;IAC/D,0BAA0B,CAAC,EAAE,MAAM,CAAC;IACpC,2CAA2C;IAC3C,qBAAqB,CAAC,EAAE,YAAY,CAAC;IACrC,+BAA+B;IAC/B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,wDAAwD;IACxD,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,iDAAiD;IACjD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,mDAAmD;IACnD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,+CAA+C;IAC/C,eAAe,CAAC,EACZ,eAAe,GACf,MAAM,GACN,KAAK,GACL,QAAQ,GACR,MAAM,GACN,OAAO,GACP,WAAW,GACX,SAAS,GACT,cAAc,GACd,YAAY,GACZ,YAAY,GACZ,UAAU,GACV,aAAa,GACb,WAAW,CAAC;IAChB,8CAA8C;IAC9C,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,2DAA2D;IAC3D,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,8CAA8C;IAC9C,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAqCD,eAAO,MAAM,UAAU;0vBA8CpB,eAAe;;CA2TjB,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { Component, createRef, Fragment } from 'react';
2
+ import { useEffect, useRef, useState } from 'react';
3
3
  import { css } from '@patternfly/react-styles';
4
4
  import styles from '@patternfly/react-styles/css/components/CodeEditor/code-editor.mjs';
5
5
  import fileUploadStyles from '@patternfly/react-styles/css/components/FileUpload/file-upload.mjs';
@@ -94,246 +94,168 @@ export var Language;
94
94
  Language["xml"] = "xml";
95
95
  Language["yaml"] = "yaml";
96
96
  })(Language || (Language = {}));
97
- class CodeEditor extends Component {
98
- static getExtensionFromLanguage(language) {
99
- switch (language) {
100
- case Language.shell:
101
- return 'sh';
102
- case Language.ruby:
103
- return 'rb';
104
- case Language.perl:
105
- return 'pl';
106
- case Language.python:
107
- return 'py';
108
- case Language.mysql:
109
- return 'sql';
110
- case Language.javascript:
111
- return 'js';
112
- case Language.typescript:
113
- return 'ts';
114
- case Language.markdown:
115
- return 'md';
116
- case Language.plaintext:
117
- return 'txt';
118
- default:
119
- return language.toString();
120
- }
97
+ const getExtensionFromLanguage = (language) => {
98
+ switch (language) {
99
+ case Language.shell:
100
+ return 'sh';
101
+ case Language.ruby:
102
+ return 'rb';
103
+ case Language.perl:
104
+ return 'pl';
105
+ case Language.python:
106
+ return 'py';
107
+ case Language.mysql:
108
+ return 'sql';
109
+ case Language.javascript:
110
+ return 'js';
111
+ case Language.typescript:
112
+ return 'ts';
113
+ case Language.markdown:
114
+ return 'md';
115
+ case Language.plaintext:
116
+ return 'txt';
117
+ default:
118
+ return language.toString();
121
119
  }
122
- constructor(props) {
123
- super(props);
124
- this.editor = null;
125
- this.wrapperRef = createRef();
126
- this.ref = createRef();
127
- this.timer = null;
128
- this.observer = () => { };
129
- this.onChange = (value, event) => {
130
- if (this.props.height === 'sizeToFit') {
131
- this.setHeightToFitContent();
132
- }
133
- if (this.props.onChange) {
134
- this.props.onChange(value, event);
135
- }
136
- this.setState({ value });
137
- this.props.onCodeChange(value);
138
- };
139
- this.handleResize = () => {
140
- if (this.editor) {
141
- this.editor.layout({ width: 0, height: 0 }); // ensures the editor won't take up more space than it needs
142
- this.editor.layout();
143
- }
144
- };
145
- this.handleGlobalKeys = (event) => {
146
- var _a;
147
- if (this.wrapperRef.current === document.activeElement && (event.key === 'ArrowDown' || event.key === ' ')) {
148
- (_a = this.editor) === null || _a === void 0 ? void 0 : _a.focus();
149
- event.preventDefault();
150
- }
151
- };
152
- this.editorDidMount = (editor, monaco) => {
153
- // eslint-disable-next-line no-bitwise
154
- editor.addCommand(monaco.KeyMod.Shift | monaco.KeyCode.Tab, () => this.wrapperRef.current.focus());
155
- Array.from(document.getElementsByClassName('monaco-editor')).forEach((editorElement) => editorElement.removeAttribute('role'));
156
- this.props.onEditorDidMount(editor, monaco);
157
- this.editor = editor;
158
- if (this.props.height === 'sizeToFit') {
159
- this.setHeightToFitContent();
160
- }
161
- };
162
- this.handleFileChange = (value, filename) => {
163
- this.setState({
164
- value,
165
- filename
166
- });
167
- this.props.onCodeChange(value);
168
- };
169
- this.handleFileReadStarted = () => this.setState({ isLoading: true });
170
- this.handleFileReadFinished = () => this.setState({ isLoading: false });
171
- this.onDropAccepted = (acceptedFiles) => {
172
- if (acceptedFiles.length > 0) {
173
- const fileHandle = acceptedFiles[0];
174
- this.handleFileChange('', fileHandle.name); // Show the filename while reading
175
- this.handleFileReadStarted();
176
- this.readFile(fileHandle)
177
- .then((data) => {
178
- this.handleFileReadFinished();
179
- this.toggleEmptyState();
180
- this.handleFileChange(data, fileHandle.name);
181
- })
182
- .catch((error) => {
183
- // eslint-disable-next-line no-console
184
- console.error('error', error);
185
- this.handleFileReadFinished();
186
- this.handleFileChange('', ''); // Clear the filename field on a failure
187
- });
188
- }
120
+ };
121
+ /**
122
+ * Downloads a file to a users device given its string content and a full file name.
123
+ */
124
+ const defaultOnDownload = (value, fileName) => {
125
+ const link = document.createElement('a');
126
+ link.href = URL.createObjectURL(new Blob([value], { type: 'text' }));
127
+ link.download = fileName;
128
+ link.click();
129
+ };
130
+ export const CodeEditor = ({ className = '', code = '', copyButtonAriaLabel = 'Copy code to clipboard', copyButtonSuccessTooltipText = 'Content added to clipboard', copyButtonToolTipText = 'Copy to clipboard', customControls = null, downloadButtonAriaLabel = 'Download code', downloadButtonToolTipText = 'Download', downloadFileName = Date.now().toString(), editorProps, emptyState = '', emptyStateBody = 'Drag and drop a file or upload one.', emptyStateButton = 'Browse', emptyStateLink = 'Start from scratch', emptyStateTitle = 'Start editing', headerMainContent = '', height, isCopyEnabled = false, isDarkTheme = false, isDownloadEnabled = false, isFullHeight = false, isHeaderPlain = false, isLanguageLabelVisible = false, isLineNumbersVisible = true, isMinimapVisible = false, isReadOnly = false, isUploadEnabled = false, language = Language.plaintext, loading = '', onChange = () => { }, onCodeChange = () => { }, onDownload = defaultOnDownload, onEditorDidMount = () => { }, options = {}, overrideServices = {}, shortcutsPopoverButtonText = 'View Shortcuts', shortcutsPopoverProps = { bodyContent: '', 'aria-label': 'Keyboard Shortcuts' }, showEditor = true, toolTipCopyExitDelay = 1600, toolTipDelay = 300, toolTipMaxWidth = '100px', toolTipPosition = 'top', uploadButtonAriaLabel = 'Upload code', uploadButtonToolTipText = 'Upload', width = '' }) => {
131
+ const [value, setValue] = useState(code);
132
+ const [isLoading, setIsLoading] = useState(false);
133
+ const [showEmptyState, setShowEmptyState] = useState(true);
134
+ const [copied, setCopied] = useState(false);
135
+ const editorRef = useRef(null);
136
+ const wrapperRef = useRef(null);
137
+ const ref = useRef(null);
138
+ const observer = useRef(() => { });
139
+ const setHeightToFitContent = () => {
140
+ var _a, _b, _c;
141
+ const contentHeight = (_a = editorRef.current) === null || _a === void 0 ? void 0 : _a.getContentHeight();
142
+ const layoutInfo = (_b = editorRef.current) === null || _b === void 0 ? void 0 : _b.getLayoutInfo();
143
+ (_c = editorRef.current) === null || _c === void 0 ? void 0 : _c.layout({ width: layoutInfo.width, height: contentHeight });
144
+ };
145
+ const onModelChange = (value, event) => {
146
+ if (height === 'sizeToFit') {
147
+ setHeightToFitContent();
148
+ }
149
+ if (onChange) {
150
+ onChange(value, event);
151
+ }
152
+ setValue(value);
153
+ onCodeChange(value);
154
+ };
155
+ const handleResize = () => {
156
+ if (editorRef.current) {
157
+ editorRef.current.layout({ width: 0, height: 0 }); // ensures the editor won't take up more space than it needs
158
+ editorRef.current.layout();
159
+ }
160
+ };
161
+ const handleGlobalKeys = (event) => {
162
+ var _a;
163
+ if (wrapperRef.current === document.activeElement && (event.key === 'ArrowDown' || event.key === ' ')) {
164
+ (_a = editorRef.current) === null || _a === void 0 ? void 0 : _a.focus();
165
+ event.preventDefault();
166
+ }
167
+ };
168
+ // if the code changes due to the prop changing
169
+ // set the value to the code prop
170
+ useEffect(() => setValue(code), [code]);
171
+ useEffect(() => {
172
+ document.addEventListener('keydown', handleGlobalKeys);
173
+ observer.current = getResizeObserver(ref.current, handleResize, true);
174
+ handleResize();
175
+ return () => {
176
+ document.removeEventListener('keydown', handleGlobalKeys);
177
+ observer.current();
189
178
  };
190
- this.onDropRejected = (rejectedFiles) => {
191
- if (rejectedFiles.length > 0) {
179
+ }, []);
180
+ const editorDidMount = (editor, monaco) => {
181
+ // eslint-disable-next-line no-bitwise
182
+ editor.addCommand(monaco.KeyMod.Shift | monaco.KeyCode.Tab, () => wrapperRef.current.focus());
183
+ Array.from(document.getElementsByClassName('monaco-editor')).forEach((editorElement) => editorElement.removeAttribute('role'));
184
+ onEditorDidMount(editor, monaco);
185
+ editorRef.current = editor;
186
+ if (height === 'sizeToFit') {
187
+ setHeightToFitContent();
188
+ }
189
+ };
190
+ const handleFileChange = (value) => {
191
+ setValue(value);
192
+ onCodeChange(value);
193
+ };
194
+ const handleFileReadStarted = () => setIsLoading(true);
195
+ const handleFileReadFinished = () => setIsLoading(false);
196
+ const readFile = (fileHandle) => new Promise((resolve, reject) => {
197
+ const reader = new FileReader();
198
+ reader.onload = () => resolve(reader.result);
199
+ reader.onerror = () => reject(reader.error);
200
+ reader.readAsText(fileHandle);
201
+ });
202
+ const onDropAccepted = (acceptedFiles) => {
203
+ if (acceptedFiles.length > 0) {
204
+ const fileHandle = acceptedFiles[0];
205
+ handleFileChange(''); // Show the filename while reading
206
+ handleFileReadStarted();
207
+ readFile(fileHandle)
208
+ .then((data) => {
209
+ handleFileReadFinished();
210
+ setShowEmptyState(false);
211
+ handleFileChange(data);
212
+ })
213
+ .catch((error) => {
192
214
  // eslint-disable-next-line no-console
193
- console.error('There was an error accepting that dropped file'); // TODO
194
- }
195
- };
196
- this.copyCode = () => {
197
- navigator.clipboard.writeText(this.state.value);
198
- this.setState({ copied: true });
199
- };
200
- this.download = () => {
201
- const { value } = this.state;
202
- const element = document.createElement('a');
203
- const file = new Blob([value], { type: 'text' });
204
- element.href = URL.createObjectURL(file);
205
- element.download = `${this.props.downloadFileName}.${CodeEditor.getExtensionFromLanguage(this.props.language)}`;
206
- document.body.appendChild(element); // Required for this to work in FireFox
207
- element.click();
208
- };
209
- this.toggleEmptyState = () => {
210
- this.setState({ showEmptyState: false });
211
- };
212
- this.state = {
213
- height: this.props.height,
214
- prevPropsCode: this.props.code,
215
- value: this.props.code,
216
- filename: '',
217
- isLoading: false,
218
- showEmptyState: true,
219
- copied: false
220
- };
221
- }
222
- setHeightToFitContent() {
223
- const contentHeight = this.editor.getContentHeight();
224
- const layoutInfo = this.editor.getLayoutInfo();
225
- this.editor.layout({ width: layoutInfo.width, height: contentHeight });
226
- }
227
- // this function is only called when the props change
228
- // the only conflict is between props.code and state.value
229
- static getDerivedStateFromProps(nextProps, prevState) {
230
- // if the code changes due to the props.code changing
231
- // set the value to props.code
232
- if (nextProps.code !== prevState.prevPropsCode) {
233
- return {
234
- value: nextProps.code,
235
- prevPropsCode: nextProps.code
236
- };
215
+ console.error('error', error);
216
+ handleFileReadFinished();
217
+ handleFileChange('');
218
+ });
237
219
  }
238
- // else, don't need to change the state.value
239
- // because the onChange function will do all the work
240
- return null;
241
- }
242
- componentDidMount() {
243
- document.addEventListener('keydown', this.handleGlobalKeys);
244
- this.observer = getResizeObserver(this.ref.current, this.handleResize, true);
245
- this.handleResize();
246
- }
247
- componentWillUnmount() {
248
- document.removeEventListener('keydown', this.handleGlobalKeys);
249
- this.observer();
250
- }
251
- readFile(fileHandle) {
252
- return new Promise((resolve, reject) => {
253
- const reader = new FileReader();
254
- reader.onload = () => resolve(reader.result);
255
- reader.onerror = () => reject(reader.error);
256
- reader.readAsText(fileHandle);
257
- });
258
- }
259
- render() {
260
- const { height, value, isLoading, showEmptyState, copied } = this.state;
261
- const { isDarkTheme, width, className, isCopyEnabled, copyButtonSuccessTooltipText, isReadOnly, isUploadEnabled, isLanguageLabelVisible, copyButtonAriaLabel, copyButtonToolTipText, uploadButtonAriaLabel, uploadButtonToolTipText, downloadButtonAriaLabel, downloadButtonToolTipText, toolTipDelay, toolTipCopyExitDelay, toolTipMaxWidth, toolTipPosition, isLineNumbersVisible, isDownloadEnabled, language, emptyState: providedEmptyState, emptyStateTitle, emptyStateBody, emptyStateButton, emptyStateLink, customControls, isMinimapVisible, isHeaderPlain, headerMainContent, shortcutsPopoverButtonText, shortcutsPopoverProps: shortcutsPopoverPropsProp, showEditor, options: optionsProp, overrideServices, loading, editorProps } = this.props;
262
- const shortcutsPopoverProps = Object.assign(Object.assign({}, CodeEditor.defaultProps.shortcutsPopoverProps), shortcutsPopoverPropsProp);
263
- const options = Object.assign({ scrollBeyondLastLine: height !== 'sizeToFit', readOnly: isReadOnly, cursorStyle: 'line', lineNumbers: isLineNumbersVisible ? 'on' : 'off', tabIndex: -1, minimap: {
264
- enabled: isMinimapVisible
265
- } }, optionsProp);
266
- const isFullHeight = this.props.height === '100%' ? true : this.props.isFullHeight;
267
- return (_jsx(Dropzone, { multiple: false, onDropAccepted: this.onDropAccepted, onDropRejected: this.onDropRejected, children: ({ getRootProps, getInputProps, isDragActive, open }) => {
268
- const emptyState = providedEmptyState ||
269
- (isUploadEnabled ? (_jsxs(EmptyState, { variant: EmptyStateVariant.sm, titleText: emptyStateTitle, icon: CodeIcon, headingLevel: "h4", children: [_jsx(EmptyStateBody, { children: emptyStateBody }), !isReadOnly && (_jsxs(EmptyStateFooter, { children: [_jsx(EmptyStateActions, { children: _jsx(Button, { variant: "primary", onClick: open, children: emptyStateButton }) }), _jsx(EmptyStateActions, { children: _jsx(Button, { variant: "link", onClick: this.toggleEmptyState, children: emptyStateLink }) })] }))] })) : (_jsx(EmptyState, { variant: EmptyStateVariant.sm, titleText: emptyStateTitle, icon: CodeIcon, headingLevel: "h4", children: !isReadOnly && (_jsx(EmptyStateFooter, { children: _jsx(EmptyStateActions, { children: _jsx(Button, { variant: "primary", onClick: this.toggleEmptyState, children: emptyStateLink }) }) })) })));
270
- const tooltipProps = {
271
- position: toolTipPosition,
272
- exitDelay: toolTipDelay,
273
- entryDelay: toolTipDelay,
274
- maxWidth: toolTipMaxWidth,
275
- trigger: 'mouseenter focus'
276
- };
277
- const hasEditorHeaderContent = ((isCopyEnabled || isDownloadEnabled) && (!showEmptyState || !!value)) ||
278
- isUploadEnabled ||
279
- customControls ||
280
- headerMainContent ||
281
- !!shortcutsPopoverProps.bodyContent;
282
- const editorHeaderContent = (_jsxs(Fragment, { children: [_jsx("div", { className: css(styles.codeEditorControls), children: _jsxs(CodeEditorContext.Provider, { value: { code: value }, children: [isCopyEnabled && (!showEmptyState || !!value) && (_jsx(CodeEditorControl, { icon: _jsx(CopyIcon, {}), "aria-label": copyButtonAriaLabel, tooltipProps: Object.assign(Object.assign({}, tooltipProps), { 'aria-live': 'polite', content: _jsx("div", { children: copied ? copyButtonSuccessTooltipText : copyButtonToolTipText }), exitDelay: copied ? toolTipCopyExitDelay : toolTipDelay, onTooltipHidden: () => this.setState({ copied: false }) }), onClick: this.copyCode })), isUploadEnabled && (_jsx(CodeEditorControl, { icon: _jsx(UploadIcon, {}), "aria-label": uploadButtonAriaLabel, tooltipProps: Object.assign({ content: _jsx("div", { children: uploadButtonToolTipText }) }, tooltipProps), onClick: open })), isDownloadEnabled && (!showEmptyState || !!value) && (_jsx(CodeEditorControl, { icon: _jsx(DownloadIcon, {}), "aria-label": downloadButtonAriaLabel, tooltipProps: Object.assign({ content: _jsx("div", { children: downloadButtonToolTipText }) }, tooltipProps), onClick: this.download })), customControls && customControls] }) }), headerMainContent && _jsx("div", { className: css(styles.codeEditorHeaderMain), children: headerMainContent }), !!shortcutsPopoverProps.bodyContent && (_jsx("div", { className: `${styles.codeEditor}__keyboard-shortcuts`, children: _jsx(Popover, Object.assign({}, shortcutsPopoverProps, { children: _jsx(Button, { variant: ButtonVariant.link, icon: _jsx(HelpIcon, {}), children: shortcutsPopoverButtonText }) })) }))] }));
283
- const editorHeader = (_jsxs("div", { className: css(styles.codeEditorHeader, isHeaderPlain && styles.modifiers.plain), children: [hasEditorHeaderContent && (_jsx("div", { className: css(styles.codeEditorHeaderContent), children: editorHeaderContent })), isLanguageLabelVisible && (_jsxs("div", { className: css(styles.codeEditorTab), children: [_jsx("span", { className: css(styles.codeEditorTabIcon), children: _jsx(CodeIcon, {}) }), _jsx("span", { className: css(styles.codeEditorTabText), children: language.toUpperCase() })] }))] }));
284
- const editor = (_jsx("div", { className: css(styles.codeEditorCode), ref: this.wrapperRef, tabIndex: 0, dir: "ltr", children: _jsx(Editor, Object.assign({ height: height === '100%' ? undefined : height, width: width, language: language, value: value, options: options, overrideServices: overrideServices, onChange: this.onChange, onMount: this.editorDidMount, theme: isDarkTheme ? 'vs-dark' : 'vs-light', loading: loading }, editorProps)) }));
285
- const hiddenFileInput = _jsx("input", Object.assign({}, getInputProps(), { hidden: true }));
286
- return (_jsx("div", { className: css(styles.codeEditor, isReadOnly && styles.modifiers.readOnly, isFullHeight && styles.modifiers.fullHeight, className), ref: this.ref, children: (isUploadEnabled || providedEmptyState) && !value ? (_jsxs("div", Object.assign({}, getRootProps({
287
- onClick: (event) => event.stopPropagation() // Prevents clicking TextArea from opening file dialog
288
- }), { className: css(styles.codeEditorContainer, isLoading && fileUploadStyles.modifiers.loading), children: [editorHeader, _jsx("div", { className: css(styles.codeEditorMain, isDragActive && styles.modifiers.dragHover), children: (showEmptyState || providedEmptyState) && !value ? (_jsxs("div", { className: css(styles.codeEditorUpload), children: [hiddenFileInput, emptyState] })) : (_jsxs(_Fragment, { children: [hiddenFileInput, editor] })) })] }))) : (_jsxs(_Fragment, { children: [editorHeader, showEditor && (_jsxs("div", { className: css(styles.codeEditorMain), children: [hiddenFileInput, editor] }))] })) }));
289
- } }));
290
- }
291
- }
292
- CodeEditor.displayName = 'CodeEditor';
293
- CodeEditor.defaultProps = {
294
- className: '',
295
- code: '',
296
- onEditorDidMount: () => { },
297
- language: Language.plaintext,
298
- isDarkTheme: false,
299
- width: '',
300
- isLineNumbersVisible: true,
301
- isReadOnly: false,
302
- isLanguageLabelVisible: false,
303
- loading: '',
304
- emptyState: '',
305
- emptyStateTitle: 'Start editing',
306
- emptyStateBody: 'Drag and drop a file or upload one.',
307
- emptyStateButton: 'Browse',
308
- emptyStateLink: 'Start from scratch',
309
- downloadFileName: Date.now().toString(),
310
- isUploadEnabled: false,
311
- isDownloadEnabled: false,
312
- isCopyEnabled: false,
313
- isHeaderPlain: false,
314
- copyButtonAriaLabel: 'Copy code to clipboard',
315
- uploadButtonAriaLabel: 'Upload code',
316
- downloadButtonAriaLabel: 'Download code',
317
- copyButtonToolTipText: 'Copy to clipboard',
318
- uploadButtonToolTipText: 'Upload',
319
- downloadButtonToolTipText: 'Download',
320
- copyButtonSuccessTooltipText: 'Content added to clipboard',
321
- toolTipCopyExitDelay: 1600,
322
- toolTipDelay: 300,
323
- toolTipMaxWidth: '100px',
324
- toolTipPosition: 'top',
325
- customControls: null,
326
- isMinimapVisible: false,
327
- headerMainContent: '',
328
- shortcutsPopoverButtonText: 'View Shortcuts',
329
- shortcutsPopoverProps: {
330
- bodyContent: '',
331
- 'aria-label': 'Keyboard Shortcuts'
332
- },
333
- showEditor: true,
334
- options: {},
335
- overrideServices: {},
336
- onCodeChange: () => { }
220
+ };
221
+ const onDropRejected = (rejectedFiles) => {
222
+ if (rejectedFiles.length > 0) {
223
+ // eslint-disable-next-line no-console
224
+ console.error('There was an error accepting that dropped file'); // TODO
225
+ }
226
+ };
227
+ const copyCode = () => {
228
+ navigator.clipboard.writeText(value);
229
+ setCopied(true);
230
+ };
231
+ const editorOptions = Object.assign({ scrollBeyondLastLine: height !== 'sizeToFit', readOnly: isReadOnly, cursorStyle: 'line', lineNumbers: isLineNumbersVisible ? 'on' : 'off', tabIndex: -1, minimap: {
232
+ enabled: isMinimapVisible
233
+ } }, options);
234
+ const tooltipProps = {
235
+ position: toolTipPosition,
236
+ exitDelay: toolTipDelay,
237
+ entryDelay: toolTipDelay,
238
+ maxWidth: toolTipMaxWidth,
239
+ trigger: 'mouseenter focus'
240
+ };
241
+ const hasEditorHeaderContent = ((isCopyEnabled || isDownloadEnabled) && (!showEmptyState || !!value)) ||
242
+ isUploadEnabled ||
243
+ customControls ||
244
+ headerMainContent ||
245
+ !!shortcutsPopoverProps.bodyContent;
246
+ return (_jsx(Dropzone, { multiple: false, onDropAccepted: onDropAccepted, onDropRejected: onDropRejected, children: ({ getRootProps, getInputProps, isDragActive, open }) => {
247
+ const hiddenFileInput = _jsx("input", Object.assign({}, getInputProps(), { hidden: true }));
248
+ const editorEmptyState = emptyState ||
249
+ (isUploadEnabled ? (_jsxs(EmptyState, { variant: EmptyStateVariant.sm, titleText: emptyStateTitle, icon: CodeIcon, headingLevel: "h4", children: [_jsx(EmptyStateBody, { children: emptyStateBody }), !isReadOnly && (_jsxs(EmptyStateFooter, { children: [_jsx(EmptyStateActions, { children: _jsx(Button, { variant: "primary", onClick: open, children: emptyStateButton }) }), _jsx(EmptyStateActions, { children: _jsx(Button, { variant: "link", onClick: () => setShowEmptyState(false), children: emptyStateLink }) })] }))] })) : (_jsx(EmptyState, { variant: EmptyStateVariant.sm, titleText: emptyStateTitle, icon: CodeIcon, headingLevel: "h4", children: !isReadOnly && (_jsx(EmptyStateFooter, { children: _jsx(EmptyStateActions, { children: _jsx(Button, { variant: "primary", onClick: () => setShowEmptyState(false), children: emptyStateLink }) }) })) })));
250
+ const editorHeaderContent = (_jsxs(_Fragment, { children: [_jsx("div", { className: css(styles.codeEditorControls), children: _jsxs(CodeEditorContext.Provider, { value: { code: value }, children: [isCopyEnabled && (!showEmptyState || !!value) && (_jsx(CodeEditorControl, { icon: _jsx(CopyIcon, {}), "aria-label": copyButtonAriaLabel, tooltipProps: Object.assign(Object.assign({}, tooltipProps), { 'aria-live': 'polite', content: _jsx("div", { children: copied ? copyButtonSuccessTooltipText : copyButtonToolTipText }), exitDelay: copied ? toolTipCopyExitDelay : toolTipDelay, onTooltipHidden: () => setCopied(false) }), onClick: copyCode })), isUploadEnabled && (_jsx(CodeEditorControl, { icon: _jsx(UploadIcon, {}), "aria-label": uploadButtonAriaLabel, tooltipProps: Object.assign({ content: _jsx("div", { children: uploadButtonToolTipText }) }, tooltipProps), onClick: open })), isDownloadEnabled && (!showEmptyState || !!value) && (_jsx(CodeEditorControl, { icon: _jsx(DownloadIcon, {}), "aria-label": downloadButtonAriaLabel, tooltipProps: Object.assign({ content: _jsx("div", { children: downloadButtonToolTipText }) }, tooltipProps), onClick: () => {
251
+ onDownload(value, `${downloadFileName}.${getExtensionFromLanguage(language)}`);
252
+ } })), customControls && customControls] }) }), headerMainContent && _jsx("div", { className: css(styles.codeEditorHeaderMain), children: headerMainContent }), !!shortcutsPopoverProps.bodyContent && (_jsx("div", { className: `${styles.codeEditor}__keyboard-shortcuts`, children: _jsx(Popover, Object.assign({}, shortcutsPopoverProps, { children: _jsx(Button, { variant: ButtonVariant.link, icon: _jsx(HelpIcon, {}), children: shortcutsPopoverButtonText }) })) }))] }));
253
+ const editorHeader = (_jsxs("div", { className: css(styles.codeEditorHeader, isHeaderPlain && styles.modifiers.plain), children: [hasEditorHeaderContent && _jsx("div", { className: css(styles.codeEditorHeaderContent), children: editorHeaderContent }), isLanguageLabelVisible && (_jsxs("div", { className: css(styles.codeEditorTab), children: [_jsx("span", { className: css(styles.codeEditorTabIcon), children: _jsx(CodeIcon, {}) }), _jsx("span", { className: css(styles.codeEditorTabText), children: language.toUpperCase() })] }))] }));
254
+ const editor = (_jsx("div", { className: css(styles.codeEditorCode), ref: wrapperRef, tabIndex: 0, dir: "ltr", children: _jsx(Editor, Object.assign({ height: height === '100%' ? undefined : height, width: width, language: language, value: value, options: editorOptions, overrideServices: overrideServices, onChange: onModelChange, onMount: editorDidMount, loading: loading, theme: isDarkTheme ? 'vs-dark' : 'vs-light' }, editorProps)) }));
255
+ return (_jsx("div", { className: css(styles.codeEditor, isReadOnly && styles.modifiers.readOnly, (height === '100%' ? true : isFullHeight) && styles.modifiers.fullHeight, className), ref: ref, children: (isUploadEnabled || emptyState) && !value ? (_jsxs("div", Object.assign({}, getRootProps({
256
+ onClick: (event) => event.stopPropagation() // Prevents clicking TextArea from opening file dialog
257
+ }), { className: css(styles.codeEditorContainer, isLoading && fileUploadStyles.modifiers.loading), children: [editorHeader, _jsx("div", { className: css(styles.codeEditorMain, isDragActive && styles.modifiers.dragHover), children: (showEmptyState || emptyState) && !value ? (_jsxs("div", { className: css(styles.codeEditorUpload), children: [hiddenFileInput, editorEmptyState] })) : (_jsxs(_Fragment, { children: [hiddenFileInput, editor] })) })] }))) : (_jsxs(_Fragment, { children: [editorHeader, showEditor && (_jsxs("div", { className: css(styles.codeEditorMain), children: [hiddenFileInput, editor] }))] })) }));
258
+ } }));
337
259
  };
338
- export { CodeEditor };
260
+ CodeEditor.displayName = 'CodeEditor';
339
261
  //# sourceMappingURL=CodeEditor.js.map