docusaurus-live-brython 3.0.0-beta.9 → 3.0.1
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/.devcontainer/devcontainer.json +38 -0
- package/.prettierignore +17 -0
- package/.prettierrc +9 -8
- package/CHANGELOG.md +5 -0
- package/README.md +7 -4
- package/lib/assets/py_back_trace.py +2 -1
- package/lib/index.d.ts +1 -7
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +94 -16
- package/lib/options.d.ts +1 -0
- package/lib/options.d.ts.map +1 -0
- package/lib/options.js +2 -2
- package/lib/theme/CodeBlock/index.d.ts +3 -3
- package/lib/theme/CodeBlock/index.d.ts.map +1 -0
- package/lib/theme/CodeBlock/index.jsx +24 -14
- package/lib/theme/CodeEditor/Actions/DownloadCode.d.ts +1 -0
- package/lib/theme/CodeEditor/Actions/DownloadCode.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Actions/DownloadCode.jsx +8 -8
- package/lib/theme/CodeEditor/Actions/Reset.d.ts +1 -0
- package/lib/theme/CodeEditor/Actions/Reset.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Actions/Reset.jsx +5 -5
- package/lib/theme/CodeEditor/Actions/RunCode.d.ts +2 -1
- package/lib/theme/CodeEditor/Actions/RunCode.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Actions/RunCode.jsx +4 -4
- package/lib/theme/CodeEditor/Actions/ShowRaw.d.ts +1 -0
- package/lib/theme/CodeEditor/Actions/ShowRaw.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Actions/ShowRaw.jsx +13 -7
- package/lib/theme/CodeEditor/Actions/ShowSyncStatus.d.ts +1 -0
- package/lib/theme/CodeEditor/Actions/ShowSyncStatus.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Actions/ShowSyncStatus.jsx +21 -16
- package/lib/theme/CodeEditor/Actions/styles.module.css +2 -3
- package/lib/theme/CodeEditor/BrythonCommunicator.d.ts +2 -1
- package/lib/theme/CodeEditor/BrythonCommunicator.d.ts.map +1 -0
- package/lib/theme/CodeEditor/BrythonCommunicator.jsx +13 -9
- package/lib/theme/CodeEditor/Button/index.d.ts +3 -2
- package/lib/theme/CodeEditor/Button/index.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Button/index.jsx +1 -1
- package/lib/theme/CodeEditor/Button/styles.module.css +1 -1
- package/lib/theme/CodeEditor/CodeHistory/index.d.ts +1 -0
- package/lib/theme/CodeEditor/CodeHistory/index.d.ts.map +1 -0
- package/lib/theme/CodeEditor/CodeHistory/index.jsx +26 -15
- package/lib/theme/CodeEditor/CodeHistory/styles.module.css +31 -31
- package/lib/theme/CodeEditor/ContextEditor/index.d.ts +22 -0
- package/lib/theme/CodeEditor/ContextEditor/index.d.ts.map +1 -0
- package/lib/theme/CodeEditor/ContextEditor/index.jsx +36 -0
- package/lib/theme/CodeEditor/Editor/EditorAce.d.ts +2 -1
- package/lib/theme/CodeEditor/Editor/EditorAce.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Editor/EditorAce.jsx +17 -14
- package/lib/theme/CodeEditor/Editor/Header/index.d.ts +2 -1
- package/lib/theme/CodeEditor/Editor/Header/index.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Editor/Header/index.jsx +12 -12
- package/lib/theme/CodeEditor/Editor/Header/styles.module.css +7 -7
- package/lib/theme/CodeEditor/Editor/HiddenCode/index.d.ts +8 -0
- package/lib/theme/CodeEditor/Editor/HiddenCode/index.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Editor/HiddenCode/index.jsx +27 -0
- package/lib/theme/CodeEditor/Editor/HiddenCode/styles.module.css +52 -0
- package/lib/theme/CodeEditor/Editor/Result/Graphics/Canvas.d.ts +1 -0
- package/lib/theme/CodeEditor/Editor/Result/Graphics/Canvas.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Editor/Result/Graphics/Canvas.jsx +8 -9
- package/lib/theme/CodeEditor/Editor/Result/Graphics/Turtle.d.ts +1 -0
- package/lib/theme/CodeEditor/Editor/Result/Graphics/Turtle.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Editor/Result/Graphics/Turtle.jsx +11 -11
- package/lib/theme/CodeEditor/Editor/Result/Graphics/index.d.ts +4 -3
- package/lib/theme/CodeEditor/Editor/Result/Graphics/index.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Editor/Result/Graphics/index.jsx +12 -10
- package/lib/theme/CodeEditor/Editor/Result/Graphics/styles.module.css +2 -2
- package/lib/theme/CodeEditor/Editor/Result/index.d.ts +2 -3
- package/lib/theme/CodeEditor/Editor/Result/index.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Editor/Result/index.jsx +6 -9
- package/lib/theme/CodeEditor/Editor/Result/styles.module.css +15 -10
- package/lib/theme/CodeEditor/Editor/index.d.ts +6 -3
- package/lib/theme/CodeEditor/Editor/index.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Editor/index.jsx +34 -28
- package/lib/theme/CodeEditor/Editor/styles.module.css +15 -7
- package/lib/theme/CodeEditor/Editor/utils/checkForButtonClick.d.ts +1 -0
- package/lib/theme/CodeEditor/Editor/utils/checkForButtonClick.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Editor/utils/saveSvg.d.ts +1 -0
- package/lib/theme/CodeEditor/Editor/utils/saveSvg.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Editor/utils/saveSvg.js +19 -8
- package/lib/theme/CodeEditor/Editor/utils/svgWithoutAnimations.d.ts +1 -0
- package/lib/theme/CodeEditor/Editor/utils/svgWithoutAnimations.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Editor/utils/svgWithoutAnimations.js +43 -49
- package/lib/theme/CodeEditor/Icon/icons.d.ts +4 -1
- package/lib/theme/CodeEditor/Icon/icons.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Icon/icons.js +3 -1
- package/lib/theme/CodeEditor/Icon/index.d.ts +4 -2
- package/lib/theme/CodeEditor/Icon/index.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Icon/index.jsx +10 -3
- package/lib/theme/CodeEditor/Icon/styles.module.css +1 -1
- package/lib/theme/CodeEditor/WithScript/ScriptContext.d.ts +8 -0
- package/lib/theme/CodeEditor/WithScript/ScriptContext.d.ts.map +1 -0
- package/lib/theme/CodeEditor/WithScript/ScriptContext.jsx +27 -0
- package/lib/theme/CodeEditor/WithScript/Storage.d.ts +2 -1
- package/lib/theme/CodeEditor/WithScript/Storage.d.ts.map +1 -0
- package/lib/theme/CodeEditor/WithScript/Types.d.ts +12 -4
- package/lib/theme/CodeEditor/WithScript/Types.d.ts.map +1 -0
- package/lib/theme/CodeEditor/WithScript/bryRunner.d.ts +3 -0
- package/lib/theme/CodeEditor/WithScript/bryRunner.d.ts.map +1 -0
- package/lib/theme/CodeEditor/WithScript/bryRunner.js +29 -0
- package/lib/theme/CodeEditor/WithScript/createStore.d.ts +4 -0
- package/lib/theme/CodeEditor/WithScript/createStore.d.ts.map +1 -0
- package/lib/theme/CodeEditor/WithScript/{Store.jsx → createStore.js} +62 -74
- package/lib/theme/CodeEditor/WithScript/helpers.d.ts +1 -4
- package/lib/theme/CodeEditor/WithScript/helpers.d.ts.map +1 -0
- package/lib/theme/CodeEditor/WithScript/helpers.js +4 -14
- package/lib/theme/CodeEditor/constants.d.ts +1 -0
- package/lib/theme/CodeEditor/constants.d.ts.map +1 -0
- package/lib/theme/CodeEditor/hooks/index.d.ts +3 -0
- package/lib/theme/CodeEditor/hooks/index.d.ts.map +1 -0
- package/lib/theme/CodeEditor/hooks/index.js +2 -0
- package/lib/theme/CodeEditor/hooks/useScript.d.ts +3 -0
- package/lib/theme/CodeEditor/hooks/useScript.d.ts.map +1 -0
- package/lib/theme/CodeEditor/hooks/useScript.js +4 -0
- package/lib/theme/CodeEditor/hooks/useStore.d.ts +3 -0
- package/lib/theme/CodeEditor/hooks/useStore.d.ts.map +1 -0
- package/lib/theme/CodeEditor/hooks/useStore.js +10 -0
- package/lib/theme/CodeEditor/index.d.ts +24 -5
- package/lib/theme/CodeEditor/index.d.ts.map +1 -0
- package/lib/theme/CodeEditor/index.jsx +17 -16
- package/lib/theme/CodeEditor/styles.module.css +28 -30
- package/og-image.md +23 -0
- package/package.json +35 -20
- package/src/assets/py_back_trace.py +2 -1
- package/src/index.ts +96 -25
- package/src/options.ts +12 -12
- package/src/theme/CodeBlock/index.tsx +44 -68
- package/src/theme/CodeEditor/Actions/DownloadCode.tsx +23 -22
- package/src/theme/CodeEditor/Actions/Reset.tsx +14 -12
- package/src/theme/CodeEditor/Actions/RunCode.tsx +14 -11
- package/src/theme/CodeEditor/Actions/ShowRaw.tsx +17 -11
- package/src/theme/CodeEditor/Actions/ShowSyncStatus.tsx +32 -27
- package/src/theme/CodeEditor/Actions/styles.module.css +2 -3
- package/src/theme/CodeEditor/BrythonCommunicator.tsx +16 -19
- package/src/theme/CodeEditor/Button/index.tsx +17 -13
- package/src/theme/CodeEditor/Button/styles.module.css +1 -1
- package/src/theme/CodeEditor/CodeHistory/index.tsx +32 -20
- package/src/theme/CodeEditor/CodeHistory/styles.module.css +31 -31
- package/src/theme/CodeEditor/ContextEditor/index.tsx +74 -0
- package/src/theme/CodeEditor/Editor/EditorAce.tsx +20 -16
- package/src/theme/CodeEditor/Editor/Header/index.tsx +13 -19
- package/src/theme/CodeEditor/Editor/Header/styles.module.css +7 -7
- package/src/theme/CodeEditor/Editor/HiddenCode/index.tsx +49 -0
- package/src/theme/CodeEditor/Editor/HiddenCode/styles.module.css +52 -0
- package/src/theme/CodeEditor/Editor/Result/Graphics/Canvas.tsx +25 -22
- package/src/theme/CodeEditor/Editor/Result/Graphics/Turtle.tsx +23 -19
- package/src/theme/CodeEditor/Editor/Result/Graphics/index.tsx +16 -16
- package/src/theme/CodeEditor/Editor/Result/Graphics/styles.module.css +2 -2
- package/src/theme/CodeEditor/Editor/Result/index.tsx +7 -13
- package/src/theme/CodeEditor/Editor/Result/styles.module.css +15 -10
- package/src/theme/CodeEditor/Editor/index.tsx +67 -65
- package/src/theme/CodeEditor/Editor/styles.module.css +15 -7
- package/src/theme/CodeEditor/Editor/utils/checkForButtonClick.ts +5 -5
- package/src/theme/CodeEditor/Editor/utils/saveSvg.ts +63 -53
- package/src/theme/CodeEditor/Editor/utils/svgWithoutAnimations.ts +182 -201
- package/src/theme/CodeEditor/Icon/icons.ts +27 -13
- package/src/theme/CodeEditor/Icon/index.tsx +31 -11
- package/src/theme/CodeEditor/Icon/styles.module.css +1 -1
- package/src/theme/CodeEditor/WithScript/ScriptContext.tsx +36 -0
- package/src/theme/CodeEditor/WithScript/Storage.ts +3 -3
- package/src/theme/CodeEditor/WithScript/Types.ts +17 -11
- package/src/theme/CodeEditor/WithScript/bryRunner.ts +39 -0
- package/src/theme/CodeEditor/WithScript/createStore.ts +276 -0
- package/src/theme/CodeEditor/WithScript/helpers.ts +16 -26
- package/src/theme/CodeEditor/constants.ts +9 -11
- package/src/theme/CodeEditor/hooks/index.ts +2 -0
- package/src/theme/CodeEditor/hooks/useScript.ts +9 -0
- package/src/theme/CodeEditor/hooks/useStore.ts +15 -0
- package/src/theme/CodeEditor/index.tsx +45 -31
- package/src/theme/CodeEditor/styles.module.css +28 -30
- package/src/typings.d.ts +11 -0
- package/lib/theme/CodeEditor/WithScript/Store.d.ts +0 -15
- package/lib/types.d.ts +0 -28
- package/lib/types.js +0 -1
- package/src/theme/CodeEditor/WithScript/Store.tsx +0 -294
- package/src/types.ts +0 -29
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { DOM_ELEMENT_IDS } from '
|
|
3
|
-
import Graphics from '
|
|
2
|
+
import { DOM_ELEMENT_IDS } from '@theme/CodeEditor/constants';
|
|
3
|
+
import Graphics from '@theme/CodeEditor/Editor/Result/Graphics';
|
|
4
4
|
import styles from './styles.module.css';
|
|
5
|
-
import {
|
|
6
|
-
import Button from '
|
|
5
|
+
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
6
|
+
import Button from '@theme/CodeEditor/Button';
|
|
7
7
|
const downloadCanvas = (canvasId) => {
|
|
8
8
|
const canvas = document.getElementById(canvasId);
|
|
9
9
|
if (!canvas) {
|
|
@@ -14,7 +14,7 @@ const downloadCanvas = (canvasId) => {
|
|
|
14
14
|
dt = dt.replace(/^data:image\/[^;]*/, 'data:application/octet-stream');
|
|
15
15
|
/* In addition to <a>'s "download" attribute, you can define HTTP-style headers */
|
|
16
16
|
dt = dt.replace(/^data:application\/octet-stream/, 'data:application/octet-stream;headers=Content-Disposition%3A%20attachment%3B%20filename=Canvas.png');
|
|
17
|
-
var downloadLink = document.createElement(
|
|
17
|
+
var downloadLink = document.createElement('a');
|
|
18
18
|
downloadLink.href = dt;
|
|
19
19
|
downloadLink.download = `${canvasId}.png`;
|
|
20
20
|
document.body.appendChild(downloadLink);
|
|
@@ -22,10 +22,9 @@ const downloadCanvas = (canvasId) => {
|
|
|
22
22
|
document.body.removeChild(downloadLink);
|
|
23
23
|
};
|
|
24
24
|
const Canvas = () => {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return (<Graphics controls={<Button icon='Download' iconSize='12px' onClick={() => {
|
|
25
|
+
const store = useStore();
|
|
26
|
+
const codeId = useScript(store, 'codeId');
|
|
27
|
+
return (<Graphics controls={<Button icon="Download" iconSize="12px" onClick={() => {
|
|
29
28
|
downloadCanvas(DOM_ELEMENT_IDS.canvasContainer(codeId));
|
|
30
29
|
}} title="Download SVG" className={styles.slimStrippedButton}/>} main={<canvas id={DOM_ELEMENT_IDS.canvasContainer(codeId)} width="500" height="500" style={{
|
|
31
30
|
display: 'block',
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Turtle.d.ts","sourceRoot":"","sources":["../../../../../../src/theme/CodeEditor/Editor/Result/Graphics/Turtle.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAS/B,QAAA,MAAM,MAAM,yBAwCX,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import styles from './styles.module.css';
|
|
3
|
-
import { DOM_ELEMENT_IDS } from '
|
|
4
|
-
import Graphics from '
|
|
5
|
-
import { saveSvg } from '
|
|
6
|
-
import {
|
|
7
|
-
import Button from '
|
|
3
|
+
import { DOM_ELEMENT_IDS } from '@theme/CodeEditor/constants';
|
|
4
|
+
import Graphics from '@theme/CodeEditor/Editor/Result/Graphics';
|
|
5
|
+
import { saveSvg } from '@theme/CodeEditor/Editor/utils/saveSvg';
|
|
6
|
+
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
7
|
+
import Button from '@theme/CodeEditor/Button';
|
|
8
8
|
import clsx from 'clsx';
|
|
9
9
|
const Turtle = () => {
|
|
10
|
-
const
|
|
11
|
-
const codeId =
|
|
12
|
-
const code =
|
|
10
|
+
const store = useStore();
|
|
11
|
+
const codeId = useScript(store, 'codeId');
|
|
12
|
+
const code = useScript(store, 'code');
|
|
13
13
|
return (<Graphics controls={<React.Fragment>
|
|
14
|
-
<Button icon=
|
|
14
|
+
<Button icon="AnimationPlay" onClick={() => {
|
|
15
15
|
const turtleResult = document.getElementById(DOM_ELEMENT_IDS.turtleSvgContainer(codeId));
|
|
16
16
|
if (turtleResult) {
|
|
17
17
|
saveSvg(turtleResult, `${codeId}`, code, true);
|
|
18
18
|
}
|
|
19
|
-
}} className={clsx(styles.slimStrippedButton)} iconSize=
|
|
20
|
-
<Button icon=
|
|
19
|
+
}} className={clsx(styles.slimStrippedButton)} iconSize="12px" title="Download Animated SVG"/>
|
|
20
|
+
<Button icon="Download" iconSize="12px" onClick={() => {
|
|
21
21
|
const turtleResult = document.getElementById(DOM_ELEMENT_IDS.turtleSvgContainer(codeId));
|
|
22
22
|
if (turtleResult) {
|
|
23
23
|
saveSvg(turtleResult, `${codeId}`, code);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
interface Props {
|
|
3
|
-
controls?:
|
|
4
|
-
main?:
|
|
2
|
+
export interface Props {
|
|
3
|
+
controls?: React.ReactNode;
|
|
4
|
+
main?: React.ReactNode;
|
|
5
5
|
}
|
|
6
6
|
declare const Graphics: (props: Props) => React.JSX.Element;
|
|
7
7
|
export default Graphics;
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/theme/CodeEditor/Editor/Result/Graphics/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAQ/B,MAAM,WAAW,KAAK;IAClB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC1B;AACD,QAAA,MAAM,QAAQ,GAAI,OAAO,KAAK,sBAgC7B,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import styles from './styles.module.css';
|
|
3
|
-
import { DOM_ELEMENT_IDS } from '
|
|
3
|
+
import { DOM_ELEMENT_IDS } from '@theme/CodeEditor/constants';
|
|
4
4
|
import Draggable from 'react-draggable';
|
|
5
|
-
import { checkForButtonClick } from '
|
|
6
|
-
import {
|
|
7
|
-
import Button from '
|
|
5
|
+
import { checkForButtonClick } from '@theme/CodeEditor/Editor/utils/checkForButtonClick';
|
|
6
|
+
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
7
|
+
import Button from '@theme/CodeEditor/Button';
|
|
8
8
|
import clsx from 'clsx';
|
|
9
9
|
const Graphics = (props) => {
|
|
10
|
-
const
|
|
11
|
-
const codeId =
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const store = useStore();
|
|
11
|
+
const codeId = useScript(store, 'codeId');
|
|
12
|
+
const graphicsModalExecutionNr = useScript(store, 'graphicsModalExecutionNr');
|
|
13
|
+
const nodeRef = React.useRef(null);
|
|
14
|
+
return (<Draggable onStop={checkForButtonClick} positionOffset={{ x: '15%', y: '25%' }} nodeRef={nodeRef}>
|
|
15
|
+
<div className={styles.brythonGraphicsResult} ref={nodeRef}>
|
|
14
16
|
<div className={styles.brythonGraphicsResultHead}>
|
|
15
17
|
<span>Output</span>
|
|
16
18
|
<span className={styles.spacer}></span>
|
|
@@ -18,9 +20,9 @@ const Graphics = (props) => {
|
|
|
18
20
|
<Button icon="Close" className={clsx(styles.closeButton)} onClick={() => {
|
|
19
21
|
store.stopScript();
|
|
20
22
|
store.closeGraphicsModal();
|
|
21
|
-
}} iconSize=
|
|
23
|
+
}} iconSize="12px"/>
|
|
22
24
|
</div>
|
|
23
|
-
<div id={DOM_ELEMENT_IDS.graphicsResult(codeId)} className="brython-graphics-result">
|
|
25
|
+
<div id={DOM_ELEMENT_IDS.graphicsResult(codeId)} className="brython-graphics-result" key={`exec-${graphicsModalExecutionNr}`}>
|
|
24
26
|
{props.main}
|
|
25
27
|
</div>
|
|
26
28
|
</div>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/theme/CodeEditor/Editor/Result/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAK/B,QAAA,MAAM,MAAM,yBAqBX,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import styles from './styles.module.css';
|
|
3
|
-
// @ts-ignore
|
|
4
3
|
import CodeBlock from '@theme/CodeBlock';
|
|
5
|
-
import {
|
|
6
|
-
const Result = (
|
|
7
|
-
const
|
|
8
|
-
const logs =
|
|
4
|
+
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
5
|
+
const Result = () => {
|
|
6
|
+
const store = useStore();
|
|
7
|
+
const logs = useScript(store, 'logs');
|
|
9
8
|
if (logs.length === 0) {
|
|
10
9
|
return null;
|
|
11
10
|
}
|
|
12
11
|
const errors = [];
|
|
13
12
|
let lineNr = 1;
|
|
14
|
-
const code = logs.map((msg) => {
|
|
13
|
+
const code = logs.slice().map((msg) => {
|
|
15
14
|
const msgLen = (msg.output || '').split('\n').length - 1;
|
|
16
15
|
if (msg.type === 'stderr') {
|
|
17
16
|
errors.push(`${lineNr}-${lineNr + msgLen}`);
|
|
@@ -20,9 +19,7 @@ const Result = (props) => {
|
|
|
20
19
|
return msg.output;
|
|
21
20
|
});
|
|
22
21
|
return (<div className={styles.result}>
|
|
23
|
-
<CodeBlock metastring={`{${errors.join(',')}}`}>
|
|
24
|
-
{code.join('')}
|
|
25
|
-
</CodeBlock>
|
|
22
|
+
<CodeBlock metastring={`{${errors.join(',')}}`}>{code.join('')}</CodeBlock>
|
|
26
23
|
</div>);
|
|
27
24
|
};
|
|
28
25
|
export default Result;
|
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
.result {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
grid-area: result;
|
|
3
|
+
max-width: 100%;
|
|
4
|
+
overflow-x: auto;
|
|
5
5
|
--ifm-leading: 0;
|
|
6
6
|
flex-grow: 1;
|
|
7
7
|
flex-basis: 80ch;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
.result>pre {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
.result > pre {
|
|
11
|
+
margin-bottom: 0px;
|
|
12
|
+
border-top-left-radius: 0;
|
|
13
|
+
border-top-right-radius: 0;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
.result :global(.theme-code-block-highlighted-line) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
17
|
+
color: var(--ifm-color-danger-darker) !important;
|
|
18
|
+
background: transparent;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.result pre {
|
|
22
|
+
border-top-left-radius: 0;
|
|
23
|
+
border-top-right-radius: 0;
|
|
24
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
interface Props {
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export interface Props {
|
|
3
3
|
slim: boolean;
|
|
4
4
|
title: string;
|
|
5
5
|
resettable: boolean;
|
|
@@ -7,9 +7,12 @@ interface Props {
|
|
|
7
7
|
download: boolean;
|
|
8
8
|
lang: string;
|
|
9
9
|
noCompare: boolean;
|
|
10
|
-
|
|
10
|
+
preCode: string;
|
|
11
|
+
postCode: string;
|
|
11
12
|
maxLines?: number;
|
|
12
13
|
versioned?: boolean;
|
|
14
|
+
onChange?: (code: string) => void;
|
|
13
15
|
}
|
|
14
16
|
declare const Editor: (props: Props) => React.JSX.Element;
|
|
15
17
|
export default Editor;
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/theme/CodeEditor/Editor/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAa/B,MAAM,WAAW,KAAK;IAClB,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,OAAO,CAAC;IACpB,eAAe,EAAE,OAAO,CAAC;IACzB,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACrC;AAED,QAAA,MAAM,MAAM,GAAI,OAAO,KAAK,sBA0C3B,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
|
@@ -1,32 +1,38 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import { DOM_ELEMENT_IDS
|
|
3
|
-
import {
|
|
4
|
-
import Result from
|
|
5
|
-
import Turtle from
|
|
6
|
-
import Canvas from
|
|
7
|
-
import Graphics from
|
|
8
|
-
import Header from
|
|
9
|
-
import EditorAce from
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { DOM_ELEMENT_IDS } from '@theme/CodeEditor/constants';
|
|
3
|
+
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
4
|
+
import Result from '@theme/CodeEditor/Editor/Result';
|
|
5
|
+
import Turtle from '@theme/CodeEditor/Editor/Result/Graphics/Turtle';
|
|
6
|
+
import Canvas from '@theme/CodeEditor/Editor/Result/Graphics/Canvas';
|
|
7
|
+
import Graphics from '@theme/CodeEditor/Editor/Result/Graphics';
|
|
8
|
+
import Header from '@theme/CodeEditor/Editor/Header';
|
|
9
|
+
import EditorAce from '@theme/CodeEditor/Editor/EditorAce';
|
|
10
|
+
import clsx from 'clsx';
|
|
11
|
+
import styles from './styles.module.css';
|
|
12
|
+
import HiddenCode from '@theme/CodeEditor/Editor/HiddenCode';
|
|
10
13
|
const Editor = (props) => {
|
|
11
|
-
const
|
|
12
|
-
const lang =
|
|
13
|
-
const codeId =
|
|
14
|
-
const hasCanvasOutput =
|
|
15
|
-
const hasTurtleOutput =
|
|
16
|
-
const
|
|
14
|
+
const store = useStore();
|
|
15
|
+
const lang = useScript(store, 'lang');
|
|
16
|
+
const codeId = useScript(store, 'codeId');
|
|
17
|
+
const hasCanvasOutput = useScript(store, 'hasCanvasOutput');
|
|
18
|
+
const hasTurtleOutput = useScript(store, 'hasTurtleOutput');
|
|
19
|
+
const graphicsModalExecutionNr = useScript(store, 'graphicsModalExecutionNr');
|
|
17
20
|
return (<React.Fragment>
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
<Header slim={props.slim} title={props.title} resettable={props.resettable} download={props.download} noCompare={props.noCompare}/>
|
|
22
|
+
<div className={clsx(styles.editorContainer)}>
|
|
23
|
+
<HiddenCode type="pre" code={props.preCode}/>
|
|
24
|
+
<EditorAce showLineNumbers={props.showLineNumbers} maxLines={props.maxLines} versioned={props.versioned} onChange={props.onChange}/>
|
|
25
|
+
<HiddenCode type="post" code={props.postCode}/>
|
|
26
|
+
</div>
|
|
27
|
+
{lang === 'python' && (<>
|
|
28
|
+
<Result />
|
|
29
|
+
<div id={DOM_ELEMENT_IDS.outputDiv(codeId)}></div>
|
|
30
|
+
{graphicsModalExecutionNr > 0 && (<>
|
|
31
|
+
{hasTurtleOutput && <Turtle />}
|
|
32
|
+
{hasCanvasOutput && <Canvas />}
|
|
33
|
+
{!hasCanvasOutput && !hasTurtleOutput && <Graphics />}
|
|
34
|
+
</>)}
|
|
35
|
+
</>)}
|
|
36
|
+
</React.Fragment>);
|
|
31
37
|
};
|
|
32
38
|
export default Editor;
|
|
@@ -1,20 +1,28 @@
|
|
|
1
|
+
.editorContainer {
|
|
2
|
+
grid-area: editor;
|
|
3
|
+
position: relative;
|
|
4
|
+
--show-hidden-code-toggle-opacity: 0;
|
|
5
|
+
}
|
|
1
6
|
.editor {
|
|
2
|
-
grid-area: editor;
|
|
3
7
|
display: flex;
|
|
4
8
|
flex-wrap: wrap;
|
|
5
9
|
}
|
|
6
10
|
|
|
7
11
|
.editor .noGutter :global(.ace_scroller) {
|
|
8
|
-
|
|
12
|
+
left: 4px !important;
|
|
9
13
|
}
|
|
10
14
|
|
|
11
15
|
.editor :global(.ace_scrollbar.ace_scrollbar-h) {
|
|
12
|
-
|
|
16
|
+
overflow-x: hidden !important;
|
|
13
17
|
}
|
|
14
18
|
|
|
15
19
|
.brythonEditor {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
flex-grow: 1;
|
|
21
|
+
flex-basis: 80ch;
|
|
22
|
+
/*rtl:ignore*/
|
|
23
|
+
direction: ltr;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.editorContainer:hover {
|
|
27
|
+
--show-hidden-code-toggle-opacity: 1;
|
|
20
28
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkForButtonClick.d.ts","sourceRoot":"","sources":["../../../../../src/theme/CodeEditor/Editor/utils/checkForButtonClick.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD;;;;GAIG;AACH,QAAA,MAAM,mBAAmB,GAAI,OAAO,cAAc,SAwBjD,CAAC;AAEF,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"saveSvg.d.ts","sourceRoot":"","sources":["../../../../../src/theme/CodeEditor/Editor/utils/saveSvg.ts"],"names":[],"mappings":"AAYA,QAAA,MAAM,OAAO,GAAI,OAAO,aAAa,EAAE,MAAM,MAAM,EAAE,OAAO,MAAM,EAAE,WAAW,OAAO,SAyErF,CAAC;AAEF,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { removeAnimations } from
|
|
1
|
+
import { removeAnimations } from '@theme/CodeEditor/Editor/utils/svgWithoutAnimations';
|
|
2
2
|
const duration = (anim) => {
|
|
3
3
|
const dur = anim.getAttribute('dur') || '';
|
|
4
4
|
if (/ms$/.test(dur)) {
|
|
@@ -10,7 +10,7 @@ const duration = (anim) => {
|
|
|
10
10
|
return 0;
|
|
11
11
|
};
|
|
12
12
|
const saveSvg = (svgEl, name, code, animated) => {
|
|
13
|
-
svgEl.setAttribute(
|
|
13
|
+
svgEl.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
|
|
14
14
|
const bbox = svgEl.getBBox();
|
|
15
15
|
const svgProps = {
|
|
16
16
|
viewBox: `${bbox.x - 5},${bbox.y - 5},${bbox.width + 10},${bbox.height + 10}`,
|
|
@@ -25,12 +25,16 @@ const saveSvg = (svgEl, name, code, animated) => {
|
|
|
25
25
|
if (animated || window.__KEEP_TURTLE_ANIMATIONS__) {
|
|
26
26
|
const saveSvg = svgEl.cloneNode(true);
|
|
27
27
|
const anims = saveSvg.querySelectorAll('animate');
|
|
28
|
-
const frameIds = Array.from(anims)
|
|
28
|
+
const frameIds = Array.from(anims)
|
|
29
|
+
.map((n) => (n.id.match(/\d+/) || [])[0])
|
|
30
|
+
.filter((nr) => nr)
|
|
31
|
+
.map((nr) => Number.parseInt(nr))
|
|
32
|
+
.sort((a, b) => (a > b ? 1 : -1));
|
|
29
33
|
if (frameIds.length > 0) {
|
|
30
34
|
const lastAnim = frameIds[frameIds.length - 1];
|
|
31
35
|
const firstAnim = saveSvg.getElementById('animation_frame0');
|
|
32
36
|
if (firstAnim) {
|
|
33
|
-
const looper = document.createElement(
|
|
37
|
+
const looper = document.createElement('rect');
|
|
34
38
|
looper.innerHTML = ` <rect><animate id="looper_animation" begin="0;animation_frame${lastAnim}.end" dur="1ms" attributeName="visibility" from="hide" to="hide"/></rect>`;
|
|
35
39
|
firstAnim.parentElement.insertBefore(looper, firstAnim);
|
|
36
40
|
firstAnim.setAttribute('begin', 'looper_animation.end');
|
|
@@ -47,7 +51,9 @@ const saveSvg = (svgEl, name, code, animated) => {
|
|
|
47
51
|
saveSvg.setAttribute('height', `${svgProps.height}`);
|
|
48
52
|
saveSvg.setAttribute('width', `${svgProps.width}`);
|
|
49
53
|
wrapper.innerHTML = `${preface}\r\n${saveSvg.outerHTML}`;
|
|
50
|
-
animDuration = Array.from(saveSvg.querySelectorAll('animate'))
|
|
54
|
+
animDuration = Array.from(saveSvg.querySelectorAll('animate'))
|
|
55
|
+
.map(duration)
|
|
56
|
+
.reduce((d, c) => d + c, 0);
|
|
51
57
|
}
|
|
52
58
|
else {
|
|
53
59
|
const svgWithoutAnim = removeAnimations(`${preface}${svgData}`, svgProps);
|
|
@@ -62,11 +68,16 @@ const saveSvg = (svgEl, name, code, animated) => {
|
|
|
62
68
|
metadata.appendChild(script);
|
|
63
69
|
svg.appendChild(metadata);
|
|
64
70
|
}
|
|
65
|
-
var svgBlob = new Blob([wrapper.innerHTML], {
|
|
71
|
+
var svgBlob = new Blob([wrapper.innerHTML], {
|
|
72
|
+
type: 'image/svg+xml;charset=utf-8'
|
|
73
|
+
});
|
|
66
74
|
var svgUrl = URL.createObjectURL(svgBlob);
|
|
67
|
-
var downloadLink = document.createElement(
|
|
75
|
+
var downloadLink = document.createElement('a');
|
|
68
76
|
downloadLink.href = svgUrl;
|
|
69
|
-
downloadLink.download =
|
|
77
|
+
downloadLink.download =
|
|
78
|
+
animDuration > 0
|
|
79
|
+
? `${name}__${(Math.round(animDuration * 10) / 10).toString().replace('.', '_')}s.svg`
|
|
80
|
+
: `${name}.svg`;
|
|
70
81
|
document.body.appendChild(downloadLink);
|
|
71
82
|
downloadLink.click();
|
|
72
83
|
document.body.removeChild(downloadLink);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svgWithoutAnimations.d.ts","sourceRoot":"","sources":["../../../../../src/theme/CodeEditor/Editor/utils/svgWithoutAnimations.ts"],"names":[],"mappings":"AA6LA,QAAA,MAAM,gBAAgB,GAAI,KAAK,MAAM,EAAE,UAAU,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,KAAG,MAOlF,CAAC;AAEF,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|