@codecademy/codebytes 0.3.1-alpha.c03268.0 → 0.3.1-alpha.cef935.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 +2 -2
- package/src/editor.tsx +5 -5
- package/src/index.tsx +6 -17
- package/src/types.ts +20 -0
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.
|
|
6
|
+
### [0.3.1-alpha.cef935.0](https://github.com/Codecademy/client-modules/compare/@codecademy/codebytes@0.3.0...@codecademy/codebytes@0.3.1-alpha.cef935.0) (2022-01-13)
|
|
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.
|
|
4
|
+
"version": "0.3.1-alpha.cef935.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": "
|
|
51
|
+
"gitHead": "0f05e194904faae9337cdbd57e84382acc355a92"
|
|
52
52
|
}
|
package/src/editor.tsx
CHANGED
|
@@ -9,11 +9,11 @@ import { CopyIcon } from '@codecademy/gamut-icons';
|
|
|
9
9
|
import styled from '@emotion/styled';
|
|
10
10
|
import React, { useState } from 'react';
|
|
11
11
|
|
|
12
|
-
import { CodebytesChangeHandlerMap } from '.';
|
|
13
12
|
import { postSnippet } from './api';
|
|
14
13
|
import type { languageOption } from './consts';
|
|
15
14
|
import { Drawers } from './drawers';
|
|
16
15
|
import { SimpleMonacoEditor } from './MonacoEditor';
|
|
16
|
+
import { CodebytesChangeHandlerMap } from './types';
|
|
17
17
|
|
|
18
18
|
const Output = styled.pre<{ hasError: boolean }>`
|
|
19
19
|
width: 100%;
|
|
@@ -40,7 +40,7 @@ type EditorProps = {
|
|
|
40
40
|
language: languageOption;
|
|
41
41
|
text: string;
|
|
42
42
|
onChange: (text: string) => void;
|
|
43
|
-
|
|
43
|
+
on?: CodebytesChangeHandlerMap;
|
|
44
44
|
snippetsBaseUrl?: string;
|
|
45
45
|
};
|
|
46
46
|
|
|
@@ -48,7 +48,7 @@ export const Editor: React.FC<EditorProps> = ({
|
|
|
48
48
|
language,
|
|
49
49
|
text,
|
|
50
50
|
hideCopyButton,
|
|
51
|
-
|
|
51
|
+
on = {},
|
|
52
52
|
onChange,
|
|
53
53
|
snippetsBaseUrl,
|
|
54
54
|
}) => {
|
|
@@ -61,7 +61,7 @@ export const Editor: React.FC<EditorProps> = ({
|
|
|
61
61
|
.writeText(text)
|
|
62
62
|
// eslint-disable-next-line no-console
|
|
63
63
|
.catch(() => console.error('Failed to copy'));
|
|
64
|
-
|
|
64
|
+
on.copy?.(text, language);
|
|
65
65
|
setIsCodeByteCopied(true);
|
|
66
66
|
}
|
|
67
67
|
};
|
|
@@ -81,7 +81,7 @@ export const Editor: React.FC<EditorProps> = ({
|
|
|
81
81
|
};
|
|
82
82
|
setStatus('waiting');
|
|
83
83
|
setOutput('');
|
|
84
|
-
on
|
|
84
|
+
on.run?.();
|
|
85
85
|
|
|
86
86
|
try {
|
|
87
87
|
const response = await postSnippet(data, snippetsBaseUrl);
|
package/src/index.tsx
CHANGED
|
@@ -8,19 +8,7 @@ import React, { useState } from 'react';
|
|
|
8
8
|
import { helloWorld, languageOption } from './consts';
|
|
9
9
|
import { Editor } from './editor';
|
|
10
10
|
import { LanguageSelection } from './languageSelection';
|
|
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
|
-
}
|
|
11
|
+
import { CodeByteEditorProps } from './types';
|
|
24
12
|
|
|
25
13
|
const editorStates = states({
|
|
26
14
|
isIFrame: { height: '100vh' },
|
|
@@ -49,9 +37,8 @@ export const CodeByteEditor: React.FC<CodeByteEditorProps> = ({
|
|
|
49
37
|
language: initialLanguage,
|
|
50
38
|
hideCopyButton,
|
|
51
39
|
isIFrame = false,
|
|
40
|
+
on = {},
|
|
52
41
|
snippetsBaseUrl = process.env.CONTAINER_API_BASE,
|
|
53
|
-
onEdit,
|
|
54
|
-
onLanguageChange,
|
|
55
42
|
}) => {
|
|
56
43
|
const [text, setText] = useState<string>(initialText);
|
|
57
44
|
const [language, setLanguage] = useState<languageOption>(initialLanguage);
|
|
@@ -65,6 +52,7 @@ export const CodeByteEditor: React.FC<CodeByteEditorProps> = ({
|
|
|
65
52
|
target="_blank"
|
|
66
53
|
rel="noreferrer"
|
|
67
54
|
aria-label="visit codecademy.com"
|
|
55
|
+
onClick={() => on.logoClick?.()}
|
|
68
56
|
/>
|
|
69
57
|
</Box>
|
|
70
58
|
{language ? (
|
|
@@ -74,8 +62,9 @@ export const CodeByteEditor: React.FC<CodeByteEditorProps> = ({
|
|
|
74
62
|
hideCopyButton={hideCopyButton}
|
|
75
63
|
onChange={(newText: string) => {
|
|
76
64
|
setText(newText);
|
|
77
|
-
|
|
65
|
+
on.edit?.(newText, language);
|
|
78
66
|
}}
|
|
67
|
+
on={on}
|
|
79
68
|
snippetsBaseUrl={snippetsBaseUrl}
|
|
80
69
|
/>
|
|
81
70
|
) : (
|
|
@@ -84,7 +73,7 @@ export const CodeByteEditor: React.FC<CodeByteEditorProps> = ({
|
|
|
84
73
|
const newText: string = text || helloWorld[newLanguage] || '';
|
|
85
74
|
setLanguage(newLanguage);
|
|
86
75
|
setText(newText);
|
|
87
|
-
|
|
76
|
+
on.languageChange?.(newText, newLanguage);
|
|
88
77
|
}}
|
|
89
78
|
/>
|
|
90
79
|
)}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
}
|