@codecademy/codebytes 0.2.1-alpha.7386df.0 → 0.2.1-alpha.808d0d.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.
package/CHANGELOG.md CHANGED
@@ -3,7 +3,7 @@
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
- ### [0.2.1-alpha.7386df.0](https://github.com/Codecademy/client-modules/compare/@codecademy/codebytes@0.2.0...@codecademy/codebytes@0.2.1-alpha.7386df.0) (2022-01-05)
6
+ ### [0.2.1-alpha.808d0d.0](https://github.com/Codecademy/client-modules/compare/@codecademy/codebytes@0.2.0...@codecademy/codebytes@0.2.1-alpha.808d0d.0) (2022-01-11)
7
7
 
8
8
  **Note:** Version bump only for package @codecademy/codebytes
9
9
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@codecademy/codebytes",
3
3
  "description": "Codebytes Code Editor",
4
- "version": "0.2.1-alpha.7386df.0",
4
+ "version": "0.2.1-alpha.808d0d.0",
5
5
  "author": "Codecademy Engineering <dev@codecademy.com>",
6
6
  "sideEffects": [
7
7
  "**/*.css",
@@ -27,8 +27,8 @@
27
27
  "@emotion/react": "^11.4.0",
28
28
  "@emotion/styled": "^11.3.0",
29
29
  "@loadable/component": "^5.13.1",
30
- "monaco-editor": "0.20.0",
31
- "react-monaco-editor": "0.34.0",
30
+ "@monaco-editor/react": "4.3.1",
31
+ "monaco-editor": ">= 0.25.0 < 1",
32
32
  "react-resize-observer": "1.1.1"
33
33
  },
34
34
  "scripts": {
@@ -50,5 +50,5 @@
50
50
  "publishConfig": {
51
51
  "access": "public"
52
52
  },
53
- "gitHead": "b46e91d88ac0844c7f4d71856806785aab64cdc6"
53
+ "gitHead": "263768f9ce1f6e3f97404bc46d560268eece40c2"
54
54
  }
@@ -51,4 +51,4 @@ export const ui = {
51
51
 
52
52
  export type SyntaxColors = typeof syntax;
53
53
 
54
- export type UIColors = typeof ui;
54
+ export type UIColors = typeof ui;
@@ -4,14 +4,15 @@
4
4
  // Monaco as a shared package RFC https://www.notion.so/codecademy/Monaco-editor-as-a-shared-package-1f4484db165b4abc8394c3556451ef6a
5
5
 
6
6
  import loadable from '@loadable/component';
7
+ import { OnMount } from '@monaco-editor/react';
8
+ import { editor } from 'monaco-editor/esm/vs/editor/editor.api';
7
9
  import React, { useCallback, useRef } from 'react';
8
- import MonacoEditor from 'react-monaco-editor';
9
10
  import ResizeObserver from 'react-resize-observer';
10
11
 
11
12
  import { dark } from './theme';
12
13
  import { Monaco } from './types';
13
14
 
14
- const ReactMonacoEditor = loadable(() => import('react-monaco-editor'));
15
+ const ReactMonacoEditor = loadable(() => import('@monaco-editor/react'));
15
16
 
16
17
  export type SimpleMonacoEditorProps = {
17
18
  value: string;
@@ -19,34 +20,39 @@ export type SimpleMonacoEditorProps = {
19
20
  onChange?: (value: string) => void;
20
21
  };
21
22
 
23
+ type ThemedEditor = Parameters<OnMount>[0];
24
+
22
25
  export const SimpleMonacoEditor: React.FC<SimpleMonacoEditorProps> = ({
23
26
  value,
24
27
  language,
25
28
  onChange,
26
29
  }) => {
27
- const editorRef = useRef<MonacoEditor>(null);
28
- const editorWillMount = useCallback((monaco: Monaco) => {
29
- monaco.editor.defineTheme('dark', dark);
30
- monaco.editor.setTheme('dark');
31
- }, []);
30
+ const editorRef = useRef<editor.IStandaloneCodeEditor | null>(null);
31
+ const editorWillMount = useCallback(
32
+ (editor: ThemedEditor, monaco: Monaco) => {
33
+ editorRef.current = editor;
34
+ monaco.editor.defineTheme('dark', dark);
35
+ monaco.editor.setTheme('dark');
36
+ },
37
+ []
38
+ );
32
39
  return (
33
40
  <>
34
41
  <ResizeObserver
35
42
  onResize={({ height, width }) => {
36
- editorRef.current?.editor?.layout({
43
+ editorRef.current?.layout({
37
44
  height,
38
45
  width,
39
46
  });
40
47
  }}
41
48
  />
42
49
  <ReactMonacoEditor
43
- ref={editorRef}
44
- editorWillMount={editorWillMount}
50
+ onMount={editorWillMount}
45
51
  onChange={onChange}
46
52
  options={{ minimap: { enabled: false } }}
47
- theme="dark"
53
+ theme="vs-dark"
48
54
  value={value}
49
- language="language"
55
+ language={language}
50
56
  />
51
57
  </>
52
58
  );
@@ -61,4 +61,4 @@ const theme = ({
61
61
  },
62
62
  });
63
63
 
64
- export const dark = theme(darkColors);
64
+ export const dark = theme(darkColors);
@@ -1 +1 @@
1
- export type Monaco = typeof import('monaco-editor');
1
+ export type Monaco = typeof import('monaco-editor');
package/src/editor.tsx CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  ToolTip,
7
7
  } from '@codecademy/gamut';
8
8
  import { CopyIcon } from '@codecademy/gamut-icons';
9
- import { theme } from '@codecademy/gamut-styles';
9
+ import { colors } from '@codecademy/gamut-styles';
10
10
  import styled from '@emotion/styled';
11
11
  import React, { useState } from 'react';
12
12
 
@@ -23,9 +23,9 @@ const Output = styled.pre<{ hasError: boolean }>`
23
23
  font-family: Monaco;
24
24
  font-size: 0.875rem;
25
25
  overflow: auto;
26
- ${({ hasError }) => `
26
+ ${({ hasError, theme }) => `
27
27
  color: ${hasError ? theme.colors.orange : theme.colors.white};
28
- background-color: ${theme.colors['gray-900']};
28
+ background-color: ${colors['gray-900']};
29
29
  `}
30
30
  `;
31
31
 
@@ -39,10 +39,7 @@ type EditorProps = {
39
39
  hideCopyButton: boolean;
40
40
  language: languageOption;
41
41
  text: string;
42
- // eslint-disable-next-line react/no-unused-prop-types
43
- onChange: (
44
- text: string
45
- ) => void /* TODO: Add onChange behavior in DISC-353 */;
42
+ onChange: (text: string) => void;
46
43
  onCopy?: (text: string, language: string) => void;
47
44
  snippetsBaseUrl?: string;
48
45
  };
package/src/index.tsx CHANGED
@@ -46,7 +46,7 @@ export const CodeByteEditor: React.FC<CodeByteEditorProps> = ({
46
46
  hideCopyButton,
47
47
  onCopy,
48
48
  isIFrame = false,
49
- snippetsBaseUrl = '',
49
+ snippetsBaseUrl = process.env.CONTAINER_API_BASE,
50
50
  onTextChange,
51
51
  }) => {
52
52
  const [text, setText] = useState<string>(initialText);