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,12 +1,11 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import { BRYTHON_NOTIFICATION_EVENT, DOM_ELEMENT_IDS } from
|
|
3
|
-
import {
|
|
4
|
-
import { type LogMessage } from '
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { BRYTHON_NOTIFICATION_EVENT, DOM_ELEMENT_IDS } from '@theme/CodeEditor/constants';
|
|
3
|
+
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
4
|
+
import { type LogMessage } from '@theme/CodeEditor/WithScript/Types';
|
|
5
5
|
|
|
6
6
|
const BrythonCommunicator = () => {
|
|
7
|
-
const
|
|
8
|
-
const codeId =
|
|
9
|
-
|
|
7
|
+
const store = useStore();
|
|
8
|
+
const codeId = useScript(store, 'codeId');
|
|
10
9
|
|
|
11
10
|
const ref = React.useRef<HTMLDivElement>(null);
|
|
12
11
|
React.useEffect(() => {
|
|
@@ -18,32 +17,30 @@ const BrythonCommunicator = () => {
|
|
|
18
17
|
if (event.detail) {
|
|
19
18
|
const data = event.detail as LogMessage;
|
|
20
19
|
switch (data.type) {
|
|
21
|
-
case
|
|
20
|
+
case 'start':
|
|
22
21
|
store.clearLogMessages();
|
|
23
22
|
store.setExecuting(true);
|
|
24
23
|
break;
|
|
25
|
-
case
|
|
24
|
+
case 'done':
|
|
26
25
|
store.setExecuting(false);
|
|
27
26
|
break;
|
|
28
27
|
default:
|
|
29
|
-
store.addLogMessage(
|
|
28
|
+
store.addLogMessage({
|
|
29
|
+
type: data.type,
|
|
30
|
+
output: data.output,
|
|
31
|
+
timeStamp: data.timeStamp
|
|
32
|
+
});
|
|
30
33
|
break;
|
|
31
34
|
}
|
|
32
35
|
}
|
|
33
36
|
};
|
|
34
37
|
current.addEventListener(BRYTHON_NOTIFICATION_EVENT, onBryNotify as EventListener);
|
|
35
38
|
return () => {
|
|
36
|
-
current.removeEventListener(BRYTHON_NOTIFICATION_EVENT, onBryNotify as EventListener)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
+
current.removeEventListener(BRYTHON_NOTIFICATION_EVENT, onBryNotify as EventListener);
|
|
40
|
+
};
|
|
39
41
|
}, [ref, store]);
|
|
40
42
|
|
|
41
|
-
return (
|
|
42
|
-
<div
|
|
43
|
-
id={DOM_ELEMENT_IDS.communicator(codeId)}
|
|
44
|
-
ref={ref}
|
|
45
|
-
></div>
|
|
46
|
-
);
|
|
43
|
+
return <div id={DOM_ELEMENT_IDS.communicator(codeId)} ref={ref}></div>;
|
|
47
44
|
};
|
|
48
45
|
|
|
49
46
|
export default BrythonCommunicator;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import * as Icons from '
|
|
2
|
+
import * as Icons from '@theme/CodeEditor/Icon/icons';
|
|
3
3
|
import styles from './styles.module.css';
|
|
4
4
|
import clsx from 'clsx';
|
|
5
|
-
import Icon from '
|
|
5
|
+
import Icon from '@theme/CodeEditor/Icon';
|
|
6
6
|
|
|
7
7
|
export enum Color {
|
|
8
8
|
Primary = 'button--primary',
|
|
@@ -11,14 +11,14 @@ export enum Color {
|
|
|
11
11
|
Info = 'button--info',
|
|
12
12
|
Warning = 'button--warning',
|
|
13
13
|
Danger = 'button--danger',
|
|
14
|
-
Link = 'button--link'
|
|
14
|
+
Link = 'button--link'
|
|
15
15
|
}
|
|
16
16
|
export enum Size {
|
|
17
17
|
Small = 'button--sm',
|
|
18
|
-
Large = 'button--lg'
|
|
18
|
+
Large = 'button--lg'
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
interface Props {
|
|
21
|
+
export interface Props {
|
|
22
22
|
icon: keyof typeof Icons;
|
|
23
23
|
title?: string;
|
|
24
24
|
onClick?: React.MouseEventHandler<HTMLButtonElement>;
|
|
@@ -29,23 +29,27 @@ interface Props {
|
|
|
29
29
|
className?: string;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
|
|
33
32
|
const Button = (props: Props) => {
|
|
34
|
-
|
|
35
33
|
return (
|
|
36
|
-
<button
|
|
37
|
-
className={clsx(
|
|
34
|
+
<button
|
|
35
|
+
className={clsx(
|
|
36
|
+
'button',
|
|
37
|
+
props.color || Color.Secondary,
|
|
38
|
+
props.size || Size.Small,
|
|
39
|
+
styles.button,
|
|
40
|
+
props.className
|
|
41
|
+
)}
|
|
38
42
|
onClick={props.onClick}
|
|
39
43
|
title={props.title}
|
|
40
44
|
>
|
|
41
|
-
<Icon
|
|
45
|
+
<Icon
|
|
42
46
|
icon={props.icon}
|
|
43
47
|
className={styles.icon}
|
|
44
48
|
spin={props.spin}
|
|
45
49
|
size={props.iconSize || '1.6em'}
|
|
46
50
|
/>
|
|
47
51
|
</button>
|
|
48
|
-
)
|
|
49
|
-
}
|
|
52
|
+
);
|
|
53
|
+
};
|
|
50
54
|
|
|
51
|
-
export default Button;
|
|
55
|
+
export default Button;
|
|
@@ -4,10 +4,10 @@ import styles from './styles.module.css';
|
|
|
4
4
|
import { Prism } from 'prism-react-renderer';
|
|
5
5
|
import Slider from 'rc-slider';
|
|
6
6
|
import 'rc-slider/assets/index.css';
|
|
7
|
-
import {
|
|
7
|
+
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
8
8
|
import Translate, { translate } from '@docusaurus/Translate';
|
|
9
|
-
import Button from '
|
|
10
|
-
import DiffViewer from 'react-diff-viewer';
|
|
9
|
+
import Button from '@theme/CodeEditor/Button';
|
|
10
|
+
import DiffViewer from 'react-diff-viewer-continued';
|
|
11
11
|
import Details from '@theme/Details';
|
|
12
12
|
|
|
13
13
|
const highlightSyntax = (str: string) => {
|
|
@@ -17,7 +17,7 @@ const highlightSyntax = (str: string) => {
|
|
|
17
17
|
return (
|
|
18
18
|
<span
|
|
19
19
|
dangerouslySetInnerHTML={{
|
|
20
|
-
__html: Prism.highlight(str, Prism.languages.python, 'python')
|
|
20
|
+
__html: Prism.highlight(str, Prism.languages.python, 'python')
|
|
21
21
|
}}
|
|
22
22
|
/>
|
|
23
23
|
);
|
|
@@ -25,13 +25,13 @@ const highlightSyntax = (str: string) => {
|
|
|
25
25
|
|
|
26
26
|
const CodeHistory = () => {
|
|
27
27
|
const [version, setVersion] = React.useState(1);
|
|
28
|
-
const
|
|
29
|
-
const versions =
|
|
30
|
-
const versionsLoaded =
|
|
31
|
-
|
|
28
|
+
const store = useStore();
|
|
29
|
+
const versions = useScript(store, 'versions');
|
|
30
|
+
const versionsLoaded = useScript(store, 'versionsLoaded');
|
|
32
31
|
if (versions?.length < 2) {
|
|
33
32
|
return null;
|
|
34
33
|
}
|
|
34
|
+
|
|
35
35
|
return (
|
|
36
36
|
<div className={clsx(styles.codeHistory)}>
|
|
37
37
|
<Details
|
|
@@ -40,16 +40,26 @@ const CodeHistory = () => {
|
|
|
40
40
|
<summary>
|
|
41
41
|
<div className={clsx(styles.summary)}>
|
|
42
42
|
<span className="badge badge--secondary">
|
|
43
|
-
{
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
{versionsLoaded
|
|
44
|
+
? translate(
|
|
45
|
+
{
|
|
46
|
+
message: '{n} Versions',
|
|
47
|
+
id: 'CodeHistory.nVersions.text'
|
|
48
|
+
},
|
|
49
|
+
{ n: versions.length }
|
|
50
|
+
)
|
|
51
|
+
: translate({
|
|
52
|
+
message: 'Load Versions',
|
|
53
|
+
id: 'CodeHistory.LoadVersions.text'
|
|
54
|
+
})}
|
|
48
55
|
</span>
|
|
49
56
|
<span className={clsx(styles.spacer)}></span>
|
|
50
57
|
<Button
|
|
51
|
-
icon=
|
|
52
|
-
title={translate({
|
|
58
|
+
icon="Sync"
|
|
59
|
+
title={translate({
|
|
60
|
+
message: 'Sync Versions',
|
|
61
|
+
id: 'CodeHistory.LoadVersions.text'
|
|
62
|
+
})}
|
|
53
63
|
onClick={(e) => {
|
|
54
64
|
e.preventDefault();
|
|
55
65
|
e.stopPropagation();
|
|
@@ -80,9 +90,7 @@ const CodeHistory = () => {
|
|
|
80
90
|
max={versions.length - 1}
|
|
81
91
|
dots={versions.length < 50}
|
|
82
92
|
/>
|
|
83
|
-
<span className="badge badge--primary">
|
|
84
|
-
V{version}
|
|
85
|
-
</span>
|
|
93
|
+
<span className="badge badge--primary">V{version}</span>
|
|
86
94
|
</div>
|
|
87
95
|
<div className={clsx(styles.diffViewer)}>
|
|
88
96
|
{versions.length > 1 && (
|
|
@@ -95,7 +103,9 @@ const CodeHistory = () => {
|
|
|
95
103
|
{`V${version}`}
|
|
96
104
|
{versions[version].pasted && (
|
|
97
105
|
<span className={clsx('badge', 'badge--danger')}>
|
|
98
|
-
<Translate id="CodeHistory.PastedBadge.Text">
|
|
106
|
+
<Translate id="CodeHistory.PastedBadge.Text">
|
|
107
|
+
Pasted
|
|
108
|
+
</Translate>
|
|
99
109
|
</span>
|
|
100
110
|
)}
|
|
101
111
|
</div>
|
|
@@ -105,7 +115,9 @@ const CodeHistory = () => {
|
|
|
105
115
|
{`V${version}`}
|
|
106
116
|
{versions[version].pasted && (
|
|
107
117
|
<span className={clsx('badge', 'badge--danger')}>
|
|
108
|
-
<Translate id="CodeHistory.PastedBadge.Text">
|
|
118
|
+
<Translate id="CodeHistory.PastedBadge.Text">
|
|
119
|
+
Pasted
|
|
120
|
+
</Translate>
|
|
109
121
|
</span>
|
|
110
122
|
)}
|
|
111
123
|
</div>
|
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
.codeHistory
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
.codeHistory > .historyDetails {
|
|
2
|
+
cursor: pointer;
|
|
3
|
+
margin-bottom: 0;
|
|
4
|
+
border-top-left-radius: 0;
|
|
5
|
+
border-top-right-radius: 0;
|
|
6
6
|
}
|
|
7
7
|
.summary {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
display: flex;
|
|
9
|
+
align-items: center;
|
|
10
10
|
}
|
|
11
11
|
.spacer {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
12
|
+
flex-grow: 1;
|
|
13
|
+
flex-shrink: 1;
|
|
14
|
+
flex-basis: 0;
|
|
15
|
+
}
|
|
16
16
|
|
|
17
17
|
.versionControl {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
padding: 1em 2em;
|
|
19
|
+
box-shadow: var(--ifm-global-shadow-lw);
|
|
20
|
+
border-radius: var(--ifm-global-radius);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
.faButton {
|
|
24
|
-
|
|
24
|
+
margin-left: 1em;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
.faButton:hover {
|
|
28
|
-
|
|
28
|
+
transform: scale(1.2);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
.diffViewer {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
--ifm-pre-background: rgba(255, 255, 255, 0);
|
|
33
|
+
--ifm-alert-background-color: rgba(255, 255, 255, 0);
|
|
34
|
+
--ifm-alert-background-color-highlight: rgba(255, 255, 255, 0);
|
|
35
|
+
--ifm-table-stripe-background: rgba(255, 255, 255, 0);
|
|
36
|
+
font-family: monospace;
|
|
37
|
+
overflow: auto;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
.diffViewer table tbody tr td {
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
padding-top: 0;
|
|
42
|
+
padding-bottom: 0;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
.diffViewer table tbody tr td pre {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
white-space: nowrap;
|
|
47
|
+
padding-top: 0;
|
|
48
|
+
padding-bottom: 0;
|
|
49
|
+
line-height: 18px;
|
|
50
50
|
}
|
|
51
51
|
.diffHeader {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
52
|
+
display: flex;
|
|
53
|
+
justify-content: space-between;
|
|
54
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
|
|
3
|
+
import CodeEditor, { type MetaProps } from '@theme/CodeEditor';
|
|
4
|
+
import ScriptContext from '@theme/CodeEditor/WithScript/ScriptContext';
|
|
5
|
+
import CodeBlock from '@theme/CodeBlock';
|
|
6
|
+
|
|
7
|
+
interface Props extends MetaProps {
|
|
8
|
+
className?: string;
|
|
9
|
+
title?: string;
|
|
10
|
+
children: string | React.ReactNode;
|
|
11
|
+
onChange?: (code: string) => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const SPLIT_CODE_REGEX = /^(?:(?<pre>.*?)\n###\s*PRE\s*)?(?<code>.*?)(?:\n###\s*POST\s*(?<post>.*))?$/s;
|
|
15
|
+
export const splitCode = (rawCode: string) => {
|
|
16
|
+
const { pre, code, post } = rawCode.replace(/\s*\n$/, '').match(SPLIT_CODE_REGEX).groups || {};
|
|
17
|
+
return {
|
|
18
|
+
pre: pre || '',
|
|
19
|
+
code: code || '',
|
|
20
|
+
post: post || ''
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Use this component when you want a working CodeEditor.
|
|
26
|
+
* The CodeEditor must be wrapped in a ScriptContext - this component does that.
|
|
27
|
+
* wraps it in a ScriptContext and initializes the CodeEditor with the given
|
|
28
|
+
* params.
|
|
29
|
+
*/
|
|
30
|
+
const ContextEditor = (props: Props) => {
|
|
31
|
+
const langMatch = ((props.className || '') as string).match(/language-(?<lang>\w*)/);
|
|
32
|
+
let lang = langMatch?.groups?.lang?.toLocaleLowerCase() ?? '';
|
|
33
|
+
if (lang === 'py') {
|
|
34
|
+
lang = 'python';
|
|
35
|
+
}
|
|
36
|
+
if (ExecutionEnvironment.canUseDOM) {
|
|
37
|
+
const title = props.title || lang;
|
|
38
|
+
const { pre, code, post } = splitCode((props.children as string) || '');
|
|
39
|
+
return (
|
|
40
|
+
<ScriptContext
|
|
41
|
+
id={props.id}
|
|
42
|
+
lang={lang}
|
|
43
|
+
title={title}
|
|
44
|
+
code={code}
|
|
45
|
+
preCode={pre}
|
|
46
|
+
postCode={post}
|
|
47
|
+
readonly={!!props.readonly}
|
|
48
|
+
versioned={!!props.versioned}
|
|
49
|
+
>
|
|
50
|
+
<CodeEditor
|
|
51
|
+
code={code}
|
|
52
|
+
lang={lang}
|
|
53
|
+
preCode={pre}
|
|
54
|
+
postCode={post}
|
|
55
|
+
maxLines={props.maxLines && Number.parseInt(props.maxLines, 10)}
|
|
56
|
+
readonly={!!props.readonly}
|
|
57
|
+
resettable={!props.noReset}
|
|
58
|
+
download={!props.versioned && !props.noDownload}
|
|
59
|
+
slim={!!props.slim}
|
|
60
|
+
showLineNumbers={!(!!props.slim && !/\n/.test(code))}
|
|
61
|
+
versioned={!!props.versioned}
|
|
62
|
+
noHistory={!!props.noHistory}
|
|
63
|
+
noCompare={!!props.noCompare}
|
|
64
|
+
title={title}
|
|
65
|
+
className={props.className}
|
|
66
|
+
onChange={props.onChange}
|
|
67
|
+
/>
|
|
68
|
+
</ScriptContext>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
return <CodeBlock {...props} />;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export default ContextEditor;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import clsx from 'clsx';
|
|
3
3
|
import styles from './styles.module.css';
|
|
4
|
-
import { DOM_ELEMENT_IDS } from '
|
|
4
|
+
import { DOM_ELEMENT_IDS } from '@theme/CodeEditor/constants';
|
|
5
5
|
import AceEditor from 'react-ace';
|
|
6
6
|
import 'ace-builds/src-noconflict/ext-searchbox';
|
|
7
7
|
import 'ace-builds/src-noconflict/mode-python';
|
|
@@ -10,7 +10,7 @@ import 'ace-builds/src-noconflict/mode-svg';
|
|
|
10
10
|
import 'ace-builds/src-noconflict/theme-dracula';
|
|
11
11
|
import 'ace-builds/src-noconflict/ext-language_tools';
|
|
12
12
|
import 'ace-builds/webpack-resolver';
|
|
13
|
-
import {
|
|
13
|
+
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
14
14
|
// import 'ace-builds/src-noconflict/theme-textmate';
|
|
15
15
|
// import('ace-builds/src-noconflict/snippets/python'),
|
|
16
16
|
|
|
@@ -18,20 +18,21 @@ export interface Props {
|
|
|
18
18
|
versioned?: boolean;
|
|
19
19
|
showLineNumbers: boolean;
|
|
20
20
|
maxLines?: number;
|
|
21
|
+
onChange?: (code: string) => void;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
const ALIAS_LANG_MAP_ACE = {
|
|
24
|
-
mpy: 'python'
|
|
25
|
-
}
|
|
25
|
+
mpy: 'python'
|
|
26
|
+
};
|
|
26
27
|
|
|
27
28
|
const EditorAce = (props: Props) => {
|
|
28
29
|
const eRef = React.useRef<AceEditor>(null);
|
|
29
|
-
const
|
|
30
|
-
const code =
|
|
31
|
-
const pristineCode =
|
|
32
|
-
const lang =
|
|
33
|
-
const codeId =
|
|
34
|
-
const showRaw =
|
|
30
|
+
const store = useStore();
|
|
31
|
+
const code = useScript(store, 'code');
|
|
32
|
+
const pristineCode = useScript(store, 'pristineCode');
|
|
33
|
+
const lang = useScript(store, 'lang');
|
|
34
|
+
const codeId = useScript(store, 'codeId');
|
|
35
|
+
const showRaw = useScript(store, 'showRaw');
|
|
35
36
|
|
|
36
37
|
React.useEffect(() => {
|
|
37
38
|
if (eRef && eRef.current) {
|
|
@@ -41,7 +42,7 @@ const EditorAce = (props: Props) => {
|
|
|
41
42
|
// commands is array of key bindings.
|
|
42
43
|
name: 'execute',
|
|
43
44
|
bindKey: { win: 'Ctrl-Enter', mac: 'Command-Enter' },
|
|
44
|
-
exec: () => store.execScript()
|
|
45
|
+
exec: () => store.execScript()
|
|
45
46
|
});
|
|
46
47
|
}
|
|
47
48
|
node.editor.commands.addCommand({
|
|
@@ -50,7 +51,7 @@ const EditorAce = (props: Props) => {
|
|
|
50
51
|
bindKey: { win: 'Ctrl-s', mac: 'Command-s' },
|
|
51
52
|
exec: () => {
|
|
52
53
|
store.saveNow();
|
|
53
|
-
}
|
|
54
|
+
}
|
|
54
55
|
});
|
|
55
56
|
return () => {
|
|
56
57
|
if (node && node.editor) {
|
|
@@ -65,7 +66,7 @@ const EditorAce = (props: Props) => {
|
|
|
65
66
|
}
|
|
66
67
|
};
|
|
67
68
|
}
|
|
68
|
-
}, [eRef, lang]);
|
|
69
|
+
}, [eRef, lang, store]);
|
|
69
70
|
|
|
70
71
|
return (
|
|
71
72
|
<div className={clsx(styles.editor)}>
|
|
@@ -83,7 +84,7 @@ const EditorAce = (props: Props) => {
|
|
|
83
84
|
/**
|
|
84
85
|
* Save immediately as pasted content
|
|
85
86
|
*/
|
|
86
|
-
store.
|
|
87
|
+
store.setIsPasted(true);
|
|
87
88
|
}
|
|
88
89
|
}}
|
|
89
90
|
focus={false}
|
|
@@ -92,8 +93,11 @@ const EditorAce = (props: Props) => {
|
|
|
92
93
|
ref={eRef}
|
|
93
94
|
mode={ALIAS_LANG_MAP_ACE[lang as keyof typeof ALIAS_LANG_MAP_ACE] ?? lang}
|
|
94
95
|
theme="dracula"
|
|
95
|
-
onChange={(value: string, e: {action: 'insert' | 'remove'}) => {
|
|
96
|
+
onChange={(value: string, e: { action: 'insert' | 'remove' }) => {
|
|
96
97
|
store.setCode(value, e.action);
|
|
98
|
+
if (props.onChange) {
|
|
99
|
+
props.onChange(value);
|
|
100
|
+
}
|
|
97
101
|
}}
|
|
98
102
|
readOnly={showRaw}
|
|
99
103
|
value={showRaw ? pristineCode : code}
|
|
@@ -103,7 +107,7 @@ const EditorAce = (props: Props) => {
|
|
|
103
107
|
setOptions={{
|
|
104
108
|
displayIndentGuides: true,
|
|
105
109
|
vScrollBarAlwaysVisible: false,
|
|
106
|
-
highlightGutterLine: false
|
|
110
|
+
highlightGutterLine: false
|
|
107
111
|
}}
|
|
108
112
|
showPrintMargin={false}
|
|
109
113
|
highlightActiveLine={false}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import clsx from 'clsx';
|
|
3
3
|
import styles from './styles.module.css';
|
|
4
|
-
import {
|
|
5
|
-
import ShowSyncStatus from '
|
|
6
|
-
import Reset from '
|
|
7
|
-
import DownloadCode from '
|
|
8
|
-
import ShowRaw from '
|
|
9
|
-
import RunCode from '
|
|
4
|
+
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
5
|
+
import ShowSyncStatus from '@theme/CodeEditor/Actions/ShowSyncStatus';
|
|
6
|
+
import Reset from '@theme/CodeEditor/Actions/Reset';
|
|
7
|
+
import DownloadCode from '@theme/CodeEditor/Actions/DownloadCode';
|
|
8
|
+
import ShowRaw from '@theme/CodeEditor/Actions/ShowRaw';
|
|
9
|
+
import RunCode from '@theme/CodeEditor/Actions/RunCode';
|
|
10
10
|
|
|
11
|
-
interface Props {
|
|
11
|
+
export interface Props {
|
|
12
12
|
slim: boolean;
|
|
13
13
|
title: string;
|
|
14
14
|
resettable: boolean;
|
|
@@ -17,25 +17,19 @@ interface Props {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
const Header = (props: Props) => {
|
|
20
|
-
const
|
|
20
|
+
const store = useStore();
|
|
21
21
|
|
|
22
|
-
const hasEdits =
|
|
23
|
-
const lang =
|
|
22
|
+
const hasEdits = useScript(store, 'hasEdits');
|
|
23
|
+
const lang = useScript(store, 'lang');
|
|
24
24
|
return (
|
|
25
25
|
<div className={clsx(styles.controls, props.slim && styles.slim)}>
|
|
26
26
|
{!props.slim && (
|
|
27
27
|
<React.Fragment>
|
|
28
28
|
<div className={styles.title}>{props.title}</div>
|
|
29
29
|
<ShowSyncStatus />
|
|
30
|
-
{hasEdits && props.resettable &&
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
{props.download && (
|
|
34
|
-
<DownloadCode title={props.title} />
|
|
35
|
-
)}
|
|
36
|
-
{hasEdits && !props.noCompare && (
|
|
37
|
-
<ShowRaw />
|
|
38
|
-
)}
|
|
30
|
+
{hasEdits && props.resettable && <Reset />}
|
|
31
|
+
{props.download && <DownloadCode title={props.title} />}
|
|
32
|
+
{hasEdits && !props.noCompare && <ShowRaw />}
|
|
39
33
|
</React.Fragment>
|
|
40
34
|
)}
|
|
41
35
|
{lang === 'python' && <RunCode title={props.title} slim={props.slim} />}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
display: flex;
|
|
4
4
|
align-items: center;
|
|
5
5
|
letter-spacing: 0.08em;
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
z-index: calc(var(--ifm-z-index-fixed) - 2);
|
|
8
8
|
padding: 0.2em;
|
|
9
9
|
padding-left: 0.5em;
|
|
@@ -15,13 +15,13 @@
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
.controls > .title {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
flex-shrink: 1;
|
|
19
|
+
flex-grow: 1;
|
|
20
|
+
overflow-x: hidden;
|
|
21
|
+
text-overflow: ellipsis;
|
|
22
|
+
white-space: nowrap;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
.controls.slim {
|
|
26
26
|
padding: 0;
|
|
27
|
-
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import styles from './styles.module.css';
|
|
3
|
+
import CodeBlock from '@theme/CodeBlock';
|
|
4
|
+
import clsx from 'clsx';
|
|
5
|
+
import Icon from '@theme/CodeEditor/Icon';
|
|
6
|
+
import { translate } from '@docusaurus/Translate';
|
|
7
|
+
|
|
8
|
+
interface Props {
|
|
9
|
+
type: 'pre' | 'post';
|
|
10
|
+
code: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const HiddenCode = (props: Props) => {
|
|
14
|
+
const [show, setShow] = React.useState(false);
|
|
15
|
+
const { code } = props;
|
|
16
|
+
if (code.length === 0) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return (
|
|
20
|
+
<div className={clsx(styles.container)}>
|
|
21
|
+
{show && (
|
|
22
|
+
<div>
|
|
23
|
+
<CodeBlock
|
|
24
|
+
language="python"
|
|
25
|
+
showLineNumbers={false}
|
|
26
|
+
className={clsx(styles.hiddenCode, styles.pre, show && styles.open)}
|
|
27
|
+
>
|
|
28
|
+
{code}
|
|
29
|
+
</CodeBlock>
|
|
30
|
+
</div>
|
|
31
|
+
)}
|
|
32
|
+
<button
|
|
33
|
+
className={clsx(styles.toggleButton, show && styles.open, styles[props.type])}
|
|
34
|
+
onClick={() => setShow(!show)}
|
|
35
|
+
title={translate({
|
|
36
|
+
id: 'theme.CodeEditor.Editor.HiddenCode.toggleButtonTitle',
|
|
37
|
+
message: 'Toggle hidden code'
|
|
38
|
+
})}
|
|
39
|
+
>
|
|
40
|
+
<Icon
|
|
41
|
+
icon={show ? 'TrayMinus' : 'TrayPlus'}
|
|
42
|
+
rotate={(show ? 180 : 0) + (props.type === 'post' ? 180 : 0)}
|
|
43
|
+
/>
|
|
44
|
+
</button>
|
|
45
|
+
</div>
|
|
46
|
+
);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export default HiddenCode;
|