Skip to content

Commit 8a4f481

Browse files
committed
simplify license setup
1 parent ebe16fa commit 8a4f481

12 files changed

Lines changed: 359 additions & 39 deletions

File tree

NOTICE.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,32 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
214214
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
215215
THE SOFTWARE.
216216

217+
---
218+
This code is forked from the `react-monaco-editor`
219+
https://github.com/react-monaco-editor/react-monaco-editor/blob/975cc47b5cb411ee2ffcbdb973daa9342e81a805/src/editor.tsx
220+
221+
The MIT License (MIT)
222+
223+
Copyright (c) 2016-present Leon Shi
224+
225+
Permission is hereby granted, free of charge, to any person obtaining a copy
226+
of this software and associated documentation files (the "Software"), to deal
227+
in the Software without restriction, including without limitation the rights
228+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
229+
copies of the Software, and to permit persons to whom the Software is
230+
furnished to do so, subject to the following conditions:
231+
232+
The above copyright notice and this permission notice shall be included in
233+
all copies or substantial portions of the Software.
234+
235+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
236+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
237+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
238+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
239+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
240+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
241+
THE SOFTWARE.
242+
217243
---
218244
This code is part of the Services provided by FullStory, Inc. For license information, please refer to https://www.fullstory.com/legal/terms-and-conditions/
219245
Portions of this code are licensed under the following license:

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,6 @@
12161216
"react-intl": "6.6.6",
12171217
"react-is": "^17.0.2",
12181218
"react-markdown": "^6.0.3",
1219-
"react-monaco-editor": "^0.54.0",
12201219
"react-popper-tooltip": "^3.1.1",
12211220
"react-recompose": "^0.33.0",
12221221
"react-redux": "^7.2.8",

