docusaurus-live-brython 3.0.0-beta.24 → 3.0.0-beta.26
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 +5 -0
- package/lib/theme/CodeBlock/index.d.ts.map +1 -1
- package/lib/theme/CodeBlock/index.jsx +9 -6
- package/lib/theme/CodeEditor/Actions/ShowSyncStatus.d.ts.map +1 -1
- package/lib/theme/CodeEditor/Actions/ShowSyncStatus.jsx +14 -9
- package/lib/theme/CodeEditor/Editor/Result/Graphics/index.d.ts.map +1 -1
- package/lib/theme/CodeEditor/Editor/Result/Graphics/index.jsx +2 -1
- package/lib/theme/CodeEditor/Editor/index.jsx +2 -2
- package/lib/theme/CodeEditor/WithScript/ScriptContext.d.ts.map +1 -1
- package/lib/theme/CodeEditor/WithScript/ScriptContext.jsx +10 -4
- package/lib/theme/CodeEditor/WithScript/Types.d.ts +1 -1
- package/lib/theme/CodeEditor/WithScript/Types.d.ts.map +1 -1
- package/lib/theme/CodeEditor/WithScript/createStore.js +3 -3
- package/lib/theme/CodeEditor/index.d.ts.map +1 -1
- package/lib/theme/CodeEditor/index.jsx +2 -1
- package/package.json +1 -1
- package/src/theme/CodeBlock/index.tsx +12 -7
- package/src/theme/CodeEditor/Actions/DownloadCode.tsx +1 -1
- package/src/theme/CodeEditor/Actions/ShowSyncStatus.tsx +22 -9
- package/src/theme/CodeEditor/Editor/Result/Graphics/index.tsx +6 -1
- package/src/theme/CodeEditor/Editor/index.tsx +2 -2
- package/src/theme/CodeEditor/WithScript/ScriptContext.tsx +12 -5
- package/src/theme/CodeEditor/WithScript/Types.ts +1 -1
- package/src/theme/CodeEditor/WithScript/bryRunner.ts +1 -1
- package/src/theme/CodeEditor/WithScript/createStore.ts +3 -3
- package/src/theme/CodeEditor/index.tsx +2 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## Version 3.0.0beta.25
|
|
4
|
+
- Breaking: Renamed `isGraphicsmodalOpen` to `graphicsModalExecutionNr` and changing it's type from `boolean` to `number`.
|
|
5
|
+
This fixes an issue that caused the Turtle Output to display the first animation instead of the current created one, when the user kept the graphics modal open while changing the code.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/theme/CodeBlock/index.tsx"],"names":[],"mappings":";;AACA,OAAkB,EAAE,KAAK,KAAK,IAAI,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC/E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAOtD,KAAK,KAAK,GAAG,YAAY,CAAC,OAAO,aAAa,CAAC,CAAC;AAsChD,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,KAAK,EAAE,KAAK,GAAG,GAAG,CAAC,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/theme/CodeBlock/index.tsx"],"names":[],"mappings":";;AACA,OAAkB,EAAE,KAAK,KAAK,IAAI,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC/E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAOtD,KAAK,KAAK,GAAG,YAAY,CAAC,OAAO,aAAa,CAAC,CAAC;AAsChD,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,KAAK,EAAE,KAAK,GAAG,GAAG,CAAC,OAAO,CA2BlE"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import CodeBlock from '@theme-init/CodeBlock';
|
|
3
|
-
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
|
|
4
3
|
import ContextEditor from '@theme/CodeEditor/ContextEditor';
|
|
4
|
+
import BrowserOnly from '@docusaurus/BrowserOnly';
|
|
5
5
|
const sanitizedTitle = (id) => {
|
|
6
6
|
if (!id) {
|
|
7
7
|
return;
|
|
@@ -42,13 +42,16 @@ export default function CodeBlockWrapper(props) {
|
|
|
42
42
|
// if (metaProps.live_jsx) {
|
|
43
43
|
// return <Playground scope={ReactLiveScope} {...props} />;
|
|
44
44
|
// }
|
|
45
|
-
if (metaProps.live_py
|
|
45
|
+
if (metaProps.live_py) {
|
|
46
46
|
const title = props.title || metaProps.title;
|
|
47
47
|
const rawcode = (props.children || '').replace(/\s*\n$/, '');
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
{props
|
|
51
|
-
|
|
48
|
+
return (<BrowserOnly fallback={<CodeBlock {...props}/>}>
|
|
49
|
+
{() => {
|
|
50
|
+
return (<ContextEditor {...props} {...metaProps} title={sanitizedTitle(title) || lang}>
|
|
51
|
+
{props.children}
|
|
52
|
+
</ContextEditor>);
|
|
53
|
+
}}
|
|
54
|
+
</BrowserOnly>);
|
|
52
55
|
}
|
|
53
56
|
return <CodeBlock {...props}/>;
|
|
54
57
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ShowSyncStatus.d.ts","sourceRoot":"","sources":["../../../../src/theme/CodeEditor/Actions/ShowSyncStatus.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"ShowSyncStatus.d.ts","sourceRoot":"","sources":["../../../../src/theme/CodeEditor/Actions/ShowSyncStatus.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAM/B,QAAA,MAAM,cAAc,yBAqCnB,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -2,6 +2,7 @@ import * as React from 'react';
|
|
|
2
2
|
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
3
3
|
import Icon, { Color } from '@theme/CodeEditor/Icon';
|
|
4
4
|
import { Status } from '@theme/CodeEditor/WithScript/Types';
|
|
5
|
+
import BrowserOnly from '@docusaurus/BrowserOnly';
|
|
5
6
|
const ShowSyncStatus = () => {
|
|
6
7
|
const store = useStore();
|
|
7
8
|
const isLoaded = useScript(store, 'isLoaded');
|
|
@@ -14,14 +15,18 @@ const ShowSyncStatus = () => {
|
|
|
14
15
|
return () => clearTimeout(disposer);
|
|
15
16
|
}
|
|
16
17
|
}, [status, store]);
|
|
17
|
-
return (
|
|
18
|
-
{
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
return (<BrowserOnly fallback={null}>
|
|
19
|
+
{() => {
|
|
20
|
+
return (<>
|
|
21
|
+
{!isLoaded && <Icon icon="Sync" spin size={'1.2em'} color={Color.Primary}/>}
|
|
22
|
+
<div style={{ flexGrow: 1, flexShrink: 1, flexBasis: 0 }}></div>
|
|
23
|
+
<span style={{ minWidth: '1em' }}>
|
|
24
|
+
{status === Status.SYNCING && (<Icon icon="Sync" spin size={'1.2em'} color={Color.Primary}/>)}
|
|
25
|
+
{status === Status.SUCCESS && (<Icon icon="Check" size={'1.2em'} color={Color.Success}/>)}
|
|
26
|
+
{status === Status.ERROR && (<Icon icon="Close" size={'1.2em'} color={Color.Danger}/>)}
|
|
27
|
+
</span>
|
|
28
|
+
</>);
|
|
29
|
+
}}
|
|
30
|
+
</BrowserOnly>);
|
|
26
31
|
};
|
|
27
32
|
export default ShowSyncStatus;
|
|
@@ -1 +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,GAAG,CAAC,OAAO,CAAC;IACvB,IAAI,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;CACtB;AACD,QAAA,MAAM,QAAQ,UAAW,KAAK,
|
|
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,GAAG,CAAC,OAAO,CAAC;IACvB,IAAI,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;CACtB;AACD,QAAA,MAAM,QAAQ,UAAW,KAAK,sBAgC7B,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
|
@@ -9,6 +9,7 @@ import clsx from 'clsx';
|
|
|
9
9
|
const Graphics = (props) => {
|
|
10
10
|
const store = useStore();
|
|
11
11
|
const codeId = useScript(store, 'codeId');
|
|
12
|
+
const graphicsModalExecutionNr = useScript(store, 'graphicsModalExecutionNr');
|
|
12
13
|
const nodeRef = React.useRef(null);
|
|
13
14
|
return (<Draggable onStop={checkForButtonClick} positionOffset={{ x: '15%', y: '25%' }} nodeRef={nodeRef}>
|
|
14
15
|
<div className={styles.brythonGraphicsResult} ref={nodeRef}>
|
|
@@ -21,7 +22,7 @@ const Graphics = (props) => {
|
|
|
21
22
|
store.closeGraphicsModal();
|
|
22
23
|
}} iconSize="12px"/>
|
|
23
24
|
</div>
|
|
24
|
-
<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}`}>
|
|
25
26
|
{props.main}
|
|
26
27
|
</div>
|
|
27
28
|
</div>
|
|
@@ -16,7 +16,7 @@ const Editor = (props) => {
|
|
|
16
16
|
const codeId = useScript(store, 'codeId');
|
|
17
17
|
const hasCanvasOutput = useScript(store, 'hasCanvasOutput');
|
|
18
18
|
const hasTurtleOutput = useScript(store, 'hasTurtleOutput');
|
|
19
|
-
const
|
|
19
|
+
const graphicsModalExecutionNr = useScript(store, 'graphicsModalExecutionNr');
|
|
20
20
|
return (<React.Fragment>
|
|
21
21
|
<Header slim={props.slim} title={props.title} resettable={props.resettable} download={props.download} noCompare={props.noCompare}/>
|
|
22
22
|
<div className={clsx(styles.editorContainer)}>
|
|
@@ -27,7 +27,7 @@ const Editor = (props) => {
|
|
|
27
27
|
{lang === 'python' && (<>
|
|
28
28
|
<Result />
|
|
29
29
|
<div id={DOM_ELEMENT_IDS.outputDiv(codeId)}></div>
|
|
30
|
-
{
|
|
30
|
+
{graphicsModalExecutionNr > 0 && (<>
|
|
31
31
|
{hasTurtleOutput && <Turtle />}
|
|
32
32
|
{hasCanvasOutput && <Canvas />}
|
|
33
33
|
{!hasCanvasOutput && !hasTurtleOutput && <Graphics />}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScriptContext.d.ts","sourceRoot":"","sources":["../../../../src/theme/CodeEditor/WithScript/ScriptContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,QAAQ,EAAE,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"ScriptContext.d.ts","sourceRoot":"","sources":["../../../../src/theme/CodeEditor/WithScript/ScriptContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAKnF,eAAO,MAAM,OAAO,8EAAuD,CAAC;AAE5E,QAAA,MAAM,aAAa,UAAW,SAAS,GAAG;IAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;CAAE,sBAwBtE,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
|
@@ -2,6 +2,8 @@ import React from 'react';
|
|
|
2
2
|
import { usePluginData } from '@docusaurus/useGlobalData';
|
|
3
3
|
import { createStore } from '@theme/CodeEditor/WithScript/createStore';
|
|
4
4
|
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
5
|
+
import BrowserOnly from '@docusaurus/BrowserOnly';
|
|
6
|
+
import CodeBlock from '@theme/CodeBlock';
|
|
5
7
|
export const Context = React.createContext(undefined);
|
|
6
8
|
const ScriptContext = (props) => {
|
|
7
9
|
const { libDir, syncMaxOnceEvery } = usePluginData('docusaurus-live-brython');
|
|
@@ -13,9 +15,13 @@ const ScriptContext = (props) => {
|
|
|
13
15
|
setStore(store);
|
|
14
16
|
store.load();
|
|
15
17
|
}, [props.id, libDir, siteConfig]);
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
return (<BrowserOnly fallback={<CodeBlock language={props.lang}>{props.code}</CodeBlock>}>
|
|
19
|
+
{() => {
|
|
20
|
+
if (!store) {
|
|
21
|
+
return <div>Load</div>;
|
|
22
|
+
}
|
|
23
|
+
return <Context.Provider value={store}>{props.children}</Context.Provider>;
|
|
24
|
+
}}
|
|
25
|
+
</BrowserOnly>);
|
|
20
26
|
};
|
|
21
27
|
export default ScriptContext;
|
|
@@ -31,7 +31,7 @@ export interface Script extends StoredScript {
|
|
|
31
31
|
postCode: string;
|
|
32
32
|
lang: 'py' | string;
|
|
33
33
|
logs: LogMessage[];
|
|
34
|
-
|
|
34
|
+
graphicsModalExecutionNr: number;
|
|
35
35
|
hasGraphicsOutput: boolean;
|
|
36
36
|
hasTurtleOutput: boolean;
|
|
37
37
|
hasCanvasOutput: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Types.d.ts","sourceRoot":"","sources":["../../../../src/theme/CodeEditor/WithScript/Types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,IAAI,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC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AClB,SAAS,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,QAAQ,CAAC,CAAC,GAAG,MAAM;IAChC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAClB,QAAQ,EAAE,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,KAAK,IAAI,CAAC;IAClD,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,CAAC;IAChD,OAAO,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/B,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,MAAM,KAAK,IAAI,CAAC;IACvE,YAAY,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI,CAAC;IAC3C,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,kBAAkB,EAAE,MAAM,IAAI,CAAC;IAC/B,aAAa,EAAE,CAAC,GAAG,EAAE,UAAU,KAAK,IAAI,CAAC;IACzC,gBAAgB,EAAE,MAAM,IAAI,CAAC;IAC7B,IAAI,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IAC5B,YAAY,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,WAAW,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;IACzC,UAAU,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IACvC,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;CACvC"}
|
|
@@ -115,7 +115,7 @@ export const createStore = (props, libDir, syncMaxOnceEvery, router) => {
|
|
|
115
115
|
setState((s) => ({
|
|
116
116
|
...s,
|
|
117
117
|
isExecuting: true,
|
|
118
|
-
|
|
118
|
+
graphicsModalExecutionNr: state.hasGraphicsOutput ? state.graphicsModalExecutionNr + 1 : 0
|
|
119
119
|
}));
|
|
120
120
|
runCode(state.code, state.preCode, state.postCode, codeId, libDir, router);
|
|
121
121
|
};
|
|
@@ -169,7 +169,7 @@ export const createStore = (props, libDir, syncMaxOnceEvery, router) => {
|
|
|
169
169
|
setState((s) => ({ ...s, logs: [] }));
|
|
170
170
|
};
|
|
171
171
|
const closeGraphicsModal = () => {
|
|
172
|
-
setState((s) => ({ ...s,
|
|
172
|
+
setState((s) => ({ ...s, graphicsModalExecutionNr: 0 }));
|
|
173
173
|
};
|
|
174
174
|
const stopScript = () => {
|
|
175
175
|
const code = document.getElementById(DOM_ELEMENT_IDS.communicator(state.codeId));
|
|
@@ -185,7 +185,7 @@ export const createStore = (props, libDir, syncMaxOnceEvery, router) => {
|
|
|
185
185
|
pristineCode: codeData.code,
|
|
186
186
|
isExecuting: false,
|
|
187
187
|
logs: [],
|
|
188
|
-
|
|
188
|
+
graphicsModalExecutionNr: 0,
|
|
189
189
|
hasEdits: false,
|
|
190
190
|
createdAt: createdAt,
|
|
191
191
|
isLoaded: false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/theme/CodeEditor/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/theme/CodeEditor/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAU/B,MAAM,WAAW,SAAS;IACtB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AACD,MAAM,WAAW,KAAK;IAClB,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,eAAe,EAAE,OAAO,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACrC;AAED,QAAA,MAAM,UAAU,UAAW,KAAK,sBAwB/B,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
|
@@ -6,10 +6,11 @@ import clsx from 'clsx';
|
|
|
6
6
|
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
7
7
|
import BrowserOnly from '@docusaurus/BrowserOnly';
|
|
8
8
|
import CodeHistory from '@theme/CodeEditor/CodeHistory';
|
|
9
|
+
import CodeBlock from '@theme/CodeBlock';
|
|
9
10
|
const CodeEditor = (props) => {
|
|
10
11
|
const store = useStore();
|
|
11
12
|
const lang = useScript(store, 'lang');
|
|
12
|
-
return (<BrowserOnly fallback={<
|
|
13
|
+
return (<BrowserOnly fallback={<CodeBlock language={props.lang}>{props.code}</CodeBlock>}>
|
|
13
14
|
{() => {
|
|
14
15
|
return (<div className={clsx(styles.wrapper, 'notranslate', props.className)}>
|
|
15
16
|
<div className={clsx(styles.playgroundContainer, props.slim ? styles.containerSlim : styles.containerBig, 'live_py')}>
|
package/package.json
CHANGED
|
@@ -2,10 +2,10 @@ import React from 'react';
|
|
|
2
2
|
import CodeBlock, { type Props as CodeBlockType } from '@theme-init/CodeBlock';
|
|
3
3
|
import type { WrapperProps } from '@docusaurus/types';
|
|
4
4
|
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
|
|
5
|
-
import
|
|
5
|
+
import { type MetaProps } from '@theme/CodeEditor';
|
|
6
6
|
|
|
7
|
-
import ScriptContext from '@theme/CodeEditor/WithScript/ScriptContext';
|
|
8
7
|
import ContextEditor from '@theme/CodeEditor/ContextEditor';
|
|
8
|
+
import BrowserOnly from '@docusaurus/BrowserOnly';
|
|
9
9
|
|
|
10
10
|
type Props = WrapperProps<typeof CodeBlockType>;
|
|
11
11
|
|
|
@@ -55,15 +55,20 @@ export default function CodeBlockWrapper(props: Props): JSX.Element {
|
|
|
55
55
|
// if (metaProps.live_jsx) {
|
|
56
56
|
// return <Playground scope={ReactLiveScope} {...props} />;
|
|
57
57
|
// }
|
|
58
|
-
if (metaProps.live_py
|
|
58
|
+
if (metaProps.live_py) {
|
|
59
59
|
const title = props.title || metaProps.title;
|
|
60
60
|
|
|
61
61
|
const rawcode: string = ((props.children as string) || '').replace(/\s*\n$/, '');
|
|
62
|
-
let code = rawcode;
|
|
63
62
|
return (
|
|
64
|
-
<
|
|
65
|
-
{
|
|
66
|
-
|
|
63
|
+
<BrowserOnly fallback={<CodeBlock {...props} />}>
|
|
64
|
+
{() => {
|
|
65
|
+
return (
|
|
66
|
+
<ContextEditor {...props} {...metaProps} title={sanitizedTitle(title) || lang}>
|
|
67
|
+
{props.children}
|
|
68
|
+
</ContextEditor>
|
|
69
|
+
);
|
|
70
|
+
}}
|
|
71
|
+
</BrowserOnly>
|
|
67
72
|
);
|
|
68
73
|
}
|
|
69
74
|
return <CodeBlock {...props} />;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
3
|
-
import Button
|
|
3
|
+
import Button from '@theme/CodeEditor/Button';
|
|
4
4
|
import { translate } from '@docusaurus/Translate';
|
|
5
5
|
|
|
6
6
|
const DownloadCode = (props: { title: string }) => {
|
|
@@ -2,6 +2,7 @@ import * as React from 'react';
|
|
|
2
2
|
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
3
3
|
import Icon, { Color } from '@theme/CodeEditor/Icon';
|
|
4
4
|
import { Status } from '@theme/CodeEditor/WithScript/Types';
|
|
5
|
+
import BrowserOnly from '@docusaurus/BrowserOnly';
|
|
5
6
|
|
|
6
7
|
const ShowSyncStatus = () => {
|
|
7
8
|
const store = useStore();
|
|
@@ -18,15 +19,27 @@ const ShowSyncStatus = () => {
|
|
|
18
19
|
}, [status, store]);
|
|
19
20
|
|
|
20
21
|
return (
|
|
21
|
-
|
|
22
|
-
{
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
<BrowserOnly fallback={null}>
|
|
23
|
+
{() => {
|
|
24
|
+
return (
|
|
25
|
+
<>
|
|
26
|
+
{!isLoaded && <Icon icon="Sync" spin size={'1.2em'} color={Color.Primary} />}
|
|
27
|
+
<div style={{ flexGrow: 1, flexShrink: 1, flexBasis: 0 }}></div>
|
|
28
|
+
<span style={{ minWidth: '1em' }}>
|
|
29
|
+
{status === Status.SYNCING && (
|
|
30
|
+
<Icon icon="Sync" spin size={'1.2em'} color={Color.Primary} />
|
|
31
|
+
)}
|
|
32
|
+
{status === Status.SUCCESS && (
|
|
33
|
+
<Icon icon="Check" size={'1.2em'} color={Color.Success} />
|
|
34
|
+
)}
|
|
35
|
+
{status === Status.ERROR && (
|
|
36
|
+
<Icon icon="Close" size={'1.2em'} color={Color.Danger} />
|
|
37
|
+
)}
|
|
38
|
+
</span>
|
|
39
|
+
</>
|
|
40
|
+
);
|
|
41
|
+
}}
|
|
42
|
+
</BrowserOnly>
|
|
30
43
|
);
|
|
31
44
|
};
|
|
32
45
|
|
|
@@ -13,6 +13,7 @@ export interface Props {
|
|
|
13
13
|
const Graphics = (props: Props) => {
|
|
14
14
|
const store = useStore();
|
|
15
15
|
const codeId = useScript(store, 'codeId');
|
|
16
|
+
const graphicsModalExecutionNr = useScript(store, 'graphicsModalExecutionNr');
|
|
16
17
|
const nodeRef = React.useRef(null);
|
|
17
18
|
return (
|
|
18
19
|
<Draggable onStop={checkForButtonClick} positionOffset={{ x: '15%', y: '25%' }} nodeRef={nodeRef}>
|
|
@@ -31,7 +32,11 @@ const Graphics = (props: Props) => {
|
|
|
31
32
|
iconSize="12px"
|
|
32
33
|
/>
|
|
33
34
|
</div>
|
|
34
|
-
<div
|
|
35
|
+
<div
|
|
36
|
+
id={DOM_ELEMENT_IDS.graphicsResult(codeId)}
|
|
37
|
+
className="brython-graphics-result"
|
|
38
|
+
key={`exec-${graphicsModalExecutionNr}`}
|
|
39
|
+
>
|
|
35
40
|
{props.main}
|
|
36
41
|
</div>
|
|
37
42
|
</div>
|
|
@@ -32,7 +32,7 @@ const Editor = (props: Props) => {
|
|
|
32
32
|
const codeId = useScript(store, 'codeId');
|
|
33
33
|
const hasCanvasOutput = useScript(store, 'hasCanvasOutput');
|
|
34
34
|
const hasTurtleOutput = useScript(store, 'hasTurtleOutput');
|
|
35
|
-
const
|
|
35
|
+
const graphicsModalExecutionNr = useScript(store, 'graphicsModalExecutionNr');
|
|
36
36
|
|
|
37
37
|
return (
|
|
38
38
|
<React.Fragment>
|
|
@@ -57,7 +57,7 @@ const Editor = (props: Props) => {
|
|
|
57
57
|
<>
|
|
58
58
|
<Result />
|
|
59
59
|
<div id={DOM_ELEMENT_IDS.outputDiv(codeId)}></div>
|
|
60
|
-
{
|
|
60
|
+
{graphicsModalExecutionNr > 0 && (
|
|
61
61
|
<>
|
|
62
62
|
{hasTurtleOutput && <Turtle />}
|
|
63
63
|
{hasCanvasOutput && <Canvas />}
|
|
@@ -3,6 +3,8 @@ import { usePluginData } from '@docusaurus/useGlobalData';
|
|
|
3
3
|
import { type InitState, type Document } from '@theme/CodeEditor/WithScript/Types';
|
|
4
4
|
import { createStore } from '@theme/CodeEditor/WithScript/createStore';
|
|
5
5
|
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
6
|
+
import BrowserOnly from '@docusaurus/BrowserOnly';
|
|
7
|
+
import CodeBlock from '@theme/CodeBlock';
|
|
6
8
|
export const Context = React.createContext<Document | undefined>(undefined);
|
|
7
9
|
|
|
8
10
|
const ScriptContext = (props: InitState & { children: React.ReactNode }) => {
|
|
@@ -19,11 +21,16 @@ const ScriptContext = (props: InitState & { children: React.ReactNode }) => {
|
|
|
19
21
|
store.load();
|
|
20
22
|
}, [props.id, libDir, siteConfig]);
|
|
21
23
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
return (
|
|
25
|
+
<BrowserOnly fallback={<CodeBlock language={props.lang}>{props.code}</CodeBlock>}>
|
|
26
|
+
{() => {
|
|
27
|
+
if (!store) {
|
|
28
|
+
return <div>Load</div>;
|
|
29
|
+
}
|
|
30
|
+
return <Context.Provider value={store}>{props.children}</Context.Provider>;
|
|
31
|
+
}}
|
|
32
|
+
</BrowserOnly>
|
|
33
|
+
);
|
|
27
34
|
};
|
|
28
35
|
|
|
29
36
|
export default ScriptContext;
|
|
@@ -33,7 +33,7 @@ export interface Script extends StoredScript {
|
|
|
33
33
|
postCode: string;
|
|
34
34
|
lang: 'py' | string;
|
|
35
35
|
logs: LogMessage[];
|
|
36
|
-
|
|
36
|
+
graphicsModalExecutionNr: number;
|
|
37
37
|
hasGraphicsOutput: boolean;
|
|
38
38
|
hasTurtleOutput: boolean;
|
|
39
39
|
hasCanvasOutput: boolean;
|
|
@@ -23,7 +23,7 @@ export const runCode = (
|
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
25
|
const active = document.getElementById(DOM_ELEMENT_IDS.communicator(codeId));
|
|
26
|
-
active
|
|
26
|
+
active!.setAttribute('data--start-time', `${Date.now()}`);
|
|
27
27
|
/**
|
|
28
28
|
* ensure that the script is executed after the current event loop.
|
|
29
29
|
* Otherwise, the brython script will not be able to access the graphics output.
|
|
@@ -139,7 +139,7 @@ export const createStore = (
|
|
|
139
139
|
setState((s) => ({
|
|
140
140
|
...s,
|
|
141
141
|
isExecuting: true,
|
|
142
|
-
|
|
142
|
+
graphicsModalExecutionNr: state.hasGraphicsOutput ? state.graphicsModalExecutionNr + 1 : 0
|
|
143
143
|
}));
|
|
144
144
|
runCode(state.code, state.preCode, state.postCode, codeId, libDir, router);
|
|
145
145
|
};
|
|
@@ -200,7 +200,7 @@ export const createStore = (
|
|
|
200
200
|
setState((s) => ({ ...s, logs: [] }));
|
|
201
201
|
};
|
|
202
202
|
const closeGraphicsModal = () => {
|
|
203
|
-
setState((s) => ({ ...s,
|
|
203
|
+
setState((s) => ({ ...s, graphicsModalExecutionNr: 0 }));
|
|
204
204
|
};
|
|
205
205
|
const stopScript = () => {
|
|
206
206
|
const code = document.getElementById(DOM_ELEMENT_IDS.communicator(state.codeId));
|
|
@@ -216,7 +216,7 @@ export const createStore = (
|
|
|
216
216
|
pristineCode: codeData.code,
|
|
217
217
|
isExecuting: false,
|
|
218
218
|
logs: [],
|
|
219
|
-
|
|
219
|
+
graphicsModalExecutionNr: 0,
|
|
220
220
|
hasEdits: false,
|
|
221
221
|
createdAt: createdAt,
|
|
222
222
|
isLoaded: false,
|
|
@@ -6,6 +6,7 @@ import clsx from 'clsx';
|
|
|
6
6
|
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
7
7
|
import BrowserOnly from '@docusaurus/BrowserOnly';
|
|
8
8
|
import CodeHistory from '@theme/CodeEditor/CodeHistory';
|
|
9
|
+
import CodeBlock from '@theme/CodeBlock';
|
|
9
10
|
|
|
10
11
|
export interface MetaProps {
|
|
11
12
|
reference?: boolean;
|
|
@@ -45,7 +46,7 @@ const CodeEditor = (props: Props) => {
|
|
|
45
46
|
const store = useStore();
|
|
46
47
|
const lang = useScript(store, 'lang');
|
|
47
48
|
return (
|
|
48
|
-
<BrowserOnly fallback={<
|
|
49
|
+
<BrowserOnly fallback={<CodeBlock language={props.lang}>{props.code}</CodeBlock>}>
|
|
49
50
|
{() => {
|
|
50
51
|
return (
|
|
51
52
|
<div className={clsx(styles.wrapper, 'notranslate', props.className)}>
|