@codecademy/codebytes 0.3.1-alpha.405be7.0 → 0.3.1-alpha.517237.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.405be7.0](https://github.com/Codecademy/client-modules/compare/@codecademy/codebytes@0.3.0...@codecademy/codebytes@0.3.1-alpha.405be7.0) (2022-01-13)
6
+ ### [0.3.1-alpha.517237.0](https://github.com/Codecademy/client-modules/compare/@codecademy/codebytes@0.3.0...@codecademy/codebytes@0.3.1-alpha.517237.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.405be7.0",
4
+ "version": "0.3.1-alpha.517237.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": "b0c7c52677bf95764fd29e9baa58a30761858f85"
51
+ "gitHead": "131b6bdaa97ebeffada14dc527bce7a9eb2db787"
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() {
package/src/editor.tsx CHANGED
@@ -10,7 +10,7 @@ import styled from '@emotion/styled';
10
10
  import React, { useState } from 'react';
11
11
 
12
12
  import { postSnippet } from './api';
13
- import type { languageOption } from './consts';
13
+ import type { LanguageOption } from './consts';
14
14
  import { Drawers } from './drawers';
15
15
  import { SimpleMonacoEditor } from './MonacoEditor';
16
16
 
@@ -36,7 +36,7 @@ const DOCKER_SIGTERM = 143;
36
36
 
37
37
  type EditorProps = {
38
38
  hideCopyButton: boolean;
39
- language: languageOption;
39
+ language: LanguageOption;
40
40
  text: string;
41
41
  onChange: (text: string) => void;
42
42
  onCopy?: (text: string, language: string) => void;
package/src/index.tsx CHANGED
@@ -5,15 +5,15 @@ 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
11
 
12
- type CodebytesChangeHandler = (text: string, language: languageOption) => void;
12
+ type CodebytesChangeHandler = (text: string, language: LanguageOption) => void;
13
13
 
14
14
  export interface CodeByteEditorProps {
15
15
  text: string;
16
- language: languageOption;
16
+ language: LanguageOption;
17
17
  hideCopyButton: boolean;
18
18
  onCopy?: CodebytesChangeHandler;
19
19
  isIFrame?: boolean;
@@ -54,7 +54,7 @@ export const CodeByteEditor: React.FC<CodeByteEditorProps> = ({
54
54
  onLanguageChange,
55
55
  }) => {
56
56
  const [text, setText] = useState<string>(initialText);
57
- const [language, setLanguage] = useState<languageOption>(initialLanguage);
57
+ const [language, setLanguage] = useState<LanguageOption>(initialLanguage);
58
58
  return (
59
59
  <EditorContainer bg="black" as="main" isIFrame={isIFrame}>
60
60
  <Box borderBottom={1} borderColor="gray-900" py={4} pl={8}>
@@ -81,7 +81,8 @@ export const CodeByteEditor: React.FC<CodeByteEditorProps> = ({
81
81
  ) : (
82
82
  <LanguageSelection
83
83
  onChange={(newLanguage) => {
84
- const newText: string = text || helloWorld[newLanguage] || '';
84
+ const newText: string =
85
+ text || (newLanguage ? helloWorld[newLanguage] : '');
85
86
  setLanguage(newLanguage);
86
87
  setText(newText);
87
88
  onLanguageChange?.(newText, newLanguage);
@@ -2,11 +2,11 @@ import { Select, Text } from '@codecademy/gamut';
2
2
  import { ColorMode } from '@codecademy/gamut-styles';
3
3
  import React from 'react';
4
4
 
5
- import type { languageOption } from './consts';
6
- import { languageOptions } from './consts';
5
+ import type { LanguageOption } from './consts';
6
+ import { LanguageOptions } from './consts';
7
7
 
8
8
  export type LanguageSelectionProps = {
9
- onChange: (newLanguage: languageOption) => void;
9
+ onChange: (newLanguage: LanguageOption) => void;
10
10
  };
11
11
 
12
12
  export const LanguageSelection: React.FC<LanguageSelectionProps> = ({
@@ -18,8 +18,8 @@ export const LanguageSelection: React.FC<LanguageSelectionProps> = ({
18
18
  <Select
19
19
  id="language-select"
20
20
  aria-label="Select a language"
21
- options={languageOptions}
22
- onChange={(e) => onChange(e.target.value as languageOption)}
21
+ options={LanguageOptions}
22
+ onChange={(e) => onChange(e.target.value as LanguageOption)}
23
23
  />
24
24
  </ColorMode>
25
25
  );