@codecademy/codebytes 0.3.1-alpha.2eff1d.0 → 0.3.1-alpha.8f8ccd.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.3.1-alpha.2eff1d.0](https://github.com/Codecademy/client-modules/compare/@codecademy/codebytes@0.3.0...@codecademy/codebytes@0.3.1-alpha.2eff1d.0) (2022-01-13)
6
+ ### [0.3.1-alpha.8f8ccd.0](https://github.com/Codecademy/client-modules/compare/@codecademy/codebytes@0.3.0...@codecademy/codebytes@0.3.1-alpha.8f8ccd.0) (2022-01-21)
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.3.1-alpha.2eff1d.0",
4
+ "version": "0.3.1-alpha.8f8ccd.0",
5
5
  "author": "Codecademy Engineering <dev@codecademy.com>",
6
6
  "sideEffects": [
7
7
  "**/*.css",
@@ -48,5 +48,5 @@
48
48
  "publishConfig": {
49
49
  "access": "public"
50
50
  },
51
- "gitHead": "7ceb6728e18a6fd6920b1b3fa8077e92d2b2d26d"
51
+ "gitHead": "41f8ca85bfff777a9f60105a63055eadb69d8cae"
52
52
  }
package/src/api.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { languageOption } from './consts';
1
+ import type { LanguageOption } from './consts';
2
2
 
3
3
  interface Response {
4
4
  stderr: string;
@@ -7,7 +7,7 @@ interface Response {
7
7
  }
8
8
 
9
9
  interface PostSnippetData {
10
- language: languageOption;
10
+ language: LanguageOption;
11
11
  code: string;
12
12
  }
13
13
 
package/src/consts.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  // key = language param to send to snippets service
2
2
  // val = label in language selection drop down
3
- export const languageOptions = {
3
+ export const LanguageOptions = {
4
4
  '': 'Select a language',
5
5
  cpp: 'C++',
6
6
  csharp: 'C#',
@@ -12,11 +12,11 @@ export const languageOptions = {
12
12
  scheme: 'Scheme',
13
13
  };
14
14
 
15
- export type languageOption = keyof typeof languageOptions;
15
+ export type LanguageOption = keyof typeof LanguageOptions;
16
16
 
17
- export const validLanguages = Object.keys(languageOptions).filter(
17
+ export const validLanguages = Object.keys(LanguageOptions).filter(
18
18
  (option) => !!option
19
- ) as languageOption[];
19
+ ) as LanguageOption[];
20
20
 
21
21
  const cpp = `#include <iostream>
22
22
  int main() {
@@ -52,7 +52,7 @@ const scheme = `(begin
52
52
  (display "Hello world!")
53
53
  (newline))`;
54
54
 
55
- export const helloWorld: { [key in languageOption]?: string } = {
55
+ export const helloWorld = {
56
56
  cpp,
57
57
  csharp,
58
58
  golang,
@@ -61,4 +61,4 @@ export const helloWorld: { [key in languageOption]?: string } = {
61
61
  python,
62
62
  ruby,
63
63
  scheme,
64
- };
64
+ } as const;
package/src/editor.tsx CHANGED
@@ -13,7 +13,6 @@ import { postSnippet } from './api';
13
13
  import type { languageOption } from './consts';
14
14
  import { Drawers } from './drawers';
15
15
  import { SimpleMonacoEditor } from './MonacoEditor';
16
- import { CodebytesChangeHandlerMap } from './types';
17
16
 
18
17
  const Output = styled.pre<{ hasError: boolean }>`
19
18
  width: 100%;
@@ -39,9 +38,8 @@ type EditorProps = {
39
38
  hideCopyButton: boolean;
40
39
  language: languageOption;
41
40
  text: string;
42
-
43
41
  onChange: (text: string) => void;
44
- on?: CodebytesChangeHandlerMap;
42
+ onCopy?: (text: string, language: string) => void;
45
43
  snippetsBaseUrl?: string;
46
44
  };
47
45
 
@@ -49,7 +47,7 @@ export const Editor: React.FC<EditorProps> = ({
49
47
  language,
50
48
  text,
51
49
  hideCopyButton,
52
- on,
50
+ onCopy,
53
51
  onChange,
54
52
  snippetsBaseUrl,
55
53
  }) => {
@@ -62,7 +60,7 @@ export const Editor: React.FC<EditorProps> = ({
62
60
  .writeText(text)
63
61
  // eslint-disable-next-line no-console
64
62
  .catch(() => console.error('Failed to copy'));
65
- on?.copy?.(text, language);
63
+ onCopy?.(text, language);
66
64
  setIsCodeByteCopied(true);
67
65
  }
68
66
  };
@@ -82,7 +80,6 @@ export const Editor: React.FC<EditorProps> = ({
82
80
  };
83
81
  setStatus('waiting');
84
82
  setOutput('');
85
- on?.run?.();
86
83
 
87
84
  try {
88
85
  const response = await postSnippet(data, snippetsBaseUrl);
package/src/index.tsx CHANGED
@@ -5,10 +5,22 @@ import { StyleProps } from '@codecademy/variance';
5
5
  import styled from '@emotion/styled';
6
6
  import React, { useState } from 'react';
7
7
 
8
- import { helloWorld, languageOption } from './consts';
8
+ import { helloWorld, LanguageOption } from './consts';
9
9
  import { Editor } from './editor';
10
10
  import { LanguageSelection } from './languageSelection';
11
- import { CodeByteEditorProps } from './types';
11
+
12
+ type CodebytesChangeHandler = (text: string, language: LanguageOption) => void;
13
+
14
+ export interface CodeByteEditorProps {
15
+ text: string;
16
+ language: LanguageOption;
17
+ hideCopyButton: boolean;
18
+ onCopy?: CodebytesChangeHandler;
19
+ isIFrame?: boolean;
20
+ snippetsBaseUrl?: string;
21
+ onEdit?: CodebytesChangeHandler;
22
+ onLanguageChange?: CodebytesChangeHandler;
23
+ }
12
24
 
13
25
  const editorStates = states({
14
26
  isIFrame: { height: '100vh' },
@@ -37,11 +49,12 @@ export const CodeByteEditor: React.FC<CodeByteEditorProps> = ({
37
49
  language: initialLanguage,
38
50
  hideCopyButton,
39
51
  isIFrame = false,
40
- on,
41
52
  snippetsBaseUrl = process.env.CONTAINER_API_BASE,
53
+ onEdit,
54
+ onLanguageChange,
42
55
  }) => {
43
56
  const [text, setText] = useState<string>(initialText);
44
- const [language, setLanguage] = useState<languageOption>(initialLanguage);
57
+ const [language, setLanguage] = useState<LanguageOption>(initialLanguage);
45
58
  return (
46
59
  <EditorContainer bg="black" as="main" isIFrame={isIFrame}>
47
60
  <Box borderBottom={1} borderColor="gray-900" py={4} pl={8}>
@@ -52,7 +65,6 @@ export const CodeByteEditor: React.FC<CodeByteEditorProps> = ({
52
65
  target="_blank"
53
66
  rel="noreferrer"
54
67
  aria-label="visit codecademy.com"
55
- onClick={() => on?.logoClick?.()}
56
68
  />
57
69
  </Box>
58
70
  {language ? (
@@ -62,18 +74,18 @@ export const CodeByteEditor: React.FC<CodeByteEditorProps> = ({
62
74
  hideCopyButton={hideCopyButton}
63
75
  onChange={(newText: string) => {
64
76
  setText(newText);
65
- on?.edit?.(newText, language);
77
+ onEdit?.(newText, language);
66
78
  }}
67
- on={on}
68
79
  snippetsBaseUrl={snippetsBaseUrl}
69
80
  />
70
81
  ) : (
71
82
  <LanguageSelection
72
83
  onChange={(newLanguage) => {
73
- const newText: string = text || helloWorld[newLanguage] || '';
84
+ const newText: string =
85
+ text || (newLanguage ? helloWorld[newLanguage] : '');
74
86
  setLanguage(newLanguage);
75
87
  setText(newText);
76
- on?.languageChange?.(newText, newLanguage);
88
+ onLanguageChange?.(newText, newLanguage);
77
89
  }}
78
90
  />
79
91
  )}
@@ -1,45 +1,26 @@
1
- import { Select } from '@codecademy/gamut';
2
- import { Background } from '@codecademy/gamut-styles';
3
- import styled from '@emotion/styled';
1
+ import { Select, Text } from '@codecademy/gamut';
2
+ import { ColorMode } from '@codecademy/gamut-styles';
4
3
  import React from 'react';
5
4
 
6
- import type { languageOption } from './consts';
7
- import { languageOptions } from './consts';
8
-
9
- const StyledSelect = styled(Select)`
10
- margin-top: 1rem;
11
- color: ${({ theme }) => theme.colors.text};
12
- select {
13
- color: ${({ theme }) => theme.colors.text};
14
- background-color: ${({ theme }) => theme.colors.black};
15
-
16
- &:hover,
17
- &:active,
18
- &:focus {
19
- border-color: ${({ theme }) => theme.colors.primary};
20
- }
21
- &:focus {
22
- box-shadow: inset 0 0 0 1px ${({ theme }) => theme.colors.primary};
23
- }
24
- }
25
- `;
5
+ import type { LanguageOption } from './consts';
6
+ import { LanguageOptions } from './consts';
26
7
 
27
8
  export type LanguageSelectionProps = {
28
- onChange: (newLanguage: languageOption) => void;
9
+ onChange: (newLanguage: LanguageOption) => void;
29
10
  };
30
11
 
31
12
  export const LanguageSelection: React.FC<LanguageSelectionProps> = ({
32
13
  onChange,
33
14
  }) => {
34
15
  return (
35
- <Background bg="black" flex={1} px={16} pt={48}>
36
- Which language do you want to code in?
37
- <StyledSelect
16
+ <ColorMode mode="dark" flex={1} px={16} pt={48}>
17
+ <Text mb={16}>Which language do you want to code in?</Text>
18
+ <Select
38
19
  id="language-select"
39
20
  aria-label="Select a language"
40
- options={languageOptions}
41
- onChange={(e) => onChange(e.target.value as languageOption)}
21
+ options={LanguageOptions}
22
+ onChange={(e) => onChange(e.target.value as LanguageOption)}
42
23
  />
43
- </Background>
24
+ </ColorMode>
44
25
  );
45
26
  };
package/src/types.ts DELETED
@@ -1,20 +0,0 @@
1
- import { languageOption } from './consts';
2
-
3
- type CodebytesChangeHandler = (text: string, language: languageOption) => void;
4
-
5
- export type CodebytesChangeHandlerMap = {
6
- logoClick?: () => void;
7
- edit?: CodebytesChangeHandler;
8
- languageChange?: CodebytesChangeHandler;
9
- copy?: CodebytesChangeHandler;
10
- run?: () => void;
11
- };
12
-
13
- export interface CodeByteEditorProps {
14
- text: string;
15
- language: languageOption;
16
- hideCopyButton: boolean;
17
- isIFrame?: boolean;
18
- 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. */;
19
- on?: CodebytesChangeHandlerMap;
20
- }