@codecademy/codebytes 0.2.1-alpha.3da9ab.0 → 0.2.1-alpha.5fb230.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 +1 -1
- package/package.json +5 -7
- package/src/MonacoEditor/colorsDark.ts +1 -1
- package/src/MonacoEditor/index.tsx +10 -10
- package/src/MonacoEditor/theme.ts +1 -1
- package/src/MonacoEditor/types.ts +1 -1
- package/src/editor.tsx +9 -9
- package/src/index.tsx +16 -17
- package/src/languageSelection.tsx +7 -8
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.
|
|
6
|
+
### [0.2.1-alpha.5fb230.0](https://github.com/Codecademy/client-modules/compare/@codecademy/codebytes@0.2.0...@codecademy/codebytes@0.2.1-alpha.5fb230.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.
|
|
4
|
+
"version": "0.2.1-alpha.5fb230.0",
|
|
5
5
|
"author": "Codecademy Engineering <dev@codecademy.com>",
|
|
6
6
|
"sideEffects": [
|
|
7
7
|
"**/*.css",
|
|
@@ -26,9 +26,8 @@
|
|
|
26
26
|
"@codecademy/variance": "*",
|
|
27
27
|
"@emotion/react": "^11.4.0",
|
|
28
28
|
"@emotion/styled": "^11.3.0",
|
|
29
|
-
"@
|
|
30
|
-
"monaco-editor": "0.
|
|
31
|
-
"react-monaco-editor": "0.34.0",
|
|
29
|
+
"@monaco-editor/react": "4.3.1",
|
|
30
|
+
"monaco-editor": ">= 0.25.0 < 1",
|
|
32
31
|
"react-resize-observer": "1.1.1"
|
|
33
32
|
},
|
|
34
33
|
"scripts": {
|
|
@@ -44,11 +43,10 @@
|
|
|
44
43
|
"@emotion/jest": "^11.3.0",
|
|
45
44
|
"@testing-library/dom": "^7.31.2",
|
|
46
45
|
"@testing-library/react": "^11.0.4",
|
|
47
|
-
"@types/loadable__component": "^5.13.2"
|
|
48
|
-
"monaco-editor-webpack-plugin": "1.9.1"
|
|
46
|
+
"@types/loadable__component": "^5.13.2"
|
|
49
47
|
},
|
|
50
48
|
"publishConfig": {
|
|
51
49
|
"access": "public"
|
|
52
50
|
},
|
|
53
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "1d7c7131bb2c8e8147bf9927c71bb07816fa7c29"
|
|
54
52
|
}
|
|
@@ -3,29 +3,30 @@
|
|
|
3
3
|
// We are working on a monaco package in client-modules that has more configuration around themes and languages
|
|
4
4
|
// Monaco as a shared package RFC https://www.notion.so/codecademy/Monaco-editor-as-a-shared-package-1f4484db165b4abc8394c3556451ef6a
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import ReactMonacoEditor, { OnMount } from '@monaco-editor/react';
|
|
7
|
+
import { editor } from 'monaco-editor/esm/vs/editor/editor.api';
|
|
7
8
|
import React, { useCallback, useRef } from 'react';
|
|
8
|
-
import MonacoEditor from 'react-monaco-editor';
|
|
9
9
|
import ResizeObserver from 'react-resize-observer';
|
|
10
10
|
|
|
11
11
|
import { dark } from './theme';
|
|
12
12
|
import { Monaco } from './types';
|
|
13
13
|
|
|
14
|
-
const ReactMonacoEditor = loadable(() => import('react-monaco-editor'));
|
|
15
|
-
|
|
16
14
|
export type SimpleMonacoEditorProps = {
|
|
17
15
|
value: string;
|
|
18
16
|
language: string;
|
|
19
17
|
onChange?: (value: string) => void;
|
|
20
18
|
};
|
|
21
19
|
|
|
20
|
+
type ThemedEditor = Parameters<OnMount>[0];
|
|
21
|
+
|
|
22
22
|
export const SimpleMonacoEditor: React.FC<SimpleMonacoEditorProps> = ({
|
|
23
23
|
value,
|
|
24
24
|
language,
|
|
25
25
|
onChange,
|
|
26
26
|
}) => {
|
|
27
|
-
const editorRef = useRef<
|
|
28
|
-
const
|
|
27
|
+
const editorRef = useRef<editor.IStandaloneCodeEditor | null>(null);
|
|
28
|
+
const editorOnMount = useCallback((editor: ThemedEditor, monaco: Monaco) => {
|
|
29
|
+
editorRef.current = editor;
|
|
29
30
|
monaco.editor.defineTheme('dark', dark);
|
|
30
31
|
monaco.editor.setTheme('dark');
|
|
31
32
|
}, []);
|
|
@@ -33,18 +34,17 @@ export const SimpleMonacoEditor: React.FC<SimpleMonacoEditorProps> = ({
|
|
|
33
34
|
<>
|
|
34
35
|
<ResizeObserver
|
|
35
36
|
onResize={({ height, width }) => {
|
|
36
|
-
editorRef.current?.
|
|
37
|
+
editorRef.current?.layout({
|
|
37
38
|
height,
|
|
38
39
|
width,
|
|
39
40
|
});
|
|
40
41
|
}}
|
|
41
42
|
/>
|
|
42
43
|
<ReactMonacoEditor
|
|
43
|
-
|
|
44
|
-
editorWillMount={editorWillMount}
|
|
44
|
+
onMount={editorOnMount}
|
|
45
45
|
onChange={onChange}
|
|
46
46
|
options={{ minimap: { enabled: false } }}
|
|
47
|
-
theme="dark"
|
|
47
|
+
theme="vs-dark"
|
|
48
48
|
value={value}
|
|
49
49
|
language={language}
|
|
50
50
|
/>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export type Monaco = typeof import('monaco-editor');
|
|
1
|
+
export type Monaco = typeof import('monaco-editor');
|
package/src/editor.tsx
CHANGED
|
@@ -6,10 +6,10 @@ import {
|
|
|
6
6
|
ToolTip,
|
|
7
7
|
} from '@codecademy/gamut';
|
|
8
8
|
import { CopyIcon } from '@codecademy/gamut-icons';
|
|
9
|
-
import { theme } from '@codecademy/gamut-styles';
|
|
10
9
|
import styled from '@emotion/styled';
|
|
11
10
|
import React, { useState } from 'react';
|
|
12
11
|
|
|
12
|
+
import { CodebytesChangeHandlerMap } from '.';
|
|
13
13
|
import { postSnippet } from './api';
|
|
14
14
|
import type { languageOption } from './consts';
|
|
15
15
|
import { Drawers } from './drawers';
|
|
@@ -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['
|
|
28
|
+
background-color: ${theme.colors['navy-900']};
|
|
29
29
|
`}
|
|
30
30
|
`;
|
|
31
31
|
|
|
@@ -39,11 +39,10 @@ type EditorProps = {
|
|
|
39
39
|
hideCopyButton: boolean;
|
|
40
40
|
language: languageOption;
|
|
41
41
|
text: string;
|
|
42
|
+
|
|
42
43
|
// eslint-disable-next-line react/no-unused-prop-types
|
|
43
|
-
onChange: (
|
|
44
|
-
|
|
45
|
-
) => void /* TODO: Add onChange behavior in DISC-353 */;
|
|
46
|
-
onCopy?: (text: string, language: string) => void;
|
|
44
|
+
onChange: (text: string) => void;
|
|
45
|
+
on?: Pick<CodebytesChangeHandlerMap, 'copy' | 'run'>;
|
|
47
46
|
snippetsBaseUrl?: string;
|
|
48
47
|
};
|
|
49
48
|
|
|
@@ -51,7 +50,7 @@ export const Editor: React.FC<EditorProps> = ({
|
|
|
51
50
|
language,
|
|
52
51
|
text,
|
|
53
52
|
hideCopyButton,
|
|
54
|
-
|
|
53
|
+
on,
|
|
55
54
|
onChange,
|
|
56
55
|
snippetsBaseUrl,
|
|
57
56
|
}) => {
|
|
@@ -64,7 +63,7 @@ export const Editor: React.FC<EditorProps> = ({
|
|
|
64
63
|
.writeText(text)
|
|
65
64
|
// eslint-disable-next-line no-console
|
|
66
65
|
.catch(() => console.error('Failed to copy'));
|
|
67
|
-
|
|
66
|
+
on?.copy?.(text, language);
|
|
68
67
|
setIsCodeByteCopied(true);
|
|
69
68
|
}
|
|
70
69
|
};
|
|
@@ -84,6 +83,7 @@ export const Editor: React.FC<EditorProps> = ({
|
|
|
84
83
|
};
|
|
85
84
|
setStatus('waiting');
|
|
86
85
|
setOutput('');
|
|
86
|
+
on?.run?.();
|
|
87
87
|
|
|
88
88
|
try {
|
|
89
89
|
const response = await postSnippet(data, snippetsBaseUrl);
|
package/src/index.tsx
CHANGED
|
@@ -9,16 +9,22 @@ import { helloWorld, languageOption } from './consts';
|
|
|
9
9
|
import { Editor } from './editor';
|
|
10
10
|
import { LanguageSelection } from './languageSelection';
|
|
11
11
|
|
|
12
|
-
type
|
|
12
|
+
type CodebytesChangeHandler = (text: string, language: languageOption) => void;
|
|
13
|
+
export type CodebytesChangeHandlerMap = {
|
|
14
|
+
logoClick?: () => void;
|
|
15
|
+
edit?: CodebytesChangeHandler;
|
|
16
|
+
languageChange?: CodebytesChangeHandler;
|
|
17
|
+
copy?: CodebytesChangeHandler;
|
|
18
|
+
run?: () => void;
|
|
19
|
+
};
|
|
20
|
+
|
|
13
21
|
export interface CodeByteEditorProps {
|
|
14
22
|
text: string;
|
|
15
23
|
language: languageOption;
|
|
16
24
|
hideCopyButton: boolean;
|
|
17
|
-
onCopy?: (text: string, language: string) => void;
|
|
18
25
|
isIFrame?: boolean;
|
|
19
26
|
snippetsBaseUrl?: string /* TODO in DISC-353: Determine best way to host and include snippets endpoint for both staging and production in both the monolith and next.js repo. */;
|
|
20
|
-
|
|
21
|
-
onLanguageChange?: ChangeHandler;
|
|
27
|
+
on?: CodebytesChangeHandlerMap;
|
|
22
28
|
}
|
|
23
29
|
|
|
24
30
|
const editorStates = states({
|
|
@@ -47,11 +53,9 @@ export const CodeByteEditor: React.FC<CodeByteEditorProps> = ({
|
|
|
47
53
|
text: initialText,
|
|
48
54
|
language: initialLanguage,
|
|
49
55
|
hideCopyButton,
|
|
50
|
-
onCopy,
|
|
51
56
|
isIFrame = false,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
onLanguageChange,
|
|
57
|
+
on,
|
|
58
|
+
snippetsBaseUrl = process.env.CONTAINER_API_BASE,
|
|
55
59
|
}) => {
|
|
56
60
|
const [text, setText] = useState<string>(initialText);
|
|
57
61
|
const [language, setLanguage] = useState<languageOption>(initialLanguage);
|
|
@@ -65,6 +69,7 @@ export const CodeByteEditor: React.FC<CodeByteEditorProps> = ({
|
|
|
65
69
|
target="_blank"
|
|
66
70
|
rel="noreferrer"
|
|
67
71
|
aria-label="visit codecademy.com"
|
|
72
|
+
onClick={() => on?.logoClick?.()}
|
|
68
73
|
/>
|
|
69
74
|
</Box>
|
|
70
75
|
{language ? (
|
|
@@ -74,12 +79,9 @@ export const CodeByteEditor: React.FC<CodeByteEditorProps> = ({
|
|
|
74
79
|
hideCopyButton={hideCopyButton}
|
|
75
80
|
onChange={(newText: string) => {
|
|
76
81
|
setText(newText);
|
|
77
|
-
|
|
78
|
-
newText,
|
|
79
|
-
language
|
|
80
|
-
); /* TODO: in DISC-355 update component to use an object that contains all change handlers */
|
|
82
|
+
on?.edit?.(newText, language);
|
|
81
83
|
}}
|
|
82
|
-
|
|
84
|
+
on={on}
|
|
83
85
|
snippetsBaseUrl={snippetsBaseUrl}
|
|
84
86
|
/>
|
|
85
87
|
) : (
|
|
@@ -88,10 +90,7 @@ export const CodeByteEditor: React.FC<CodeByteEditorProps> = ({
|
|
|
88
90
|
const newText: string = text || helloWorld[newLanguage] || '';
|
|
89
91
|
setLanguage(newLanguage);
|
|
90
92
|
setText(newText);
|
|
91
|
-
|
|
92
|
-
newText,
|
|
93
|
-
newLanguage
|
|
94
|
-
); /* TODO: in DISC-355 update component to use an object that contains all change handlers */
|
|
93
|
+
on?.languageChange?.(newText, newLanguage);
|
|
95
94
|
}}
|
|
96
95
|
/>
|
|
97
96
|
)}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Select } from '@codecademy/gamut';
|
|
2
|
-
import { Background
|
|
2
|
+
import { Background } from '@codecademy/gamut-styles';
|
|
3
3
|
import styled from '@emotion/styled';
|
|
4
4
|
import React from 'react';
|
|
5
5
|
|
|
@@ -8,19 +8,18 @@ import { languageOptions } from './consts';
|
|
|
8
8
|
|
|
9
9
|
const StyledSelect = styled(Select)`
|
|
10
10
|
margin-top: 1rem;
|
|
11
|
-
color: ${
|
|
12
|
-
|
|
11
|
+
color: ${({ theme }) => theme.colors.text};
|
|
13
12
|
select {
|
|
14
|
-
color: ${
|
|
15
|
-
background-color: ${
|
|
13
|
+
color: ${({ theme }) => theme.colors.text};
|
|
14
|
+
background-color: ${({ theme }) => theme.colors.black};
|
|
16
15
|
|
|
17
16
|
&:hover,
|
|
18
17
|
&:active,
|
|
19
18
|
&:focus {
|
|
20
|
-
border-color: ${
|
|
19
|
+
border-color: ${({ theme }) => theme.colors.primary};
|
|
21
20
|
}
|
|
22
21
|
&:focus {
|
|
23
|
-
box-shadow: inset 0 0 0 1px ${
|
|
22
|
+
box-shadow: inset 0 0 0 1px ${({ theme }) => theme.colors.primary};
|
|
24
23
|
}
|
|
25
24
|
}
|
|
26
25
|
`;
|
|
@@ -34,7 +33,7 @@ export const LanguageSelection: React.FC<LanguageSelectionProps> = ({
|
|
|
34
33
|
}) => {
|
|
35
34
|
return (
|
|
36
35
|
<Background bg="black" flex={1} px={16} pt={48}>
|
|
37
|
-
|
|
36
|
+
Which language do you want to code in?
|
|
38
37
|
<StyledSelect
|
|
39
38
|
id="language-select"
|
|
40
39
|
aria-label="Select your language"
|