@coveord/plasma-mantine 47.4.0 → 47.5.0

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.
Files changed (33) hide show
  1. package/.turbo/turbo-build.log +3 -3
  2. package/.turbo/turbo-test.log +8 -8
  3. package/dist/.tsbuildinfo +1 -1
  4. package/dist/cjs/components/code-editor/CodeEditor.js +50 -12
  5. package/dist/cjs/components/code-editor/CodeEditor.js.map +1 -1
  6. package/dist/cjs/components/code-editor/__mocks__/monaco-editor.js +24 -0
  7. package/dist/cjs/components/code-editor/__mocks__/monaco-editor.js.map +1 -0
  8. package/dist/cjs/components/modal-wizard/index.js.map +1 -1
  9. package/dist/cjs/index.js +0 -3
  10. package/dist/cjs/index.js.map +1 -1
  11. package/dist/definitions/components/code-editor/CodeEditor.d.ts +7 -0
  12. package/dist/definitions/components/code-editor/CodeEditor.d.ts.map +1 -1
  13. package/dist/definitions/components/code-editor/__mocks__/monaco-editor.d.ts +8 -0
  14. package/dist/definitions/components/code-editor/__mocks__/monaco-editor.d.ts.map +1 -0
  15. package/dist/definitions/components/modal-wizard/index.d.ts +1 -0
  16. package/dist/definitions/components/modal-wizard/index.d.ts.map +1 -1
  17. package/dist/definitions/index.d.ts +1 -1
  18. package/dist/definitions/index.d.ts.map +1 -1
  19. package/dist/esm/components/code-editor/CodeEditor.js +49 -13
  20. package/dist/esm/components/code-editor/CodeEditor.js.map +1 -1
  21. package/dist/esm/components/code-editor/__mocks__/monaco-editor.js +14 -0
  22. package/dist/esm/components/code-editor/__mocks__/monaco-editor.js.map +1 -0
  23. package/dist/esm/components/modal-wizard/index.js.map +1 -1
  24. package/dist/esm/index.js +1 -1
  25. package/dist/esm/index.js.map +1 -1
  26. package/jest.config.js +0 -1
  27. package/package.json +3 -2
  28. package/src/components/code-editor/CodeEditor.tsx +32 -5
  29. package/src/components/code-editor/__mocks__/monaco-editor.ts +9 -0
  30. package/src/components/code-editor/__tests__/CodeEditor.spec.tsx +24 -5
  31. package/src/components/modal-wizard/index.ts +1 -0
  32. package/src/index.ts +1 -1
  33. package/tsconfig.json +6 -3
