Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ liquidjs
@tanstack/react-table
@tanstack/react-virtual
@storybook/addon-docs
@babel/plugin-transform-class-static-block
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,7 @@
"moment": "^2.30.1",
"moment-duration-format": "^2.3.2",
"moment-timezone": "^0.6.0",
"monaco-editor": "^0.44.0",
"monaco-editor": "^0.52.2",
"monaco-yaml": "^5.1.0",
"murmurhash": "^2.0.1",
"mustache": "^4.2.0",
Expand Down Expand Up @@ -1463,6 +1463,7 @@
"@babel/plugin-proposal-optional-chaining": "^7.21.0",
"@babel/plugin-proposal-private-methods": "^7.18.6",
"@babel/plugin-transform-class-properties": "^7.24.7",
"@babel/plugin-transform-class-static-block": "^7.27.1",
"@babel/plugin-transform-numeric-separator": "^7.24.7",
"@babel/plugin-transform-optional-chaining": "^7.24.8",
"@babel/plugin-transform-runtime": "^7.24.7",
Expand Down
9 changes: 9 additions & 0 deletions packages/kbn-babel-preset/common_preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ module.exports = (api) => ({
plugins: [
require.resolve('@kbn/lazy-object/src/plugin/lazy_babel_plugin'),
require.resolve('babel-plugin-add-module-exports'),

/**
* The static class features proposal https://github.com/tc39/proposal-static-class-features
* has been merged with the class fields proposal and is now stage 4.
* We include this here because Monaco needs this and
* this transform has to run before the transform class properties transform.
*/
require.resolve('@babel/plugin-transform-class-static-block'),

// The class properties proposal was merged with the private fields proposal
// into the "class fields" proposal. Babel doesn't support this combined
// proposal yet, which includes private field, so this transform is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { dataPluginMock } from '@kbn/data-plugin/public/mocks';
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
import { renderWithI18n } from '@kbn/test-jest-helpers';
import { waitFor } from '@testing-library/dom';
import { act } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react';
import { BehaviorSubject } from 'rxjs';
Expand Down Expand Up @@ -184,6 +183,7 @@ describe('ESQLEditor', () => {
});

it('should render correctly if editorIsInline prop is set to true', async () => {
const user = userEvent.setup();
const onTextLangQuerySubmit = jest.fn();
const newProps = {
...props,
Expand All @@ -198,7 +198,7 @@ describe('ESQLEditor', () => {
expect(runQueryButton).toBeInTheDocument(); // Assert it exists

if (runQueryButton) {
await userEvent.click(runQueryButton);
await user.click(runQueryButton);
expect(onTextLangQuerySubmit).toHaveBeenCalledTimes(1);
}
});
Expand All @@ -215,6 +215,8 @@ describe('ESQLEditor', () => {

describe('data errors switch', () => {
test('shown with errors enabled', async () => {
const user = userEvent.setup();

const newProps = {
...props,
dataErrorsControl: { enabled: true, onChange: jest.fn() },
Expand All @@ -230,15 +232,17 @@ describe('ESQLEditor', () => {
await waitFor(() => {
expect(queryByTestId('ESQLEditor-footerPopoverButton-error')).toBeInTheDocument();
});
act(() => {
queryByTestId('ESQLEditor-footerPopoverButton-error')?.click();
});

await user.click(queryByTestId('ESQLEditor-footerPopoverButton-error')!);

expect(queryByTestId('ESQLEditor-footerPopover-dataErrorsSwitch')).toBeInTheDocument();

expect(queryAllByText('Data error example')).toHaveLength(2);
});

test('shown with errors disabled', async () => {
const user = userEvent.setup();

const newProps = {
...props,
dataErrorsControl: { enabled: false, onChange: jest.fn() },
Expand All @@ -254,15 +258,17 @@ describe('ESQLEditor', () => {
await waitFor(() => {
expect(queryByTestId('ESQLEditor-footerPopoverButton-error')).toBeInTheDocument();
});
act(() => {
queryByTestId('ESQLEditor-footerPopoverButton-error')?.click();
});

await user.click(queryByTestId('ESQLEditor-footerPopoverButton-error')!);

expect(queryByTestId('ESQLEditor-footerPopover-dataErrorsSwitch')).toBeInTheDocument();

expect(queryAllByText('Data error example')).toHaveLength(0);
});

test('not shown when prop not set', async () => {
const user = userEvent.setup();

mockValidate.mockResolvedValue({
errors: [{ message: 'Data error example', severity: 'error' }],
warnings: [],
Expand All @@ -271,9 +277,9 @@ describe('ESQLEditor', () => {
await waitFor(() => {
expect(queryByTestId('ESQLEditor-footerPopoverButton-error')).toBeInTheDocument();
});
act(() => {
queryByTestId('ESQLEditor-footerPopoverButton-error')?.click();
});

await user.click(queryByTestId('ESQLEditor-footerPopoverButton-error')!);

expect(queryByTestId('ESQLEditor-footerPopover-dataErrorsSwitch')).not.toBeInTheDocument();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -844,8 +844,8 @@ const ESQLEditorInternal = function ESQLEditor({

onLayoutChangeRef.current = onLayoutChange;

const codeEditorOptions: CodeEditorProps['options'] = useMemo(
() => ({
const codeEditorOptions = useMemo(
(): NonNullable<CodeEditorProps['options']> => ({
hover: {
above: false,
},
Expand All @@ -859,7 +859,7 @@ const ESQLEditorInternal = function ESQLEditor({
// this becomes confusing with multiple markers, so quick fixes
// will be proposed only within the tooltip
lightbulb: {
enabled: false,
enabled: monaco.editor.ShowLightbulbIconMode.Off,
},
lineDecorationsWidth: 20,
lineNumbers: 'on',
Expand Down
17 changes: 11 additions & 6 deletions src/platform/packages/shared/kbn-monaco/src/monaco_imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import 'monaco-editor/esm/vs/base/common/worker/simpleWorker';
import 'monaco-editor/esm/vs/base/browser/defaultWorkerFactory';

import 'monaco-editor/esm/vs/editor/browser/coreCommands.js';
import 'monaco-editor/esm/vs/editor/browser/widget/codeEditorWidget.js';
import 'monaco-editor/esm/vs/editor/browser/widget/codeEditor/codeEditorWidget.js';

import 'monaco-editor/esm/vs/editor/contrib/wordOperations/browser/wordOperations.js'; // Needed for word-wise char navigation
import 'monaco-editor/esm/vs/editor/contrib/linesOperations/browser/linesOperations.js'; // Needed for enabling shortcuts of removing/joining/moving lines
import 'monaco-editor/esm/vs/editor/contrib/folding/browser/folding.js'; // Needed for folding
import 'monaco-editor/esm/vs/editor/contrib/suggest/browser/suggestController.js'; // Needed for suggestions
import 'monaco-editor/esm/vs/editor/contrib/hover/browser/hover.js'; // Needed for hover
import 'monaco-editor/esm/vs/editor/contrib/hover/browser/hoverContribution.js'; // Needed for hover
import 'monaco-editor/esm/vs/editor/contrib/parameterHints/browser/parameterHints.js'; // Needed for signature
import 'monaco-editor/esm/vs/editor/contrib/bracketMatching/browser/bracketMatching.js'; // Needed for brackets matching highlight
import 'monaco-editor/esm/vs/editor/contrib/links/browser/links.js'; // Needed for clickable links with Cmd/Ctrl+Click
Expand Down Expand Up @@ -64,14 +64,19 @@ const languageThemeResolverDefinitions = new Map<
>();

declare module 'monaco-editor/esm/vs/editor/editor.api' {
// eslint-disable-next-line @typescript-eslint/no-namespace
// eslint-disable-next-line @typescript-eslint/no-namespace -- augmenting monaco editor types
export namespace editor {
// augment monaco editor types
/**
* @description Registers language theme definition for a language
*/
function registerLanguageThemeResolver(
langId: string,
languageThemeResolver: CustomLangModuleType['languageThemeResolver'],
forceOverride?: boolean
): void;
/**
* @description Returns the registered language theme definition for the provided id
*/
function getLanguageThemeResolver(
langId: string
): CustomLangModuleType['languageThemeResolver'];
Expand All @@ -81,7 +86,7 @@ declare module 'monaco-editor/esm/vs/editor/editor.api' {
// add custom methods to monaco editor
Object.defineProperties(monaco.editor, {
/**
* @description Registers language theme definition for a language
* @description Registration for implementation of {@link monaco.editor.registerLanguageThemeResolver}
*/
registerLanguageThemeResolver: {
value: ((langId, languageThemeDefinition, forceOverride) => {
Expand All @@ -94,7 +99,7 @@ Object.defineProperties(monaco.editor, {
configurable: false,
},
/**
* @description Returns language theme definition for a language
* @description Registration for implementation of {@link monaco.editor.getLanguageThemeResolver}
*/
getLanguageThemeResolver: {
value: ((langId) =>
Expand Down
12 changes: 0 additions & 12 deletions src/platform/packages/shared/kbn-monaco/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,6 @@ const workerConfig = (languages) => ({
},
],
},
optimization: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please tell me why you are removing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the version we upgrading away from, the file referenced in the exclude pattern because it was already transform although to ESM, when we include it to be optimized (i.e treeshaking and the likes) it would break hence why we excluded it from any kind of optimization and just use as is

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...in the new version, it doesn't cause any issues

minimizer: [
(compiler) => {
const TerserPlugin = require('terser-webpack-plugin');
new TerserPlugin({
// exclude this file from being processed by terser,
// because attempts at tree shaking actually botches up the file
exclude: /monaco-editor[\\/]esm[\\/]vs[\\/]base[\\/]common[\\/]map.js/,
}).apply(compiler);
},
],
},
});

module.exports = workerConfig(['default', 'json', 'xjson', 'painless', 'yaml', 'console']);
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,56 @@ if (!Object.hasOwn(global, 'Worker')) {
if (!Object.hasOwn(global, 'MessagePort')) {
global.MessagePort = {};
}

if (!Object.hasOwn(global, 'ClipboardItem')) {
/**
* @typedef {Record<string, Blob | string | Promise<Blob | string>>} ItemData
*/

/**
* @implements {ClipboardItem}
*/
class ClipboardItemMockImpl {
/**
* @type {ItemData}
*/
#data;

/**
* @param {ItemData} d
*/
constructor(d) {
this.data = d;
}

get types() {
return Array.from(Object.keys(this.data));
}

/**
* @param {string} type
* @returns {Promise<Blob | string>}
*/
async getType(type) {
const value = await this.data[type];

if (!value) {
throw new Error(`${type} is not one of the available MIME types on this item.`);
}

return value instanceof window.Blob ? value : new window.Blob([value], { type });
}
}

Object.defineProperty(global, 'ClipboardItem', {
value: ClipboardItemMockImpl,
});
}

if (!Object.hasOwn(global.navigator, 'clipboard')) {
const {
attachClipboardStubToView,
} = require('@testing-library/user-event/dist/cjs/utils/dataTransfer/Clipboard.js');

attachClipboardStubToView(global);
}
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ export const CodeEditor: React.FC<CodeEditorProps> = ({
// outer scrollbars.
alwaysConsumeMouseWheel: false,
},
wordBasedSuggestions: false,
wordBasedSuggestions: 'off',
wordWrap: 'on',
wrappingIndent: 'indent',
matchBrackets: 'never',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export const WorkflowExecuteManualForm = ({
formatOnType: true,
quickSuggestions: false,
suggestOnTriggerCharacters: false,
wordBasedSuggestions: false,
wordBasedSuggestions: 'off',
parameterHints: {
enabled: false,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const editorOptions: monaco.editor.IStandaloneEditorConstructionOptions = {
filterGraceful: true, // Better filtering
localityBonus: true, // Prioritize matches near cursor
},
wordBasedSuggestions: false,
wordBasedSuggestions: 'off',
hover: {
enabled: true,
delay: 300,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

describe('misc console behavior', function testMiscConsoleBehavior() {
before(async () => {
await browser.setWindowSize(1200, 800);
await PageObjects.common.navigateToApp('console');
// Ensure that the text area can be interacted with
await PageObjects.console.skipTourIfExists();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ export function FormulaEditor({
minimap: { enabled: false },
wordWrap: isWordWrapped ? 'on' : 'off',
// Disable suggestions that appear when we don't provide a default suggestion
wordBasedSuggestions: false,
wordBasedSuggestions: 'off',
autoIndent: 'brackets',
wrappingIndent: 'none',
dimension: { width: 320, height: 200 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function JsonDiffViewer({ hit, decreaseAvailableHeightBy }: DocViewRenderProps)
}
editorRef.current.setModel({ original: oldModel, modified: newModel });
const commonOptions: monaco.editor.IEditorOptions = {
lightbulb: { enabled: false },
lightbulb: { enabled: monaco.editor.ShowLightbulbIconMode.Off },
fontSize: 12,
lineNumbers: 'off',
minimap: { enabled: false },
Expand Down
Loading