@codecademy/codebytes 0.2.0 → 0.2.1-alpha.a29b64.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 +8 -0
- package/package.json +10 -4
- package/src/MonacoEditor/colorsDark.ts +54 -0
- package/src/MonacoEditor/index.tsx +53 -0
- package/src/MonacoEditor/theme.ts +64 -0
- package/src/MonacoEditor/types.ts +1 -0
- package/src/editor.tsx +9 -1
- package/src/index.tsx +12 -12
- package/src/theme.d.ts +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
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.a29b64.0](https://github.com/Codecademy/client-modules/compare/@codecademy/codebytes@0.2.0...@codecademy/codebytes@0.2.1-alpha.a29b64.0) (2022-01-04)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @codecademy/codebytes
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
## [0.2.0](https://github.com/Codecademy/client-modules/compare/@codecademy/codebytes@0.1.0...@codecademy/codebytes@0.2.0) (2022-01-04)
|
|
7
15
|
|
|
8
16
|
|
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.0",
|
|
4
|
+
"version": "0.2.1-alpha.a29b64.0",
|
|
5
5
|
"author": "Codecademy Engineering <dev@codecademy.com>",
|
|
6
6
|
"sideEffects": [
|
|
7
7
|
"**/*.css",
|
|
@@ -25,7 +25,11 @@
|
|
|
25
25
|
"@codecademy/gamut-styles": "*",
|
|
26
26
|
"@codecademy/variance": "*",
|
|
27
27
|
"@emotion/react": "^11.4.0",
|
|
28
|
-
"@emotion/styled": "^11.3.0"
|
|
28
|
+
"@emotion/styled": "^11.3.0",
|
|
29
|
+
"@loadable/component": "^5.13.1",
|
|
30
|
+
"monaco-editor": "0.20.0",
|
|
31
|
+
"react-monaco-editor": "0.34.0",
|
|
32
|
+
"react-resize-observer": "1.1.1"
|
|
29
33
|
},
|
|
30
34
|
"scripts": {
|
|
31
35
|
"verify": "tsc --noEmit",
|
|
@@ -39,10 +43,12 @@
|
|
|
39
43
|
"devDependencies": {
|
|
40
44
|
"@emotion/jest": "^11.3.0",
|
|
41
45
|
"@testing-library/dom": "^7.31.2",
|
|
42
|
-
"@testing-library/react": "^11.0.4"
|
|
46
|
+
"@testing-library/react": "^11.0.4",
|
|
47
|
+
"@types/loadable__component": "^5.13.2",
|
|
48
|
+
"monaco-editor-webpack-plugin": "1.9.1"
|
|
43
49
|
},
|
|
44
50
|
"publishConfig": {
|
|
45
51
|
"access": "public"
|
|
46
52
|
},
|
|
47
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "44e6bad947fe2052d41347c37f3ae285f6f0248a"
|
|
48
54
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// DO NOT CHANGE ANYTHING HERE
|
|
2
|
+
// This file is part of the Codebytes MVP and only includes basic configuration around theming for the SimpleMonacoEditor component
|
|
3
|
+
// We are working on a monaco package in client-modules that has more configuration around themes and languages
|
|
4
|
+
// Monaco as a shared package RFC https://www.notion.so/codecademy/Monaco-editor-as-a-shared-package-1f4484db165b4abc8394c3556451ef6a
|
|
5
|
+
|
|
6
|
+
import { colors, editorColors } from '@codecademy/gamut-styles';
|
|
7
|
+
|
|
8
|
+
const darkTheme = {
|
|
9
|
+
blue: editorColors.blue,
|
|
10
|
+
deepPurple: editorColors.deepPurple,
|
|
11
|
+
gray: editorColors.gray,
|
|
12
|
+
green: editorColors.green,
|
|
13
|
+
orange: editorColors.orange,
|
|
14
|
+
purple: editorColors.purple,
|
|
15
|
+
red: editorColors.red,
|
|
16
|
+
white: colors.white,
|
|
17
|
+
yellow: editorColors.yellow,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const syntax = {
|
|
21
|
+
attribute: darkTheme.green,
|
|
22
|
+
annotation: darkTheme.red,
|
|
23
|
+
atom: darkTheme.deepPurple,
|
|
24
|
+
basic: darkTheme.white,
|
|
25
|
+
comment: darkTheme.gray,
|
|
26
|
+
constant: darkTheme.orange,
|
|
27
|
+
decoration: darkTheme.red,
|
|
28
|
+
invalid: darkTheme.red,
|
|
29
|
+
key: darkTheme.blue,
|
|
30
|
+
keyword: darkTheme.purple,
|
|
31
|
+
number: darkTheme.red,
|
|
32
|
+
operator: darkTheme.red,
|
|
33
|
+
predefined: darkTheme.white,
|
|
34
|
+
property: darkTheme.red,
|
|
35
|
+
regexp: darkTheme.green,
|
|
36
|
+
string: darkTheme.yellow,
|
|
37
|
+
tag: darkTheme.red,
|
|
38
|
+
text: darkTheme.orange,
|
|
39
|
+
value: darkTheme.yellow,
|
|
40
|
+
variable: darkTheme.green,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const ui = {
|
|
44
|
+
background: '#211E2F',
|
|
45
|
+
text: darkTheme.white,
|
|
46
|
+
indent: {
|
|
47
|
+
active: '#393b41',
|
|
48
|
+
inactive: '#494b51',
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export type SyntaxColors = typeof syntax;
|
|
53
|
+
|
|
54
|
+
export type UIColors = typeof ui;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// DO NOT CHANGE ANYTHING HERE
|
|
2
|
+
// This component is part of the Codebytes MVP and only includes basic configuration around theming
|
|
3
|
+
// We are working on a monaco package in client-modules that has more configuration around themes and languages
|
|
4
|
+
// Monaco as a shared package RFC https://www.notion.so/codecademy/Monaco-editor-as-a-shared-package-1f4484db165b4abc8394c3556451ef6a
|
|
5
|
+
|
|
6
|
+
import loadable from '@loadable/component';
|
|
7
|
+
import React, { useCallback, useRef } from 'react';
|
|
8
|
+
import MonacoEditor from 'react-monaco-editor';
|
|
9
|
+
import ResizeObserver from 'react-resize-observer';
|
|
10
|
+
|
|
11
|
+
import { dark } from './theme';
|
|
12
|
+
import { Monaco } from './types';
|
|
13
|
+
|
|
14
|
+
const ReactMonacoEditor = loadable(() => import('react-monaco-editor'));
|
|
15
|
+
|
|
16
|
+
export type SimpleMonacoEditorProps = {
|
|
17
|
+
value: string;
|
|
18
|
+
language: string;
|
|
19
|
+
onChange?: (value: string) => void;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const SimpleMonacoEditor: React.FC<SimpleMonacoEditorProps> = ({
|
|
23
|
+
value,
|
|
24
|
+
language,
|
|
25
|
+
onChange,
|
|
26
|
+
}) => {
|
|
27
|
+
const editorRef = useRef<MonacoEditor>(null);
|
|
28
|
+
const editorWillMount = useCallback((monaco: Monaco) => {
|
|
29
|
+
monaco.editor.defineTheme('dark', dark);
|
|
30
|
+
monaco.editor.setTheme('dark');
|
|
31
|
+
}, []);
|
|
32
|
+
return (
|
|
33
|
+
<>
|
|
34
|
+
<ResizeObserver
|
|
35
|
+
onResize={({ height, width }) => {
|
|
36
|
+
editorRef.current?.editor?.layout({
|
|
37
|
+
height,
|
|
38
|
+
width,
|
|
39
|
+
});
|
|
40
|
+
}}
|
|
41
|
+
/>
|
|
42
|
+
<ReactMonacoEditor
|
|
43
|
+
ref={editorRef}
|
|
44
|
+
editorWillMount={editorWillMount}
|
|
45
|
+
onChange={onChange}
|
|
46
|
+
options={{ minimap: { enabled: false } }}
|
|
47
|
+
theme="dark"
|
|
48
|
+
value={value}
|
|
49
|
+
language={language}
|
|
50
|
+
/>
|
|
51
|
+
</>
|
|
52
|
+
);
|
|
53
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// DO NOT CHANGE ANYTHING HERE
|
|
2
|
+
// This file is part of the Codebytes MVP and only includes basic configuration around theming for the SimpleMonacoEditor component
|
|
3
|
+
// We are working on a monaco package in client-modules that has more configuration around themes and languages
|
|
4
|
+
// Monaco as a shared package RFC https://www.notion.so/codecademy/Monaco-editor-as-a-shared-package-1f4484db165b4abc8394c3556451ef6a
|
|
5
|
+
|
|
6
|
+
import type * as monaco from 'monaco-editor';
|
|
7
|
+
|
|
8
|
+
import * as darkColors from './colorsDark';
|
|
9
|
+
|
|
10
|
+
const c = (color: string) => color.substr(1);
|
|
11
|
+
|
|
12
|
+
const theme = ({
|
|
13
|
+
ui,
|
|
14
|
+
syntax,
|
|
15
|
+
}: {
|
|
16
|
+
ui: darkColors.UIColors;
|
|
17
|
+
syntax: darkColors.SyntaxColors;
|
|
18
|
+
}): monaco.editor.IStandaloneThemeData => ({
|
|
19
|
+
base: 'vs-dark',
|
|
20
|
+
inherit: true,
|
|
21
|
+
rules: [
|
|
22
|
+
// Base
|
|
23
|
+
{ token: '', foreground: c(syntax.basic) },
|
|
24
|
+
{ token: 'regexp', foreground: c(syntax.regexp) },
|
|
25
|
+
{ token: 'annotation', foreground: c(syntax.annotation) },
|
|
26
|
+
{ token: 'type', foreground: c(syntax.annotation) },
|
|
27
|
+
{ token: 'doctype', foreground: c(syntax.comment) },
|
|
28
|
+
{ token: 'delimiter', foreground: c(syntax.decoration) },
|
|
29
|
+
{ token: 'invalid', foreground: c(syntax.invalid) },
|
|
30
|
+
{ token: 'emphasis', fontStyle: 'italic' },
|
|
31
|
+
{ token: 'strong', fontStyle: 'bold' },
|
|
32
|
+
{ token: 'variable', foreground: c(syntax.variable) },
|
|
33
|
+
{ token: 'variable.predefined', foreground: c(syntax.variable) },
|
|
34
|
+
{ token: 'constant', foreground: c(syntax.constant) },
|
|
35
|
+
{ token: 'comment', foreground: c(syntax.comment) },
|
|
36
|
+
{ token: 'number', foreground: c(syntax.number) },
|
|
37
|
+
{ token: 'number.hex', foreground: c(syntax.number) },
|
|
38
|
+
{ token: 'keyword.directive', foreground: c(syntax.comment) },
|
|
39
|
+
{ token: 'include', foreground: c(syntax.comment) },
|
|
40
|
+
{ token: 'key', foreground: c(syntax.property) },
|
|
41
|
+
{ token: 'attribute.name', foreground: c(syntax.attribute) },
|
|
42
|
+
{ token: 'attribute.name-numeric', foreground: c(syntax.string) },
|
|
43
|
+
{ token: 'attribute.value', foreground: c(syntax.property) },
|
|
44
|
+
{ token: 'attribute.value.number', foreground: c(syntax.number) },
|
|
45
|
+
{ token: 'string', foreground: c(syntax.string) },
|
|
46
|
+
{ token: 'string.yaml', foreground: c(syntax.string) },
|
|
47
|
+
{ token: 'tag', foreground: c(syntax.tag) },
|
|
48
|
+
{ token: 'tag.id.jade', foreground: c(syntax.tag) },
|
|
49
|
+
{ token: 'tag.class.jade', foreground: c(syntax.tag) },
|
|
50
|
+
{ token: 'metatag', foreground: c(syntax.comment) },
|
|
51
|
+
{ token: 'attribute.value.unit', foreground: c(syntax.string) },
|
|
52
|
+
{ token: 'keyword', foreground: c(syntax.keyword) },
|
|
53
|
+
{ token: 'keyword.flow', foreground: c(syntax.keyword) },
|
|
54
|
+
],
|
|
55
|
+
colors: {
|
|
56
|
+
'editor.background': ui.background,
|
|
57
|
+
'editor.foreground': ui.text,
|
|
58
|
+
'editorIndentGuide.background': ui.indent.inactive,
|
|
59
|
+
'editorIndentGuide.activeBackground': ui.indent.active,
|
|
60
|
+
'editorWhitespace.foreground': syntax.comment,
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
export const dark = theme(darkColors);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Monaco = typeof import('monaco-editor');
|
package/src/editor.tsx
CHANGED
|
@@ -13,6 +13,7 @@ import React, { useState } from 'react';
|
|
|
13
13
|
import { postSnippet } from './api';
|
|
14
14
|
import type { languageOption } from './consts';
|
|
15
15
|
import { Drawers } from './drawers';
|
|
16
|
+
import { SimpleMonacoEditor } from './MonacoEditor';
|
|
16
17
|
|
|
17
18
|
const Output = styled.pre<{ hasError: boolean }>`
|
|
18
19
|
width: 100%;
|
|
@@ -51,6 +52,7 @@ export const Editor: React.FC<EditorProps> = ({
|
|
|
51
52
|
text,
|
|
52
53
|
hideCopyButton,
|
|
53
54
|
onCopy,
|
|
55
|
+
onChange,
|
|
54
56
|
snippetsBaseUrl,
|
|
55
57
|
}) => {
|
|
56
58
|
const [output, setOutput] = useState('');
|
|
@@ -105,7 +107,13 @@ export const Editor: React.FC<EditorProps> = ({
|
|
|
105
107
|
return (
|
|
106
108
|
<>
|
|
107
109
|
<Drawers
|
|
108
|
-
leftChild={
|
|
110
|
+
leftChild={
|
|
111
|
+
<SimpleMonacoEditor
|
|
112
|
+
value={text}
|
|
113
|
+
language={language}
|
|
114
|
+
onChange={onChange}
|
|
115
|
+
/>
|
|
116
|
+
}
|
|
109
117
|
rightChild={
|
|
110
118
|
<Output hasError={status === 'error'} aria-live="polite">
|
|
111
119
|
{output}
|
package/src/index.tsx
CHANGED
|
@@ -8,6 +8,16 @@ import React, { useState } from 'react';
|
|
|
8
8
|
import { languageOption } from './consts';
|
|
9
9
|
import { Editor } from './editor';
|
|
10
10
|
|
|
11
|
+
export interface CodeByteEditorProps {
|
|
12
|
+
text: string;
|
|
13
|
+
language: languageOption;
|
|
14
|
+
hideCopyButton: boolean;
|
|
15
|
+
onCopy?: (text: string, language: string) => void;
|
|
16
|
+
isIFrame?: boolean;
|
|
17
|
+
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. */;
|
|
18
|
+
onTextChange?: (text: string) => void;
|
|
19
|
+
}
|
|
20
|
+
|
|
11
21
|
const editorStates = states({
|
|
12
22
|
isIFrame: { height: '100vh' },
|
|
13
23
|
});
|
|
@@ -17,8 +27,8 @@ const editorBaseStyles = system.css({
|
|
|
17
27
|
borderColor: 'gray-900',
|
|
18
28
|
display: 'flex',
|
|
19
29
|
flexDirection: 'column',
|
|
20
|
-
height: '
|
|
21
|
-
width: '
|
|
30
|
+
height: '400px',
|
|
31
|
+
width: '688px',
|
|
22
32
|
overflow: 'hidden',
|
|
23
33
|
});
|
|
24
34
|
export interface EditorStyleProps
|
|
@@ -30,16 +40,6 @@ const EditorContainer = styled(Background)<EditorStyleProps>(
|
|
|
30
40
|
editorStates
|
|
31
41
|
);
|
|
32
42
|
|
|
33
|
-
export interface CodeByteEditorProps {
|
|
34
|
-
text: string;
|
|
35
|
-
language: languageOption;
|
|
36
|
-
hideCopyButton: boolean;
|
|
37
|
-
onCopy?: (text: string, language: string) => void;
|
|
38
|
-
isIFrame?: boolean;
|
|
39
|
-
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. */;
|
|
40
|
-
onTextChange?: (text: string) => void;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
43
|
export const CodeByteEditor: React.FC<CodeByteEditorProps> = ({
|
|
44
44
|
text: initialText,
|
|
45
45
|
language,
|