@@ -2,12 +2,14 @@ import {CheckSize16Px, CopySize16Px} from '@coveord/plasma-react-icons';
2
2
  import {
3
3
  ActionIcon,
4
4
  Box,
5
+ Center,
5
6
  CopyButton,
6
7
  createStyles,
7
8
  DefaultProps,
8
9
  Group,
9
10
  Input,
10
11
  InputWrapperBaseProps,
12
+ Loader,
11
13
  Selectors,
12
14
  Stack,
13
15
  Tooltip,
@@ -15,13 +17,10 @@ import {
15
17
  } from '@mantine/core';
16
18
  import {useUncontrolled} from '@mantine/hooks';
17
19
  import Editor, {loader} from '@monaco-editor/react';
18
- import * as monaco from 'monaco-editor';
19
- import {FunctionComponent} from 'react';
20
+ import {FunctionComponent, useEffect, useState} from 'react';
20
21
 
21
22
  import {useParentHeight} from '../../hooks';
22
23
 
23
- loader.config({monaco});
24
-
25
24
  const useStyles = createStyles((theme) => ({
26
25
  root: {},
27
26
  editor: {
@@ -66,10 +65,18 @@ interface CodeEditorProps
66
65
  */
67
66
  maxHeight?: number;
68
67
  disabled?: boolean;
68
+ /**
69
+ * Defines how the monaco editor files will be loaded.
70
+ * Note that using `'local'` requires [some additional configuration](https://github.com/suren-atoyan/monaco-react#use-monaco-editor-as-an-npm-package).
71
+ *
72
+ * @default 'local'
73
+ */
74
+ monacoLoader?: 'cdn' | 'local';
69
75
  }
70
76
 
71
77
  const defaultProps: Partial<CodeEditorProps> = {
72
78
  language: 'plaintext',
79
+ monacoLoader: 'local',
73
80
  defaultValue: '',
74
81
  minHeight: 300,
75
82
  };
@@ -91,8 +98,10 @@ export const CodeEditor: FunctionComponent<CodeEditorProps> = (props) => {
91
98
  minHeight,
92
99
  maxHeight,
93
100
  disabled,
101
+ monacoLoader,
94
102
  ...others
95
103
  } = useComponentDefaultProps('CodeEditor', defaultProps, props);
104
+ const [loaded, setLoaded] = useState(false);
96
105
  const {classes, theme} = useStyles();
97
106
  const [_value, handleChange] = useUncontrolled<string>({
98
107
  value,
@@ -102,6 +111,20 @@ export const CodeEditor: FunctionComponent<CodeEditorProps> = (props) => {
102
111
  });
103
112
  const [parentHeight, ref] = useParentHeight();
104
113
 
114
+ const loadLocalMonaco = async () => {
115
+ const monaco = await import('monaco-editor');
116
+ loader.config({monaco});
117
+ setLoaded(true);
118
+ };
119
+
120
+ useEffect(() => {
121
+ if (monacoLoader === 'local') {
122
+ loadLocalMonaco();
123
+ } else {
124
+ setLoaded(true);
125
+ }
126
+ }, []);
127
+
105
128
  const _label = label ? (
106
129
  <Input.Label required={required} {...labelProps}>
107
130
  {label}
@@ -142,7 +165,7 @@ export const CodeEditor: FunctionComponent<CodeEditorProps> = (props) => {
142
165
  </Group>
143
166
  );
144
167
 
145
- const _editor = (
168
+ const _editor = loaded ? (
146
169
  <Box p="md" pl="xs" className={classes.editor}>
147
170
  <Editor
148
171
  defaultLanguage={language}
@@ -167,6 +190,10 @@ export const CodeEditor: FunctionComponent<CodeEditorProps> = (props) => {
167
190
  }}
168
191
  />
169
192
  </Box>
193
+ ) : (
194
+ <Center className={classes.editor}>
195
+ <Loader />
196
+ </Center>
170
197
  );
171
198
 
172
199
  return (
@@ -0,0 +1,9 @@
1
+ const editor = {
2
+ create: () => ({
3
+ dispose: (): void => null,
4
+ }),
5
+ };
6
+
7
+ export const monaco = {
8
+ editor,
9
+ };
@@ -1,22 +1,27 @@
1
1
  import {useForm} from '@mantine/form';
2
- import {render, screen, within} from '@test-utils';
2
+ import {loader} from '@monaco-editor/react';
3
+ import {render, screen, waitForElementToBeRemoved, within} from '@test-utils';
3
4
 
4
5
  import {CodeEditor} from '../CodeEditor';
5
6
 
6
- jest.mock('monaco-editor');
7
- jest.mock('@monaco-editor/react');
8
-
9
7
  describe('CodeEditor', () => {
8
+ beforeEach(() => {
9
+ jest.clearAllMocks();
10
+ });
11
+
10
12
  it('renders the monaco editor and a copy to clipboard button', async () => {
13
+ jest.mock('monaco-editor');
11
14
  render(<CodeEditor label="label" description="description" />);
12
15
 
16
+ await waitForElementToBeRemoved(screen.queryByRole('presentation'));
17
+
13
18
  expect(screen.getByText(/label/)).toBeInTheDocument();
14
19
  expect(screen.getByText(/description/)).toBeInTheDocument();
15
20
  expect(screen.getByTestId('monaco-editor')).toBeInTheDocument();
16
21
  expect(await screen.findByRole('button', {name: /copy/i})).toBeInTheDocument();
17
22
  });
18
23
 
19
- it('shows validation errors underneath the code editor', () => {
24
+ it('shows validation errors underneath the code editor', async () => {
20
25
  const Fixture = () => {
21
26
  const form = useForm({
22
27
  initialValues: {
@@ -29,9 +34,23 @@ describe('CodeEditor', () => {
29
34
  return <CodeEditor {...form.getInputProps('myJsonCode')} />;
30
35
  };
31
36
  render(<Fixture />);
37
+ await waitForElementToBeRemoved(screen.queryByRole('presentation'));
32
38
 
33
39
  const errors = screen.getByRole('alert');
34
40
 
35
41
  expect(within(errors).getByText(/invalid configuration/i)).toBeInTheDocument();
36
42
  });
43
+
44
+ it('loads the monaco editor files from node_modules when monacoLoader prop is "local"', async () => {
45
+ render(<CodeEditor label="label" description="description" monacoLoader="local" />);
46
+ await waitForElementToBeRemoved(screen.queryByRole('presentation'));
47
+ expect(loader.config).toHaveBeenCalledTimes(1);
48
+ expect(screen.getByTestId('monaco-editor')).toBeInTheDocument();
49
+ });
50
+
51
+ it('loads the monaco editor files via CDN when monacoLoader prop is "cnd"', async () => {
52
+ render(<CodeEditor label="label" description="description" monacoLoader="cdn" />);
53
+ expect(loader.config).not.toHaveBeenCalled();
54
+ expect(screen.getByTestId('monaco-editor')).toBeInTheDocument();
55
+ });
37
56
  });
@@ -1 +1,2 @@
1
1
  export * from './ModalWizard';
2
+ export {type ModalWizardStepProps} from './ModalWizardStep';
package/src/index.ts CHANGED
@@ -2,7 +2,7 @@ import {Tuple} from '@mantine/core';
2
2
 
3
3
  import {PlasmaColors} from './theme/PlasmaColors';
4
4
 
5
- export {ColumnDef, createColumnHelper} from '@tanstack/table-core';
5
+ export {type ColumnDef, createColumnHelper} from '@tanstack/table-core';
6
6
 
7
7
  export * from '@mantine/core';
8
8
  export * from '@mantine/form';
package/tsconfig.json CHANGED
@@ -4,8 +4,11 @@
4
4
  "outDir": "./dist",
5
5
  "declarationDir": "./dist/definitions",
6
6
  "rootDir": "src",
7
- "tsBuildInfoFile": "./dist/.tsbuildinfo"
7
+ "tsBuildInfoFile": "./dist/.tsbuildinfo",
8
+ "baseUrl": ".",
9
+ "paths": {
10
+ "@test-utils": ["./src/__tests__/Utils.tsx"]
11
+ }
8
12
  },
9
- "include": ["src"],
10
- "exclude": ["*.spec.*"]
13
+ "include": ["src"]
11
14
  }