@patternfly/react-code-editor 6.2.1-prerelease.1 → 6.2.1-prerelease.10

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.
@@ -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,OAAO,EAAE,eAAe,EAAE,MAAM,oDAAoD,CAAC;AAErF,OAAe,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAM5C,OAAiB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAIzD,MAAM,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,yBAAyB,KAAK,IAAI,CAAC;AAC7F,MAAM,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,qBAAqB,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;AAE5F,MAAM,WA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K,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"}
@@ -98,246 +98,169 @@ var Language;
98
98
  Language["xml"] = "xml";
99
99
  Language["yaml"] = "yaml";
100
100
  })(Language || (exports.Language = Language = {}));
101
- class CodeEditor extends react_1.Component {
102
- static getExtensionFromLanguage(language) {
103
- switch (language) {
104
- case Language.shell:
105
- return 'sh';
106
- case Language.ruby:
107
- return 'rb';
108
- case Language.perl:
109
- return 'pl';
110
- case Language.python:
111
- return 'py';
112
- case Language.mysql:
113
- return 'sql';
114
- case Language.javascript:
115
- return 'js';
116
- case Language.typescript:
117
- return 'ts';
118
- case Language.markdown:
119
- return 'md';
120
- case Language.plaintext:
121
- return 'txt';
122
- default:
123
- return language.toString();
124
- }
101
+ const getExtensionFromLanguage = (language) => {
102
+ switch (language) {
103
+ case Language.shell:
104
+ return 'sh';
105
+ case Language.ruby:
106
+ return 'rb';
107
+ case Language.perl:
108
+ return 'pl';
109
+ case Language.python:
110
+ return 'py';
111
+ case Language.mysql:
112
+ return 'sql';
113
+ case Language.javascript:
114
+ return 'js';
115
+ case Language.typescript:
116
+ return 'ts';
117
+ case Language.markdown:
118
+ return 'md';
119
+ case Language.plaintext:
120
+ return 'txt';
121
+ default:
122
+ return language.toString();
125
123
  }
126
- constructor(props) {
127
- super(props);
128
- this.editor = null;
129
- this.wrapperRef = (0, react_1.createRef)();
130
- this.ref = (0, react_1.createRef)();
131
- this.timer = null;
132
- this.observer = () => { };
133
- this.onChange = (value, event) => {
134
- if (this.props.height === 'sizeToFit') {
135
- this.setHeightToFitContent();
136
- }
137
- if (this.props.onChange) {
138
- this.props.onChange(value, event);
139
- }
140
- this.setState({ value });
141
- this.props.onCodeChange(value);
142
- };
143
- this.handleResize = () => {
144
- if (this.editor) {
145
- this.editor.layout({ width: 0, height: 0 }); // ensures the editor won't take up more space than it needs
146
- this.editor.layout();
147
- }
148
- };
149
- this.handleGlobalKeys = (event) => {
150
- var _a;
151
- if (this.wrapperRef.current === document.activeElement && (event.key === 'ArrowDown' || event.key === ' ')) {
152
- (_a = this.editor) === null || _a === void 0 ? void 0 : _a.focus();
153
- event.preventDefault();
154
- }
155
- };
156
- this.editorDidMount = (editor, monaco) => {
157
- // eslint-disable-next-line no-bitwise
158
- editor.addCommand(monaco.KeyMod.Shift | monaco.KeyCode.Tab, () => this.wrapperRef.current.focus());
159
- Array.from(document.getElementsByClassName('monaco-editor')).forEach((editorElement) => editorElement.removeAttribute('role'));
160
- this.props.onEditorDidMount(editor, monaco);
161
- this.editor = editor;
162
- if (this.props.height === 'sizeToFit') {
163
- this.setHeightToFitContent();
164
- }
165
- };
166
- this.handleFileChange = (value, filename) => {
167
- this.setState({
168
- value,
169
- filename
170
- });
171
- this.props.onCodeChange(value);
172
- };
173
- this.handleFileReadStarted = () => this.setState({ isLoading: true });
174
- this.handleFileReadFinished = () => this.setState({ isLoading: false });
175
- this.onDropAccepted = (acceptedFiles) => {
176
- if (acceptedFiles.length > 0) {
177
- const fileHandle = acceptedFiles[0];
178
- this.handleFileChange('', fileHandle.name); // Show the filename while reading
179
- this.handleFileReadStarted();
180
- this.readFile(fileHandle)
181
- .then((data) => {
182
- this.handleFileReadFinished();
183
- this.toggleEmptyState();
184
- this.handleFileChange(data, fileHandle.name);
185
- })
186
- .catch((error) => {
187
- // eslint-disable-next-line no-console
188
- console.error('error', error);
189
- this.handleFileReadFinished();
190
- this.handleFileChange('', ''); // Clear the filename field on a failure
191
- });
192
- }
124
+ };
125
+ /**
126
+ * Downloads a file to a users device given its string content and a full file name.
127
+ */
128
+ const defaultOnDownload = (value, fileName) => {
129
+ const link = document.createElement('a');
130
+ link.href = URL.createObjectURL(new Blob([value], { type: 'text' }));
131
+ link.download = fileName;
132
+ link.click();
133
+ };
134
+ 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 = '' }) => {
135
+ const [value, setValue] = (0, react_1.useState)(code);
136
+ const [isLoading, setIsLoading] = (0, react_1.useState)(false);
137
+ const [showEmptyState, setShowEmptyState] = (0, react_1.useState)(true);
138
+ const [copied, setCopied] = (0, react_1.useState)(false);
139
+ const editorRef = (0, react_1.useRef)(null);
140
+ const wrapperRef = (0, react_1.useRef)(null);
141
+ const ref = (0, react_1.useRef)(null);
142
+ const observer = (0, react_1.useRef)(() => { });
143
+ const setHeightToFitContent = () => {
144
+ var _a, _b, _c;
145
+ const contentHeight = (_a = editorRef.current) === null || _a === void 0 ? void 0 : _a.getContentHeight();
146
+ const layoutInfo = (_b = editorRef.current) === null || _b === void 0 ? void 0 : _b.getLayoutInfo();
147
+ (_c = editorRef.current) === null || _c === void 0 ? void 0 : _c.layout({ width: layoutInfo.width, height: contentHeight });
148
+ };
149
+ const onModelChange = (value, event) => {
150
+ if (height === 'sizeToFit') {
151
+ setHeightToFitContent();
152
+ }
153
+ if (onChange) {
154
+ onChange(value, event);
155
+ }
156
+ setValue(value);
157
+ onCodeChange(value);
158
+ };
159
+ const handleResize = () => {
160
+ if (editorRef.current) {
161
+ editorRef.current.layout({ width: 0, height: 0 }); // ensures the editor won't take up more space than it needs
162
+ editorRef.current.layout();
163
+ }
164
+ };
165
+ const handleGlobalKeys = (event) => {
166
+ var _a;
167
+ if (wrapperRef.current === document.activeElement && (event.key === 'ArrowDown' || event.key === ' ')) {
168
+ (_a = editorRef.current) === null || _a === void 0 ? void 0 : _a.focus();
169
+ event.preventDefault();
170
+ }
171
+ };
172
+ // if the code changes due to the prop changing
173
+ // set the value to the code prop
174
+ (0, react_1.useEffect)(() => setValue(code), [code]);
175
+ (0, react_1.useEffect)(() => {
176
+ document.addEventListener('keydown', handleGlobalKeys);
177
+ observer.current = (0, resizeObserver_1.getResizeObserver)(ref.current, handleResize, true);
178
+ handleResize();
179
+ return () => {
180
+ document.removeEventListener('keydown', handleGlobalKeys);
181
+ observer.current();
193
182
  };
194
- this.onDropRejected = (rejectedFiles) => {
195
- if (rejectedFiles.length > 0) {
183
+ }, []);
184
+ const editorDidMount = (editor, monaco) => {
185
+ // eslint-disable-next-line no-bitwise
186
+ editor.addCommand(monaco.KeyMod.Shift | monaco.KeyCode.Tab, () => wrapperRef.current.focus());
187
+ Array.from(document.getElementsByClassName('monaco-editor')).forEach((editorElement) => editorElement.removeAttribute('role'));
188
+ onEditorDidMount(editor, monaco);
189
+ editorRef.current = editor;
190
+ if (height === 'sizeToFit') {
191
+ setHeightToFitContent();
192
+ }
193
+ };
194
+ const handleFileChange = (value) => {
195
+ setValue(value);
196
+ onCodeChange(value);
197
+ };
198
+ const handleFileReadStarted = () => setIsLoading(true);
199
+ const handleFileReadFinished = () => setIsLoading(false);
200
+ const readFile = (fileHandle) => new Promise((resolve, reject) => {
201
+ const reader = new FileReader();
202
+ reader.onload = () => resolve(reader.result);
203
+ reader.onerror = () => reject(reader.error);
204
+ reader.readAsText(fileHandle);
205
+ });
206
+ const onDropAccepted = (acceptedFiles) => {
207
+ if (acceptedFiles.length > 0) {
208
+ const fileHandle = acceptedFiles[0];
209
+ handleFileChange(''); // Show the filename while reading
210
+ handleFileReadStarted();
211
+ readFile(fileHandle)
212
+ .then((data) => {
213
+ handleFileReadFinished();
214
+ setShowEmptyState(false);
215
+ handleFileChange(data);
216
+ })
217
+ .catch((error) => {
196
218
  // eslint-disable-next-line no-console
197
- console.error('There was an error accepting that dropped file'); // TODO
198
- }
199
- };
200
- this.copyCode = () => {
201
- navigator.clipboard.writeText(this.state.value);
202
- this.setState({ copied: true });
203
- };
204
- this.download = () => {
205
- const { value } = this.state;
206
- const element = document.createElement('a');
207
- const file = new Blob([value], { type: 'text' });
208
- element.href = URL.createObjectURL(file);
209
- element.download = `${this.props.downloadFileName}.${CodeEditor.getExtensionFromLanguage(this.props.language)}`;
210
- document.body.appendChild(element); // Required for this to work in FireFox
211
- element.click();
212
- };
213
- this.toggleEmptyState = () => {
214
- this.setState({ showEmptyState: false });
215
- };
216
- this.state = {
217
- height: this.props.height,
218
- prevPropsCode: this.props.code,
219
- value: this.props.code,
220
- filename: '',
221
- isLoading: false,
222
- showEmptyState: true,
223
- copied: false
224
- };
225
- }
226
- setHeightToFitContent() {
227
- const contentHeight = this.editor.getContentHeight();
228
- const layoutInfo = this.editor.getLayoutInfo();
229
- this.editor.layout({ width: layoutInfo.width, height: contentHeight });
230
- }
231
- // this function is only called when the props change
232
- // the only conflict is between props.code and state.value
233
- static getDerivedStateFromProps(nextProps, prevState) {
234
- // if the code changes due to the props.code changing
235
- // set the value to props.code
236
- if (nextProps.code !== prevState.prevPropsCode) {
237
- return {
238
- value: nextProps.code,
239
- prevPropsCode: nextProps.code
240
- };
219
+ console.error('error', error);
220
+ handleFileReadFinished();
221
+ handleFileChange('');
222
+ });
241
223
  }
242
- // else, don't need to change the state.value
243
- // because the onChange function will do all the work
244
- return null;
245
- }
246
- componentDidMount() {
247
- document.addEventListener('keydown', this.handleGlobalKeys);
248
- this.observer = (0, resizeObserver_1.getResizeObserver)(this.ref.current, this.handleResize, true);
249
- this.handleResize();
250
- }
251
- componentWillUnmount() {
252
- document.removeEventListener('keydown', this.handleGlobalKeys);
253
- this.observer();
254
- }
255
- readFile(fileHandle) {
256
- return new Promise((resolve, reject) => {
257
- const reader = new FileReader();
258
- reader.onload = () => resolve(reader.result);
259
- reader.onerror = () => reject(reader.error);
260
- reader.readAsText(fileHandle);
261
- });
262
- }
263
- render() {
264
- const { height, value, isLoading, showEmptyState, copied } = this.state;
265
- 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;
266
- const shortcutsPopoverProps = Object.assign(Object.assign({}, CodeEditor.defaultProps.shortcutsPopoverProps), shortcutsPopoverPropsProp);
267
- const options = Object.assign({ scrollBeyondLastLine: height !== 'sizeToFit', readOnly: isReadOnly, cursorStyle: 'line', lineNumbers: isLineNumbersVisible ? 'on' : 'off', tabIndex: -1, minimap: {
268
- enabled: isMinimapVisible
269
- } }, optionsProp);
270
- const isFullHeight = this.props.height === '100%' ? true : this.props.isFullHeight;
271
- return ((0, jsx_runtime_1.jsx)(react_dropzone_1.default, { multiple: false, onDropAccepted: this.onDropAccepted, onDropRejected: this.onDropRejected, children: ({ getRootProps, getInputProps, isDragActive, open }) => {
272
- const emptyState = providedEmptyState ||
273
- (isUploadEnabled ? ((0, jsx_runtime_1.jsxs)(EmptyState_1.EmptyState, { variant: EmptyState_1.EmptyStateVariant.sm, titleText: emptyStateTitle, icon: code_icon_1.default, headingLevel: "h4", children: [(0, jsx_runtime_1.jsx)(EmptyState_1.EmptyStateBody, { children: emptyStateBody }), !isReadOnly && ((0, jsx_runtime_1.jsxs)(EmptyState_1.EmptyStateFooter, { children: [(0, jsx_runtime_1.jsx)(EmptyState_1.EmptyStateActions, { children: (0, jsx_runtime_1.jsx)(Button_1.Button, { variant: "primary", onClick: open, children: emptyStateButton }) }), (0, jsx_runtime_1.jsx)(EmptyState_1.EmptyStateActions, { children: (0, jsx_runtime_1.jsx)(Button_1.Button, { variant: "link", onClick: this.toggleEmptyState, children: emptyStateLink }) })] }))] })) : ((0, jsx_runtime_1.jsx)(EmptyState_1.EmptyState, { variant: EmptyState_1.EmptyStateVariant.sm, titleText: emptyStateTitle, icon: code_icon_1.default, headingLevel: "h4", children: !isReadOnly && ((0, jsx_runtime_1.jsx)(EmptyState_1.EmptyStateFooter, { children: (0, jsx_runtime_1.jsx)(EmptyState_1.EmptyStateActions, { children: (0, jsx_runtime_1.jsx)(Button_1.Button, { variant: "primary", onClick: this.toggleEmptyState, children: emptyStateLink }) }) })) })));
274
- const tooltipProps = {
275
- position: toolTipPosition,
276
- exitDelay: toolTipDelay,
277
- entryDelay: toolTipDelay,
278
- maxWidth: toolTipMaxWidth,
279
- trigger: 'mouseenter focus'
280
- };
281
- const hasEditorHeaderContent = ((isCopyEnabled || isDownloadEnabled) && (!showEmptyState || !!value)) ||
282
- isUploadEnabled ||
283
- customControls ||
284
- headerMainContent ||
285
- !!shortcutsPopoverProps.bodyContent;
286
- const editorHeaderContent = ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: (0, react_styles_1.css)(code_editor_1.default.codeEditorControls), children: (0, jsx_runtime_1.jsxs)(CodeEditorUtils_1.CodeEditorContext.Provider, { value: { code: value }, children: [isCopyEnabled && (!showEmptyState || !!value) && ((0, jsx_runtime_1.jsx)(CodeEditorControl_1.CodeEditorControl, { icon: (0, jsx_runtime_1.jsx)(copy_icon_1.default, {}), "aria-label": copyButtonAriaLabel, tooltipProps: Object.assign(Object.assign({}, tooltipProps), { 'aria-live': 'polite', content: (0, jsx_runtime_1.jsx)("div", { children: copied ? copyButtonSuccessTooltipText : copyButtonToolTipText }), exitDelay: copied ? toolTipCopyExitDelay : toolTipDelay, onTooltipHidden: () => this.setState({ copied: false }) }), onClick: this.copyCode })), isUploadEnabled && ((0, jsx_runtime_1.jsx)(CodeEditorControl_1.CodeEditorControl, { icon: (0, jsx_runtime_1.jsx)(upload_icon_1.default, {}), "aria-label": uploadButtonAriaLabel, tooltipProps: Object.assign({ content: (0, jsx_runtime_1.jsx)("div", { children: uploadButtonToolTipText }) }, tooltipProps), onClick: open })), isDownloadEnabled && (!showEmptyState || !!value) && ((0, jsx_runtime_1.jsx)(CodeEditorControl_1.CodeEditorControl, { icon: (0, jsx_runtime_1.jsx)(download_icon_1.default, {}), "aria-label": downloadButtonAriaLabel, tooltipProps: Object.assign({ content: (0, jsx_runtime_1.jsx)("div", { children: downloadButtonToolTipText }) }, tooltipProps), onClick: this.download })), customControls && customControls] }) }), headerMainContent && (0, jsx_runtime_1.jsx)("div", { className: (0, react_styles_1.css)(code_editor_1.default.codeEditorHeaderMain), children: headerMainContent }), !!shortcutsPopoverProps.bodyContent && ((0, jsx_runtime_1.jsx)("div", { className: `${code_editor_1.default.codeEditor}__keyboard-shortcuts`, children: (0, jsx_runtime_1.jsx)(Popover_1.Popover, Object.assign({}, shortcutsPopoverProps, { children: (0, jsx_runtime_1.jsx)(Button_1.Button, { variant: Button_1.ButtonVariant.link, icon: (0, jsx_runtime_1.jsx)(help_icon_1.default, {}), children: shortcutsPopoverButtonText }) })) }))] }));
287
- const editorHeader = ((0, jsx_runtime_1.jsxs)("div", { className: (0, react_styles_1.css)(code_editor_1.default.codeEditorHeader, isHeaderPlain && code_editor_1.default.modifiers.plain), children: [hasEditorHeaderContent && ((0, jsx_runtime_1.jsx)("div", { className: (0, react_styles_1.css)(code_editor_1.default.codeEditorHeaderContent), children: editorHeaderContent })), isLanguageLabelVisible && ((0, jsx_runtime_1.jsxs)("div", { className: (0, react_styles_1.css)(code_editor_1.default.codeEditorTab), children: [(0, jsx_runtime_1.jsx)("span", { className: (0, react_styles_1.css)(code_editor_1.default.codeEditorTabIcon), children: (0, jsx_runtime_1.jsx)(code_icon_1.default, {}) }), (0, jsx_runtime_1.jsx)("span", { className: (0, react_styles_1.css)(code_editor_1.default.codeEditorTabText), children: language.toUpperCase() })] }))] }));
288
- const editor = ((0, jsx_runtime_1.jsx)("div", { className: (0, react_styles_1.css)(code_editor_1.default.codeEditorCode), ref: this.wrapperRef, tabIndex: 0, dir: "ltr", children: (0, jsx_runtime_1.jsx)(react_2.default, 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)) }));
289
- const hiddenFileInput = (0, jsx_runtime_1.jsx)("input", Object.assign({}, getInputProps(), { hidden: true }));
290
- return ((0, jsx_runtime_1.jsx)("div", { className: (0, react_styles_1.css)(code_editor_1.default.codeEditor, isReadOnly && code_editor_1.default.modifiers.readOnly, isFullHeight && code_editor_1.default.modifiers.fullHeight, className), ref: this.ref, children: (isUploadEnabled || providedEmptyState) && !value ? ((0, jsx_runtime_1.jsxs)("div", Object.assign({}, getRootProps({
291
- onClick: (event) => event.stopPropagation() // Prevents clicking TextArea from opening file dialog
292
- }), { className: (0, react_styles_1.css)(code_editor_1.default.codeEditorContainer, isLoading && file_upload_1.default.modifiers.loading), children: [editorHeader, (0, jsx_runtime_1.jsx)("div", { className: (0, react_styles_1.css)(code_editor_1.default.codeEditorMain, isDragActive && code_editor_1.default.modifiers.dragHover), children: (showEmptyState || providedEmptyState) && !value ? ((0, jsx_runtime_1.jsxs)("div", { className: (0, react_styles_1.css)(code_editor_1.default.codeEditorUpload), children: [hiddenFileInput, emptyState] })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [hiddenFileInput, editor] })) })] }))) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [editorHeader, showEditor && ((0, jsx_runtime_1.jsxs)("div", { className: (0, react_styles_1.css)(code_editor_1.default.codeEditorMain), children: [hiddenFileInput, editor] }))] })) }));
293
- } }));
294
- }
295
- }
296
- exports.CodeEditor = CodeEditor;
297
- CodeEditor.displayName = 'CodeEditor';
298
- CodeEditor.defaultProps = {
299
- className: '',
300
- code: '',
301
- onEditorDidMount: () => { },
302
- language: Language.plaintext,
303
- isDarkTheme: false,
304
- width: '',
305
- isLineNumbersVisible: true,
306
- isReadOnly: false,
307
- isLanguageLabelVisible: false,
308
- loading: '',
309
- emptyState: '',
310
- emptyStateTitle: 'Start editing',
311
- emptyStateBody: 'Drag and drop a file or upload one.',
312
- emptyStateButton: 'Browse',
313
- emptyStateLink: 'Start from scratch',
314
- downloadFileName: Date.now().toString(),
315
- isUploadEnabled: false,
316
- isDownloadEnabled: false,
317
- isCopyEnabled: false,
318
- isHeaderPlain: false,
319
- copyButtonAriaLabel: 'Copy code to clipboard',
320
- uploadButtonAriaLabel: 'Upload code',
321
- downloadButtonAriaLabel: 'Download code',
322
- copyButtonToolTipText: 'Copy to clipboard',
323
- uploadButtonToolTipText: 'Upload',
324
- downloadButtonToolTipText: 'Download',
325
- copyButtonSuccessTooltipText: 'Content added to clipboard',
326
- toolTipCopyExitDelay: 1600,
327
- toolTipDelay: 300,
328
- toolTipMaxWidth: '100px',
329
- toolTipPosition: 'top',
330
- customControls: null,
331
- isMinimapVisible: false,
332
- headerMainContent: '',
333
- shortcutsPopoverButtonText: 'View Shortcuts',
334
- shortcutsPopoverProps: {
335
- bodyContent: '',
336
- 'aria-label': 'Keyboard Shortcuts'
337
- },
338
- showEditor: true,
339
- options: {},
340
- overrideServices: {},
341
- onCodeChange: () => { }
224
+ };
225
+ const onDropRejected = (rejectedFiles) => {
226
+ if (rejectedFiles.length > 0) {
227
+ // eslint-disable-next-line no-console
228
+ console.error('There was an error accepting that dropped file'); // TODO
229
+ }
230
+ };
231
+ const copyCode = () => {
232
+ navigator.clipboard.writeText(value);
233
+ setCopied(true);
234
+ };
235
+ const editorOptions = Object.assign({ scrollBeyondLastLine: height !== 'sizeToFit', readOnly: isReadOnly, cursorStyle: 'line', lineNumbers: isLineNumbersVisible ? 'on' : 'off', tabIndex: -1, minimap: {
236
+ enabled: isMinimapVisible
237
+ } }, options);
238
+ const tooltipProps = {
239
+ position: toolTipPosition,
240
+ exitDelay: toolTipDelay,
241
+ entryDelay: toolTipDelay,
242
+ maxWidth: toolTipMaxWidth,
243
+ trigger: 'mouseenter focus'
244
+ };
245
+ const hasEditorHeaderContent = ((isCopyEnabled || isDownloadEnabled) && (!showEmptyState || !!value)) ||
246
+ isUploadEnabled ||
247
+ customControls ||
248
+ headerMainContent ||
249
+ !!shortcutsPopoverProps.bodyContent;
250
+ return ((0, jsx_runtime_1.jsx)(react_dropzone_1.default, { multiple: false, onDropAccepted: onDropAccepted, onDropRejected: onDropRejected, children: ({ getRootProps, getInputProps, isDragActive, open }) => {
251
+ const hiddenFileInput = (0, jsx_runtime_1.jsx)("input", Object.assign({}, getInputProps(), { hidden: true }));
252
+ const editorEmptyState = emptyState ||
253
+ (isUploadEnabled ? ((0, jsx_runtime_1.jsxs)(EmptyState_1.EmptyState, { variant: EmptyState_1.EmptyStateVariant.sm, titleText: emptyStateTitle, icon: code_icon_1.default, headingLevel: "h4", children: [(0, jsx_runtime_1.jsx)(EmptyState_1.EmptyStateBody, { children: emptyStateBody }), !isReadOnly && ((0, jsx_runtime_1.jsxs)(EmptyState_1.EmptyStateFooter, { children: [(0, jsx_runtime_1.jsx)(EmptyState_1.EmptyStateActions, { children: (0, jsx_runtime_1.jsx)(Button_1.Button, { variant: "primary", onClick: open, children: emptyStateButton }) }), (0, jsx_runtime_1.jsx)(EmptyState_1.EmptyStateActions, { children: (0, jsx_runtime_1.jsx)(Button_1.Button, { variant: "link", onClick: () => setShowEmptyState(false), children: emptyStateLink }) })] }))] })) : ((0, jsx_runtime_1.jsx)(EmptyState_1.EmptyState, { variant: EmptyState_1.EmptyStateVariant.sm, titleText: emptyStateTitle, icon: code_icon_1.default, headingLevel: "h4", children: !isReadOnly && ((0, jsx_runtime_1.jsx)(EmptyState_1.EmptyStateFooter, { children: (0, jsx_runtime_1.jsx)(EmptyState_1.EmptyStateActions, { children: (0, jsx_runtime_1.jsx)(Button_1.Button, { variant: "primary", onClick: () => setShowEmptyState(false), children: emptyStateLink }) }) })) })));
254
+ const editorHeaderContent = ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: (0, react_styles_1.css)(code_editor_1.default.codeEditorControls), children: (0, jsx_runtime_1.jsxs)(CodeEditorUtils_1.CodeEditorContext.Provider, { value: { code: value }, children: [isCopyEnabled && (!showEmptyState || !!value) && ((0, jsx_runtime_1.jsx)(CodeEditorControl_1.CodeEditorControl, { icon: (0, jsx_runtime_1.jsx)(copy_icon_1.default, {}), "aria-label": copyButtonAriaLabel, tooltipProps: Object.assign(Object.assign({}, tooltipProps), { 'aria-live': 'polite', content: (0, jsx_runtime_1.jsx)("div", { children: copied ? copyButtonSuccessTooltipText : copyButtonToolTipText }), exitDelay: copied ? toolTipCopyExitDelay : toolTipDelay, onTooltipHidden: () => setCopied(false) }), onClick: copyCode })), isUploadEnabled && ((0, jsx_runtime_1.jsx)(CodeEditorControl_1.CodeEditorControl, { icon: (0, jsx_runtime_1.jsx)(upload_icon_1.default, {}), "aria-label": uploadButtonAriaLabel, tooltipProps: Object.assign({ content: (0, jsx_runtime_1.jsx)("div", { children: uploadButtonToolTipText }) }, tooltipProps), onClick: open })), isDownloadEnabled && (!showEmptyState || !!value) && ((0, jsx_runtime_1.jsx)(CodeEditorControl_1.CodeEditorControl, { icon: (0, jsx_runtime_1.jsx)(download_icon_1.default, {}), "aria-label": downloadButtonAriaLabel, tooltipProps: Object.assign({ content: (0, jsx_runtime_1.jsx)("div", { children: downloadButtonToolTipText }) }, tooltipProps), onClick: () => {
255
+ onDownload(value, `${downloadFileName}.${getExtensionFromLanguage(language)}`);
256
+ } })), customControls && customControls] }) }), headerMainContent && (0, jsx_runtime_1.jsx)("div", { className: (0, react_styles_1.css)(code_editor_1.default.codeEditorHeaderMain), children: headerMainContent }), !!shortcutsPopoverProps.bodyContent && ((0, jsx_runtime_1.jsx)("div", { className: `${code_editor_1.default.codeEditor}__keyboard-shortcuts`, children: (0, jsx_runtime_1.jsx)(Popover_1.Popover, Object.assign({}, shortcutsPopoverProps, { children: (0, jsx_runtime_1.jsx)(Button_1.Button, { variant: Button_1.ButtonVariant.link, icon: (0, jsx_runtime_1.jsx)(help_icon_1.default, {}), children: shortcutsPopoverButtonText }) })) }))] }));
257
+ const editorHeader = ((0, jsx_runtime_1.jsxs)("div", { className: (0, react_styles_1.css)(code_editor_1.default.codeEditorHeader, isHeaderPlain && code_editor_1.default.modifiers.plain), children: [hasEditorHeaderContent && (0, jsx_runtime_1.jsx)("div", { className: (0, react_styles_1.css)(code_editor_1.default.codeEditorHeaderContent), children: editorHeaderContent }), isLanguageLabelVisible && ((0, jsx_runtime_1.jsxs)("div", { className: (0, react_styles_1.css)(code_editor_1.default.codeEditorTab), children: [(0, jsx_runtime_1.jsx)("span", { className: (0, react_styles_1.css)(code_editor_1.default.codeEditorTabIcon), children: (0, jsx_runtime_1.jsx)(code_icon_1.default, {}) }), (0, jsx_runtime_1.jsx)("span", { className: (0, react_styles_1.css)(code_editor_1.default.codeEditorTabText), children: language.toUpperCase() })] }))] }));
258
+ const editor = ((0, jsx_runtime_1.jsx)("div", { className: (0, react_styles_1.css)(code_editor_1.default.codeEditorCode), ref: wrapperRef, tabIndex: 0, dir: "ltr", children: (0, jsx_runtime_1.jsx)(react_2.default, 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)) }));
259
+ return ((0, jsx_runtime_1.jsx)("div", { className: (0, react_styles_1.css)(code_editor_1.default.codeEditor, isReadOnly && code_editor_1.default.modifiers.readOnly, (height === '100%' ? true : isFullHeight) && code_editor_1.default.modifiers.fullHeight, className), ref: ref, children: (isUploadEnabled || emptyState) && !value ? ((0, jsx_runtime_1.jsxs)("div", Object.assign({}, getRootProps({
260
+ onClick: (event) => event.stopPropagation() // Prevents clicking TextArea from opening file dialog
261
+ }), { className: (0, react_styles_1.css)(code_editor_1.default.codeEditorContainer, isLoading && file_upload_1.default.modifiers.loading), children: [editorHeader, (0, jsx_runtime_1.jsx)("div", { className: (0, react_styles_1.css)(code_editor_1.default.codeEditorMain, isDragActive && code_editor_1.default.modifiers.dragHover), children: (showEmptyState || emptyState) && !value ? ((0, jsx_runtime_1.jsxs)("div", { className: (0, react_styles_1.css)(code_editor_1.default.codeEditorUpload), children: [hiddenFileInput, editorEmptyState] })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [hiddenFileInput, editor] })) })] }))) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [editorHeader, showEditor && ((0, jsx_runtime_1.jsxs)("div", { className: (0, react_styles_1.css)(code_editor_1.default.codeEditorMain), children: [hiddenFileInput, editor] }))] })) }));
262
+ } }));
342
263
  };
264
+ exports.CodeEditor = CodeEditor;
265
+ exports.CodeEditor.displayName = 'CodeEditor';
343
266
  //# sourceMappingURL=CodeEditor.js.map