packages/kbn-test/jest-preset.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ module.exports = {
107107
transformIgnorePatterns: [
108108
// ignore all node_modules except monaco-editor, monaco-yaml and react-monaco-editor which requires babel transforms to handle dynamic import()
109109
// since ESM modules are not natively supported in Jest yet (https://github.com/facebook/jest/issues/4842)
110-
'[/\\\\]node_modules(?![\\/\\\\](byte-size|monaco-editor|monaco-yaml|monaco-languageserver-types|monaco-marker-data-provider|monaco-worker-manager|vscode-languageserver-types|react-monaco-editor|d3-interpolate|d3-color|langchain|langsmith|@cfworker|gpt-tokenizer|flat|@langchain))[/\\\\].+\\.js$',
110+
'[/\\\\]node_modules(?![\\/\\\\](byte-size|monaco-editor|monaco-yaml|monaco-languageserver-types|monaco-marker-data-provider|monaco-worker-manager|vscode-languageserver-types|d3-interpolate|d3-color|langchain|langsmith|@cfworker|gpt-tokenizer|flat|@langchain))[/\\\\].+\\.js$',
111111
'packages/kbn-pm/dist/index.js',
112112
'[/\\\\]node_modules(?![\\/\\\\](langchain|langsmith|@langchain))/dist/[/\\\\].+\\.js$',
113113
'[/\\\\]node_modules(?![\\/\\\\](langchain|langsmith|@langchain))/dist/util/[/\\\\].+\\.js$',

packages/shared-ux/code_editor/impl/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ SRCS = glob(
2424
BUNDLER_DEPS = [
2525
"@npm//react",
2626
"@npm//tslib",
27-
"@npm//react-monaco-editor",
2827
]
2928

3029
js_library(

packages/shared-ux/code_editor/impl/README.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ date: 2022-12-05
99

1010
## Description
1111

12-
This component is an abstraction of the [Monaco Code Editor](https://microsoft.github.io/monaco-editor/) (and the [React Monaco Editor component](https://github.com/react-monaco-editor/react-monaco-editor)). This component still allows access to the other Monaco features.
12+
This component is an abstraction of the [Monaco Code Editor](https://microsoft.github.io/monaco-editor/). This component still allows access to the other Monaco features.
1313

1414
## Usage
1515

packages/shared-ux/code_editor/impl/code_editor.test.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ import { MockedMonacoEditor, mockedEditorInstance } from '@kbn/code-editor-mock/
1818

1919
import { CodeEditor } from './code_editor';
2020

21-
jest.mock('react-monaco-editor', () => {
22-
return function JestMockEditor() {
23-
return MockedMonacoEditor;
24-
};
21+
jest.mock('./react_monaco_editor', () => {
22+
return { MonacoEditor: MockedMonacoEditor };
2523
});
2624

2725
// Mock the htmlIdGenerator to generate predictable ids for snapshot tests

packages/shared-ux/code_editor/impl/code_editor.tsx

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
*/
99

1010
import React, { useState, useRef, useCallback, useMemo, useEffect, KeyboardEvent, FC } from 'react';
11-
import ReactMonacoEditor, {
12-
type MonacoEditorProps as ReactMonacoEditorProps,
13-
} from 'react-monaco-editor';
1411
import {
1512
htmlIdGenerator,
1613
EuiToolTip,
@@ -34,6 +31,10 @@ import {
3431
import { i18n } from '@kbn/i18n';
3532
import { FormattedMessage } from '@kbn/i18n-react';
3633
import { css } from '@emotion/react';
34+
import {
35+
MonacoEditor as ReactMonacoEditor,
36+
type MonacoEditorProps as ReactMonacoEditorProps,
37+
} from './react_monaco_editor';
3738
import './register_languages';
3839
import { remeasureFonts } from './remeasure_fonts';
3940

@@ -168,7 +169,7 @@ export interface CodeEditorProps {
168169
export const CodeEditor: React.FC<CodeEditorProps> = ({
169170
languageId,
170171
value,
171-
onChange: _onChange,
172+
onChange,
172173
width,
173174
height,
174175
options,
@@ -225,8 +226,6 @@ export const CodeEditor: React.FC<CodeEditorProps> = ({
225226

226227
const [isHintActive, setIsHintActive] = useState(true);
227228

228-
const onChange = useBug175684OnChange(_onChange);
229-
230229
const startEditing = useCallback(() => {
231230
setIsHintActive(false);
232231
_editor?.focus();
@@ -701,23 +700,6 @@ const useFitToContent = ({
701700
}, [editor, isFitToContent, minLines, maxLines, isFullScreen]);
702701
};
703702

704-
// https://github.com/elastic/kibana/issues/175684
705-
// 'react-monaco-editor' has a bug that it always calls the initial onChange callback, so the closure might become stale
706-
// we work this around by calling the latest onChange from props
707-
const useBug175684OnChange = (onChange: CodeEditorProps['onChange']) => {
708-
const onChangePropRef = useRef<CodeEditorProps['onChange']>(onChange);
709-
useEffect(() => {
710-
onChangePropRef.current = onChange;
711-
}, [onChange]);
712-
const onChangeWrapper = useCallback<NonNullable<CodeEditorProps['onChange']>>((_value, event) => {
713-
if (onChangePropRef.current) {
714-
onChangePropRef.current(_value, event);
715-
}
716-
}, []);
717-
718-
return onChangeWrapper;
719-
};
720-
721703
const UseBug177756ReBroadcastMouseDown: FC<{ children: React.ReactNode }> = ({ children }) => {
722704
const [$codeWrapper, setCodeWrapper] = React.useState<HTMLElement | null>(null);
723705

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
This is a fork of [react-monaco-editor project](https://github.com/react-monaco-editor/react-monaco-editor) that is a Monaco editor wrapper for React.
2+
This fork is needed to apply a change that fixes the editor behavior in Kibana when running React@18 in Legacy Mode and the bug is described [here](https://github.com/facebook/react/issues/31023)
3+
The change is to replace the `useEffect` hook with `useLayoutEffect` when the editor is in controlled mode and the value is updated from prop.
4+
5+
```diff
6+
---useEffect(() => {
7+
+++useLayoutEffect(() => {
8+
if (editor.current) {
9+
if (value === editor.current.getValue()) {
10+
return;
11+
}
12+
13+
const model = editor.current.getModel();
14+
__prevent_trigger_change_event.current = true;
15+
editor.current.pushUndoStop();
16+
// pushEditOperations says it expects a cursorComputer, but doesn't seem to need one.
17+
model.pushEditOperations(
18+
[],
19+
[
20+
{
21+
range: model.getFullModelRange(),
22+
text: value,
23+
},
24+
],
25+
undefined,
26+
);
27+
editor.current.pushUndoStop();
28+
__prevent_trigger_change_event.current = false;
29+
}
30+
}, [value]);
31+
```
32+
33+
In addition, the fork only includes functionality that is used in Kibana and removes the rest of the code that is not needed.

0 commit comments

Comments
 (0)