docusaurus-live-brython 3.0.0-beta.13 → 3.0.0-beta.15
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/lib/options.d.ts +0 -5
- package/lib/options.d.ts.map +1 -1
- package/lib/theme/CodeBlock/index.d.ts +1 -1
- package/lib/theme/CodeEditor/Actions/DownloadCode.jsx +5 -5
- package/lib/theme/CodeEditor/Actions/Reset.jsx +3 -3
- package/lib/theme/CodeEditor/Actions/RunCode.jsx +3 -3
- package/lib/theme/CodeEditor/Actions/ShowRaw.jsx +3 -3
- package/lib/theme/CodeEditor/Actions/ShowSyncStatus.jsx +4 -4
- package/lib/theme/CodeEditor/BrythonCommunicator.jsx +3 -3
- package/lib/theme/CodeEditor/CodeHistory/index.jsx +5 -5
- package/lib/theme/CodeEditor/ContextEditor/index.jsx +1 -1
- package/lib/theme/CodeEditor/Editor/EditorAce.jsx +7 -7
- package/lib/theme/CodeEditor/Editor/Header/index.jsx +4 -4
- package/lib/theme/CodeEditor/Editor/Result/Graphics/Canvas.jsx +3 -3
- package/lib/theme/CodeEditor/Editor/Result/Graphics/Turtle.jsx +4 -4
- package/lib/theme/CodeEditor/Editor/Result/Graphics/index.jsx +3 -3
- package/lib/theme/CodeEditor/Editor/Result/index.jsx +3 -3
- package/lib/theme/CodeEditor/Editor/index.jsx +7 -7
- package/lib/theme/CodeEditor/WithScript/ScriptContext.d.ts +10 -0
- package/lib/theme/CodeEditor/WithScript/ScriptContext.d.ts.map +1 -0
- package/lib/theme/CodeEditor/WithScript/ScriptContext.jsx +20 -0
- package/lib/theme/CodeEditor/WithScript/Store.d.ts.map +1 -1
- 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.d.ts +2 -2
- package/lib/theme/CodeEditor/WithScript/createStore.d.ts.map +1 -1
- package/lib/theme/CodeEditor/WithScript/createStore.js +4 -4
- package/lib/theme/CodeEditor/WithScript/helpers.d.ts +1 -1
- package/lib/theme/CodeEditor/WithScript/helpers.d.ts.map +1 -1
- package/lib/theme/CodeEditor/WithScript/helpers.js +1 -1
- package/lib/theme/CodeEditor/hooks/index.d.ts +2 -2
- package/lib/theme/CodeEditor/hooks/index.d.ts.map +1 -1
- package/lib/theme/CodeEditor/hooks/index.js +2 -2
- package/lib/theme/CodeEditor/hooks/useSScript.d.ts +3 -0
- package/lib/theme/CodeEditor/hooks/useSScript.d.ts.map +1 -0
- package/lib/theme/CodeEditor/hooks/useSScript.js +4 -0
- package/lib/theme/CodeEditor/hooks/useSStore.d.ts +5 -0
- package/lib/theme/CodeEditor/hooks/useSStore.d.ts.map +1 -0
- package/lib/theme/CodeEditor/hooks/useSStore.js +10 -0
- package/lib/theme/CodeEditor/hooks/useScript.d.ts +2 -4
- package/lib/theme/CodeEditor/hooks/useScript.d.ts.map +1 -1
- package/lib/theme/CodeEditor/hooks/useScript.js +4 -10
- package/lib/theme/CodeEditor/hooks/useStore.d.ts +4 -2
- package/lib/theme/CodeEditor/hooks/useStore.d.ts.map +1 -1
- package/lib/theme/CodeEditor/hooks/useStore.js +10 -4
- package/lib/theme/CodeEditor/index.jsx +3 -3
- package/package.json +2 -2
- package/src/theme/CodeBlock/index.tsx +1 -1
- package/src/theme/CodeEditor/Actions/DownloadCode.tsx +5 -5
- package/src/theme/CodeEditor/Actions/Reset.tsx +3 -3
- package/src/theme/CodeEditor/Actions/RunCode.tsx +3 -3
- package/src/theme/CodeEditor/Actions/ShowRaw.tsx +3 -3
- package/src/theme/CodeEditor/Actions/ShowSyncStatus.tsx +4 -4
- package/src/theme/CodeEditor/BrythonCommunicator.tsx +3 -3
- package/src/theme/CodeEditor/CodeHistory/index.tsx +5 -5
- package/src/theme/CodeEditor/ContextEditor/index.tsx +1 -1
- package/src/theme/CodeEditor/Editor/EditorAce.tsx +7 -7
- package/src/theme/CodeEditor/Editor/Header/index.tsx +4 -4
- package/src/theme/CodeEditor/Editor/Result/Graphics/Canvas.tsx +3 -3
- package/src/theme/CodeEditor/Editor/Result/Graphics/Turtle.tsx +4 -4
- package/src/theme/CodeEditor/Editor/Result/Graphics/index.tsx +3 -3
- package/src/theme/CodeEditor/Editor/Result/index.tsx +3 -3
- package/src/theme/CodeEditor/Editor/index.tsx +7 -7
- package/src/theme/CodeEditor/WithScript/{Store.tsx → ScriptContext.tsx} +3 -3
- package/src/theme/CodeEditor/WithScript/Types.ts +1 -1
- package/src/theme/CodeEditor/WithScript/createStore.ts +7 -7
- package/src/theme/CodeEditor/WithScript/helpers.ts +1 -1
- package/src/theme/CodeEditor/hooks/index.ts +2 -2
- package/src/theme/CodeEditor/hooks/useScript.ts +7 -13
- package/src/theme/CodeEditor/hooks/useStore.ts +13 -7
- package/src/theme/CodeEditor/index.tsx +3 -3
package/lib/options.d.ts
CHANGED
|
@@ -41,10 +41,5 @@ export type ThemeOptions = {
|
|
|
41
41
|
};
|
|
42
42
|
export type Options = Partial<ThemeOptions>;
|
|
43
43
|
export declare const DEFAULT_OPTIONS: ThemeOptions;
|
|
44
|
-
export type ThemeData = {
|
|
45
|
-
libDir: string;
|
|
46
|
-
syncMaxOnceEvery: number;
|
|
47
|
-
isHashRouter: boolean;
|
|
48
|
-
};
|
|
49
44
|
export declare function validateThemeConfig({ themeConfig, validate }: ThemeConfigValidationContext<Options, ThemeOptions>): ThemeOptions;
|
|
50
45
|
//# sourceMappingURL=options.d.ts.map
|
package/lib/options.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAC,4BAA4B,EAAC,MAAM,mBAAmB,CAAC;AAEpE,MAAM,MAAM,YAAY,GAAG;IACvB;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,gBAAgB,EAAE,MAAM,CAAC;IACzB;;;;;;;OAOG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,sBAAsB,EAAE,OAAO,CAAC;IAChC;;;;OAIG;IACH,gBAAgB,EAAE,MAAM,CAAC;CAC5B,CAAA;AAGD,MAAM,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AAE5C,eAAO,MAAM,eAAe,EAAE,YAM7B,CAAC;
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAC,4BAA4B,EAAC,MAAM,mBAAmB,CAAC;AAEpE,MAAM,MAAM,YAAY,GAAG;IACvB;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,gBAAgB,EAAE,MAAM,CAAC;IACzB;;;;;;;OAOG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,sBAAsB,EAAE,OAAO,CAAC;IAChC;;;;OAIG;IACH,gBAAgB,EAAE,MAAM,CAAC;CAC5B,CAAA;AAGD,MAAM,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AAE5C,eAAO,MAAM,eAAe,EAAE,YAM7B,CAAC;AAUF,wBAAgB,mBAAmB,CAC/B,EAAC,WAAW,EAAE,QAAQ,EAAC,EAAE,4BAA4B,CAAC,OAAO,EAAE,YAAY,CAAC,GAC7E,YAAY,CAGd"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/// <reference types="@docusaurus/module-type-aliases" />
|
|
2
1
|
/// <reference types="react" />
|
|
2
|
+
/// <reference types="@docusaurus/module-type-aliases" />
|
|
3
3
|
import { type Props as CodeBlockType } from '@theme-init/CodeBlock';
|
|
4
4
|
import type { WrapperProps } from '@docusaurus/types';
|
|
5
5
|
type Props = WrapperProps<typeof CodeBlockType>;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
3
3
|
import Button from '@theme/CodeEditor/Button';
|
|
4
4
|
import { translate } from '@docusaurus/Translate';
|
|
5
5
|
const DownloadCode = (props) => {
|
|
6
|
-
const { store } =
|
|
7
|
-
const code =
|
|
8
|
-
const lang =
|
|
9
|
-
const id =
|
|
6
|
+
const { store } = useStore();
|
|
7
|
+
const code = useScript(store, (state) => state.code);
|
|
8
|
+
const lang = useScript(store, (state) => state.lang);
|
|
9
|
+
const id = useScript(store, (state) => state.id);
|
|
10
10
|
return (<Button icon='Download' onClick={() => {
|
|
11
11
|
const downloadLink = document.createElement("a");
|
|
12
12
|
const file = new Blob([code], { type: 'text/plain;charset=utf-8' });
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
3
3
|
import Button from '@theme/CodeEditor/Button';
|
|
4
4
|
import { translate } from '@docusaurus/Translate';
|
|
5
5
|
const Reset = () => {
|
|
6
|
-
const { store } =
|
|
7
|
-
const pristine =
|
|
6
|
+
const { store } = useStore();
|
|
7
|
+
const pristine = useScript(store, (state) => state.pristineCode);
|
|
8
8
|
const onReset = () => {
|
|
9
9
|
const shouldReset = window.confirm(translate({
|
|
10
10
|
message: 'Discard your edits? Your changes will be lost!'
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
3
3
|
import Button, { Color } from '@theme/CodeEditor/Button';
|
|
4
4
|
import { translate } from '@docusaurus/Translate';
|
|
5
5
|
import styles from './styles.module.css';
|
|
6
6
|
import clsx from 'clsx';
|
|
7
7
|
const RunCode = (props) => {
|
|
8
|
-
const { store } =
|
|
9
|
-
const isExecuting =
|
|
8
|
+
const { store } = useStore();
|
|
9
|
+
const isExecuting = useScript(store, (state) => state.isExecuting);
|
|
10
10
|
return (<Button icon={isExecuting ? 'Python' : 'Play'} spin={isExecuting} color={Color.Success} className={clsx(styles.runCode, props.slim && styles.slim)} iconSize={props.slim ? '1.2em' : '1.6em'} onClick={() => {
|
|
11
11
|
store.execScript();
|
|
12
12
|
}} title={translate({
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
3
3
|
import Button, { Color } from '@theme/CodeEditor/Button';
|
|
4
4
|
import { translate } from '@docusaurus/Translate';
|
|
5
5
|
const ShowRaw = () => {
|
|
6
|
-
const { store } =
|
|
7
|
-
const showRaw =
|
|
6
|
+
const { store } = useStore();
|
|
7
|
+
const showRaw = useScript(store, (state) => state.showRaw);
|
|
8
8
|
return (<Button icon={showRaw ? 'EditCode' : 'Code'} onClick={() => store.setState((state) => ({ ...state, showRaw: !showRaw }))} color={showRaw ? Color.Primary : Color.Secondary} title={showRaw
|
|
9
9
|
? translate({ message: 'Show edited Code', id: 'theme.CodeEditor.Actions.ShowCode.showEdited' })
|
|
10
10
|
: translate({ message: 'Show initial code', id: 'theme.CodeEditor.Actions.ShowCode.showRaw' })}/>);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
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
5
|
const ShowSyncStatus = () => {
|
|
6
|
-
const { store } =
|
|
7
|
-
const isLoaded =
|
|
8
|
-
const status =
|
|
6
|
+
const { store } = useStore();
|
|
7
|
+
const isLoaded = useScript(store, (state) => state.isLoaded);
|
|
8
|
+
const status = useScript(store, (state) => state.status);
|
|
9
9
|
React.useEffect(() => {
|
|
10
10
|
if (status !== Status.IDLE) {
|
|
11
11
|
const disposer = setTimeout(() => {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { BRYTHON_NOTIFICATION_EVENT, DOM_ELEMENT_IDS } from "@theme/CodeEditor/constants";
|
|
3
|
-
import {
|
|
3
|
+
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
4
4
|
const BrythonCommunicator = () => {
|
|
5
|
-
const { store } =
|
|
6
|
-
const codeId =
|
|
5
|
+
const { store } = useStore();
|
|
6
|
+
const codeId = useScript(store, (state) => state.codeId);
|
|
7
7
|
const ref = React.useRef(null);
|
|
8
8
|
React.useEffect(() => {
|
|
9
9
|
const { current } = ref;
|
|
@@ -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
9
|
import Button from '@theme/CodeEditor/Button';
|
|
10
|
-
import DiffViewer from 'react-diff-viewer';
|
|
10
|
+
import DiffViewer from 'react-diff-viewer-continued';
|
|
11
11
|
import Details from '@theme/Details';
|
|
12
12
|
const highlightSyntax = (str) => {
|
|
13
13
|
if (!str) {
|
|
@@ -19,9 +19,9 @@ const highlightSyntax = (str) => {
|
|
|
19
19
|
};
|
|
20
20
|
const CodeHistory = () => {
|
|
21
21
|
const [version, setVersion] = React.useState(1);
|
|
22
|
-
const { store } =
|
|
23
|
-
const versions =
|
|
24
|
-
const versionsLoaded =
|
|
22
|
+
const { store } = useStore();
|
|
23
|
+
const versions = useScript(store, (state) => state.versions);
|
|
24
|
+
const versionsLoaded = useScript(store, (state) => state.versionsLoaded);
|
|
25
25
|
if (versions?.length < 2) {
|
|
26
26
|
return null;
|
|
27
27
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
|
|
3
3
|
import CodeEditor from '@theme/CodeEditor';
|
|
4
|
-
import ScriptContext from '@theme/CodeEditor/WithScript/
|
|
4
|
+
import ScriptContext from '@theme/CodeEditor/WithScript/ScriptContext';
|
|
5
5
|
import CodeBlock from '@theme/CodeBlock';
|
|
6
6
|
/**
|
|
7
7
|
* Use this component when you want a working CodeEditor.
|
|
@@ -10,18 +10,18 @@ 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
|
const ALIAS_LANG_MAP_ACE = {
|
|
15
15
|
mpy: 'python',
|
|
16
16
|
};
|
|
17
17
|
const EditorAce = (props) => {
|
|
18
18
|
const eRef = React.useRef(null);
|
|
19
|
-
const { store } =
|
|
20
|
-
const code =
|
|
21
|
-
const pristineCode =
|
|
22
|
-
const lang =
|
|
23
|
-
const codeId =
|
|
24
|
-
const showRaw =
|
|
19
|
+
const { store } = useStore();
|
|
20
|
+
const code = useScript(store, (state) => state.code);
|
|
21
|
+
const pristineCode = useScript(store, (state) => state.pristineCode);
|
|
22
|
+
const lang = useScript(store, (state) => state.lang);
|
|
23
|
+
const codeId = useScript(store, (state) => state.codeId);
|
|
24
|
+
const showRaw = useScript(store, (state) => state.showRaw);
|
|
25
25
|
React.useEffect(() => {
|
|
26
26
|
if (eRef && eRef.current) {
|
|
27
27
|
const node = eRef.current;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import clsx from 'clsx';
|
|
3
3
|
import styles from './styles.module.css';
|
|
4
|
-
import {
|
|
4
|
+
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
5
5
|
import ShowSyncStatus from '@theme/CodeEditor/Actions/ShowSyncStatus';
|
|
6
6
|
import Reset from '@theme/CodeEditor/Actions/Reset';
|
|
7
7
|
import DownloadCode from '@theme/CodeEditor/Actions/DownloadCode';
|
|
8
8
|
import ShowRaw from '@theme/CodeEditor/Actions/ShowRaw';
|
|
9
9
|
import RunCode from '@theme/CodeEditor/Actions/RunCode';
|
|
10
10
|
const Header = (props) => {
|
|
11
|
-
const { store } =
|
|
12
|
-
const hasEdits =
|
|
13
|
-
const lang =
|
|
11
|
+
const { store } = useStore();
|
|
12
|
+
const hasEdits = useScript(store, (state) => state.hasEdits);
|
|
13
|
+
const lang = useScript(store, (state) => state.lang);
|
|
14
14
|
return (<div className={clsx(styles.controls, props.slim && styles.slim)}>
|
|
15
15
|
{!props.slim && (<React.Fragment>
|
|
16
16
|
<div className={styles.title}>{props.title}</div>
|
|
@@ -2,7 +2,7 @@ import * as React from 'react';
|
|
|
2
2
|
import { DOM_ELEMENT_IDS } from '@theme/CodeEditor/constants';
|
|
3
3
|
import Graphics from '@theme/CodeEditor/Editor/Result/Graphics';
|
|
4
4
|
import styles from './styles.module.css';
|
|
5
|
-
import {
|
|
5
|
+
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
6
6
|
import Button from '@theme/CodeEditor/Button';
|
|
7
7
|
const downloadCanvas = (canvasId) => {
|
|
8
8
|
const canvas = document.getElementById(canvasId);
|
|
@@ -22,9 +22,9 @@ const downloadCanvas = (canvasId) => {
|
|
|
22
22
|
document.body.removeChild(downloadLink);
|
|
23
23
|
};
|
|
24
24
|
const Canvas = () => {
|
|
25
|
-
const { store } =
|
|
25
|
+
const { store } = useStore();
|
|
26
26
|
// const { codeId } = useStore(store, (state) => ({codeId: state.codeId}));
|
|
27
|
-
const codeId =
|
|
27
|
+
const codeId = useScript(store, (state) => state.codeId);
|
|
28
28
|
return (<Graphics controls={<Button icon='Download' iconSize='12px' onClick={() => {
|
|
29
29
|
downloadCanvas(DOM_ELEMENT_IDS.canvasContainer(codeId));
|
|
30
30
|
}} title="Download SVG" className={styles.slimStrippedButton}/>} main={<canvas id={DOM_ELEMENT_IDS.canvasContainer(codeId)} width="500" height="500" style={{
|
|
@@ -3,13 +3,13 @@ import styles from './styles.module.css';
|
|
|
3
3
|
import { DOM_ELEMENT_IDS } from '@theme/CodeEditor/constants';
|
|
4
4
|
import Graphics from '@theme/CodeEditor/Editor/Result/Graphics';
|
|
5
5
|
import { saveSvg } from '@theme/CodeEditor/Editor/utils/saveSvg';
|
|
6
|
-
import {
|
|
6
|
+
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
7
7
|
import Button from '@theme/CodeEditor/Button';
|
|
8
8
|
import clsx from 'clsx';
|
|
9
9
|
const Turtle = () => {
|
|
10
|
-
const { store } =
|
|
11
|
-
const codeId =
|
|
12
|
-
const code =
|
|
10
|
+
const { store } = useStore();
|
|
11
|
+
const codeId = useScript(store, (state) => state.codeId);
|
|
12
|
+
const code = useScript(store, (state) => state.code);
|
|
13
13
|
return (<Graphics controls={<React.Fragment>
|
|
14
14
|
<Button icon='AnimationPlay' onClick={() => {
|
|
15
15
|
const turtleResult = document.getElementById(DOM_ELEMENT_IDS.turtleSvgContainer(codeId));
|
|
@@ -3,12 +3,12 @@ import styles from './styles.module.css';
|
|
|
3
3
|
import { DOM_ELEMENT_IDS } from '@theme/CodeEditor/constants';
|
|
4
4
|
import Draggable from 'react-draggable';
|
|
5
5
|
import { checkForButtonClick } from '@theme/CodeEditor/Editor/utils/checkForButtonClick';
|
|
6
|
-
import {
|
|
6
|
+
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
7
7
|
import Button from '@theme/CodeEditor/Button';
|
|
8
8
|
import clsx from 'clsx';
|
|
9
9
|
const Graphics = (props) => {
|
|
10
|
-
const { store } =
|
|
11
|
-
const codeId =
|
|
10
|
+
const { store } = useStore();
|
|
11
|
+
const codeId = useScript(store, (state) => state.codeId);
|
|
12
12
|
return (<Draggable onStop={checkForButtonClick} positionOffset={{ x: 0, y: '-50%' }}>
|
|
13
13
|
<div className={styles.brythonGraphicsResult}>
|
|
14
14
|
<div className={styles.brythonGraphicsResultHead}>
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import styles from './styles.module.css';
|
|
3
3
|
import CodeBlock from '@theme/CodeBlock';
|
|
4
|
-
import {
|
|
4
|
+
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
5
5
|
const Result = () => {
|
|
6
|
-
const { store } =
|
|
7
|
-
const logs =
|
|
6
|
+
const { store } = useStore();
|
|
7
|
+
const logs = useScript(store, (state) => state.logs);
|
|
8
8
|
if (logs.length === 0) {
|
|
9
9
|
return null;
|
|
10
10
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { DOM_ELEMENT_IDS, } from "@theme/CodeEditor/constants";
|
|
3
|
-
import {
|
|
3
|
+
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
4
4
|
import Result from "@theme/CodeEditor/Editor/Result";
|
|
5
5
|
import Turtle from "@theme/CodeEditor/Editor/Result/Graphics/Turtle";
|
|
6
6
|
import Canvas from "@theme/CodeEditor/Editor/Result/Graphics/Canvas";
|
|
@@ -8,12 +8,12 @@ import Graphics from "@theme/CodeEditor/Editor/Result/Graphics";
|
|
|
8
8
|
import Header from "@theme/CodeEditor/Editor/Header";
|
|
9
9
|
import EditorAce from "@theme/CodeEditor/Editor/EditorAce";
|
|
10
10
|
const Editor = (props) => {
|
|
11
|
-
const { store } =
|
|
12
|
-
const lang =
|
|
13
|
-
const codeId =
|
|
14
|
-
const hasCanvasOutput =
|
|
15
|
-
const hasTurtleOutput =
|
|
16
|
-
const isGraphicsmodalOpen =
|
|
11
|
+
const { store } = useStore();
|
|
12
|
+
const lang = useScript(store, (state) => state.lang);
|
|
13
|
+
const codeId = useScript(store, (state) => state.codeId);
|
|
14
|
+
const hasCanvasOutput = useScript(store, (state) => state.hasCanvasOutput);
|
|
15
|
+
const hasTurtleOutput = useScript(store, (state) => state.hasTurtleOutput);
|
|
16
|
+
const isGraphicsmodalOpen = useScript(store, (state) => state.isGraphicsmodalOpen);
|
|
17
17
|
return (<React.Fragment>
|
|
18
18
|
<Header slim={props.slim} title={props.title} resettable={props.resettable} download={props.download} noCompare={props.noCompare}/>
|
|
19
19
|
<EditorAce showLineNumbers={props.showLineNumbers} maxLines={props.maxLines} versioned={props.versioned}/>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { type InitState, type Document } from "@theme/CodeEditor/WithScript/Types";
|
|
3
|
+
export declare const Context: React.Context<{
|
|
4
|
+
store: Document;
|
|
5
|
+
}>;
|
|
6
|
+
declare const ScriptContext: (props: InitState & {
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
}) => React.JSX.Element;
|
|
9
|
+
export default ScriptContext;
|
|
10
|
+
//# sourceMappingURL=ScriptContext.d.ts.map
|
|
@@ -0,0 +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;AAEnF,eAAO,MAAM,OAAO;WAA+B,QAAQ;EAAyB,CAAC;AAErF,QAAA,MAAM,aAAa,UAAW,SAAS,GAAG;IAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;CAAE,sBAkBvE,CAAA;AAED,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { usePluginData } from "@docusaurus/useGlobalData";
|
|
3
|
+
import { createStore } from "@theme/CodeEditor/WithScript/createStore";
|
|
4
|
+
export const Context = React.createContext(undefined);
|
|
5
|
+
const ScriptContext = (props) => {
|
|
6
|
+
const { libDir, syncMaxOnceEvery } = usePluginData('docusaurus-live-brython');
|
|
7
|
+
const [store, setStore] = React.useState(null);
|
|
8
|
+
React.useEffect(() => {
|
|
9
|
+
const store = createStore(props, libDir, syncMaxOnceEvery);
|
|
10
|
+
setStore(store);
|
|
11
|
+
store.load();
|
|
12
|
+
}, [props.id, libDir]);
|
|
13
|
+
if (!store) {
|
|
14
|
+
return <div>Load</div>;
|
|
15
|
+
}
|
|
16
|
+
return (<Context.Provider value={{ store: store }}>
|
|
17
|
+
{props.children}
|
|
18
|
+
</Context.Provider>);
|
|
19
|
+
};
|
|
20
|
+
export default ScriptContext;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Store.d.ts","sourceRoot":"","sources":["../../../../src/theme/CodeEditor/WithScript/Store.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,KAAK,EAAE,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"Store.d.ts","sourceRoot":"","sources":["../../../../src/theme/CodeEditor/WithScript/Store.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,KAAK,EAAE,MAAM,oCAAoC,CAAC;AAEhF,eAAO,MAAM,OAAO;WAA+B,KAAK;EAAyB,CAAC;AAElF,QAAA,MAAM,aAAa,UAAW,SAAS,GAAG;IAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;CAAE,sBAkBvE,CAAA;AAED,eAAe,aAAa,CAAC"}
|
|
@@ -68,7 +68,7 @@ export interface InitState {
|
|
|
68
68
|
readonly: boolean;
|
|
69
69
|
versioned: boolean;
|
|
70
70
|
}
|
|
71
|
-
export interface
|
|
71
|
+
export interface Document<T = Script> {
|
|
72
72
|
getState: () => T;
|
|
73
73
|
setState: (fn: (state: Script) => Script) => void;
|
|
74
74
|
subscribe: (listener: () => void) => () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Types.d.ts","sourceRoot":"","sources":["../../../../src/theme/CodeEditor/WithScript/Types.ts"],"names":[],"mappings":"AACA,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;IAChB,QAAQ,EAAE,OAAO,EAAE,CAAC;CACvB;AAED,MAAM,MAAM,QAAQ,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC;AAC7C,MAAM,WAAW,MAAO,SAAQ,YAAY;IACxC;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IACX;;;;;;OAMG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,IAAI,GAAG,MAAM,CAAC;IACpB,IAAI,EAAE,UAAU,EAAE,CAAC;IACnB,mBAAmB,EAAE,OAAO,CAAC;IAC7B,iBAAiB,EAAE,OAAO,CAAC;IAC3B,eAAe,EAAE,OAAO,CAAC;IACzB,eAAe,EAAE,OAAO,CAAC;IACzB,QAAQ,EAAE,OAAO,CAAC;IAClB;;MAEE;IACH,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,OAAO,CAAC;IACxB,QAAQ,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,UAAU;IACvB,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,CAAC;IAC7C,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,MAAM,WAAW,GAAG;IACtB,GAAG,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IACzB,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7B,GAAG,EAAE,MAAM,IAAI,CAAC;IAChB,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,KAAK,MAAM,IAAI,CAAC;CACnE,CAAC;AAEF,oBAAY,MAAM;IACd,IAAI,SAAS;IACb,OAAO,YAAY;IACnB,KAAK,UAAU;IACf,OAAO,YAAY;CACtB;AAED,MAAM,WAAW,SAAS;IACtB,EAAE,EAAE,MAAM,GAAG,SAAS,CAAC;IACvB,IAAI,EAAE,IAAI,GAAG,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"Types.d.ts","sourceRoot":"","sources":["../../../../src/theme/CodeEditor/WithScript/Types.ts"],"names":[],"mappings":"AACA,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;IAChB,QAAQ,EAAE,OAAO,EAAE,CAAC;CACvB;AAED,MAAM,MAAM,QAAQ,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC;AAC7C,MAAM,WAAW,MAAO,SAAQ,YAAY;IACxC;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IACX;;;;;;OAMG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,IAAI,GAAG,MAAM,CAAC;IACpB,IAAI,EAAE,UAAU,EAAE,CAAC;IACnB,mBAAmB,EAAE,OAAO,CAAC;IAC7B,iBAAiB,EAAE,OAAO,CAAC;IAC3B,eAAe,EAAE,OAAO,CAAC;IACzB,eAAe,EAAE,OAAO,CAAC;IACzB,QAAQ,EAAE,OAAO,CAAC;IAClB;;MAEE;IACH,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,OAAO,CAAC;IACxB,QAAQ,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,UAAU;IACvB,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,CAAC;IAC7C,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,MAAM,WAAW,GAAG;IACtB,GAAG,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IACzB,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7B,GAAG,EAAE,MAAM,IAAI,CAAC;IAChB,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,KAAK,MAAM,IAAI,CAAC;CACnE,CAAC;AAEF,oBAAY,MAAM;IACd,IAAI,SAAS;IACb,OAAO,YAAY;IACnB,KAAK,UAAU;IACf,OAAO,YAAY;CACtB;AAED,MAAM,WAAW,SAAS;IACtB,EAAE,EAAE,MAAM,GAAG,SAAS,CAAC;IACvB,IAAI,EAAE,IAAI,GAAG,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,OAAO,CAAC;IAClB,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;CACrC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { type InitState, type
|
|
2
|
-
export declare const createStore: (props: InitState, libDir: string, syncMaxOnceEvery: number) =>
|
|
1
|
+
import { type InitState, type Document } from "@theme/CodeEditor/WithScript/Types";
|
|
2
|
+
export declare const createStore: (props: InitState, libDir: string, syncMaxOnceEvery: number) => Document;
|
|
3
3
|
//# sourceMappingURL=createStore.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createStore.d.ts","sourceRoot":"","sources":["../../../../src/theme/CodeEditor/WithScript/createStore.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,SAAS,EAAwC,KAAK,
|
|
1
|
+
{"version":3,"file":"createStore.d.ts","sourceRoot":"","sources":["../../../../src/theme/CodeEditor/WithScript/createStore.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,SAAS,EAAwC,KAAK,QAAQ,EAAmC,MAAM,oCAAoC,CAAC;AAI1J,eAAO,MAAM,WAAW,UAAW,SAAS,UAAU,MAAM,oBAAoB,MAAM,KAAG,QA8OxF,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { v4 as uuidv4 } from 'uuid';
|
|
2
2
|
import { createStorageSlot } from "@docusaurus/theme-common";
|
|
3
3
|
import { getStorageScript, syncStorageScript } from "@theme/CodeEditor/WithScript/Storage";
|
|
4
|
-
import { checkCanvasOutput, checkGraphicsOutput, checkTurtleOutput,
|
|
4
|
+
import { checkCanvasOutput, checkGraphicsOutput, checkTurtleOutput, splitPreCode as splitPreCode, sanitizePyScript } from "@theme/CodeEditor/WithScript/helpers";
|
|
5
5
|
import { Status } from "@theme/CodeEditor/WithScript/Types";
|
|
6
6
|
import { DOM_ELEMENT_IDS } from "@theme/CodeEditor/constants";
|
|
7
7
|
import throttle from 'lodash/throttle';
|
|
@@ -53,9 +53,9 @@ export const createStore = (props, libDir, syncMaxOnceEvery) => {
|
|
|
53
53
|
};
|
|
54
54
|
const prepareCode = (raw, config = {}) => {
|
|
55
55
|
const { pre, code } = config.codeOnly
|
|
56
|
-
? { pre:
|
|
57
|
-
:
|
|
58
|
-
const hasEdits = code !== (config.stateNotInitialized ?
|
|
56
|
+
? { pre: splitPreCode(state.pristineCode).pre, code: raw }
|
|
57
|
+
: splitPreCode(raw);
|
|
58
|
+
const hasEdits = code !== (config.stateNotInitialized ? splitPreCode(props.raw).code : state.pristineCode);
|
|
59
59
|
const updatedAt = new Date();
|
|
60
60
|
const hasCanvasOutput = checkCanvasOutput(raw);
|
|
61
61
|
const hasTurtleOutput = checkTurtleOutput(raw);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const checkGraphicsOutput: (raw: string) => boolean;
|
|
2
2
|
export declare const checkTurtleOutput: (raw: string) => boolean;
|
|
3
3
|
export declare const checkCanvasOutput: (raw: string) => boolean;
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const splitPreCode: (rawcode: string) => {
|
|
5
5
|
pre: string;
|
|
6
6
|
code: string;
|
|
7
7
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../../src/theme/CodeEditor/WithScript/helpers.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,mBAAmB,QAAS,MAAM,KAAG,OAEjD,CAAA;AAED,eAAO,MAAM,iBAAiB,QAAS,MAAM,KAAG,OAE/C,CAAA;AAED,eAAO,MAAM,iBAAiB,QAAS,MAAM,KAAG,OAE/C,CAAA;AAED,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../../src/theme/CodeEditor/WithScript/helpers.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,mBAAmB,QAAS,MAAM,KAAG,OAEjD,CAAA;AAED,eAAO,MAAM,iBAAiB,QAAS,MAAM,KAAG,OAE/C,CAAA;AAED,eAAO,MAAM,iBAAiB,QAAS,MAAM,KAAG,OAE/C,CAAA;AAED,eAAO,MAAM,YAAY,YAAa,MAAM;;;CAY3C,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,WAAY,MAAM,WAE9C,CAAA"}
|
|
@@ -11,7 +11,7 @@ export const checkTurtleOutput = (raw) => {
|
|
|
11
11
|
export const checkCanvasOutput = (raw) => {
|
|
12
12
|
return CANVAS_OUTPUT_TESTER.test(raw) || GRID_IMPORTS_TESTER.test(raw);
|
|
13
13
|
};
|
|
14
|
-
export const
|
|
14
|
+
export const splitPreCode = (rawcode) => {
|
|
15
15
|
const match = rawcode.match(/\n###\s*PRE.*?\n/);
|
|
16
16
|
if (match) {
|
|
17
17
|
return {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { useStore as useStore } from '@theme/CodeEditor/hooks/useStore';
|
|
2
|
+
export { useScript as useScript } from '@theme/CodeEditor/hooks/useScript';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/theme/CodeEditor/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/theme/CodeEditor/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,IAAI,QAAQ,EAAC,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAC,SAAS,IAAI,SAAS,EAAC,MAAM,mCAAmC,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { useStore as useStore } from '@theme/CodeEditor/hooks/useStore';
|
|
2
|
+
export { useScript as useScript } from '@theme/CodeEditor/hooks/useScript';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSScript.d.ts","sourceRoot":"","sources":["../../../../src/theme/CodeEditor/hooks/useSScript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,KAAK,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAG5E,eAAO,MAAM,UAAU,gBAAiB,SAAS,CAAC,CAAC,YAAY,SAAS,CAAC,EAAE,CAAC,CAAC,KAAG,CAK/E,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSStore.d.ts","sourceRoot":"","sources":["../../../../src/theme/CodeEditor/hooks/useSStore.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,KAAK,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAIlE,wBAAgB,SAAS,IAAI;IAAC,KAAK,EAAE,QAAQ,CAAA;CAAC,CAS7C"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Context } from "@theme/CodeEditor/WithScript/ScriptContext";
|
|
2
|
+
import { ReactContextError } from "@docusaurus/theme-common";
|
|
3
|
+
import { useContext } from "react";
|
|
4
|
+
export function useSStore() {
|
|
5
|
+
const context = useContext(Context);
|
|
6
|
+
if (context === null) {
|
|
7
|
+
throw new ReactContextError('ScriptContextProvider', 'The Component must be a child of the ScriptContextProvider component');
|
|
8
|
+
}
|
|
9
|
+
return context;
|
|
10
|
+
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
export declare
|
|
3
|
-
store: Store;
|
|
4
|
-
};
|
|
1
|
+
import { Selector, type Document } from "@theme/CodeEditor/WithScript/Types";
|
|
2
|
+
export declare const useScript: <T, R>(store: Document<T>, selector: Selector<T, R>) => R;
|
|
5
3
|
//# sourceMappingURL=useScript.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useScript.d.ts","sourceRoot":"","sources":["../../../../src/theme/CodeEditor/hooks/useScript.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useScript.d.ts","sourceRoot":"","sources":["../../../../src/theme/CodeEditor/hooks/useScript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,KAAK,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAG5E,eAAO,MAAM,SAAS,gBAAiB,SAAS,CAAC,CAAC,YAAY,SAAS,CAAC,EAAE,CAAC,CAAC,KAAG,CAK9E,CAAA"}
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const context = useContext(Context);
|
|
6
|
-
if (context === null) {
|
|
7
|
-
throw new ReactContextError('ScriptContextProvider', 'The Component must be a child of the ScriptContextProvider component');
|
|
8
|
-
}
|
|
9
|
-
return context;
|
|
10
|
-
}
|
|
1
|
+
import { useCallback, useSyncExternalStore } from "react";
|
|
2
|
+
export const useScript = (store, selector) => {
|
|
3
|
+
return useSyncExternalStore(store.subscribe, useCallback(() => selector(store.getState()), [store, selector]));
|
|
4
|
+
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare
|
|
1
|
+
import { type Document } from "@theme/CodeEditor/WithScript/Types";
|
|
2
|
+
export declare function useStore(): {
|
|
3
|
+
store: Document;
|
|
4
|
+
};
|
|
3
5
|
//# sourceMappingURL=useStore.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStore.d.ts","sourceRoot":"","sources":["../../../../src/theme/CodeEditor/hooks/useStore.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useStore.d.ts","sourceRoot":"","sources":["../../../../src/theme/CodeEditor/hooks/useStore.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,KAAK,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAIlE,wBAAgB,QAAQ,IAAI;IAAC,KAAK,EAAE,QAAQ,CAAA;CAAC,CAS5C"}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { Context } from "@theme/CodeEditor/WithScript/ScriptContext";
|
|
2
|
+
import { ReactContextError } from "@docusaurus/theme-common";
|
|
3
|
+
import { useContext } from "react";
|
|
4
|
+
export function useStore() {
|
|
5
|
+
const context = useContext(Context);
|
|
6
|
+
if (context === null) {
|
|
7
|
+
throw new ReactContextError('ScriptContextProvider', 'The Component must be a child of the ScriptContextProvider component');
|
|
8
|
+
}
|
|
9
|
+
return context;
|
|
10
|
+
}
|
|
@@ -3,12 +3,12 @@ import styles from './styles.module.css';
|
|
|
3
3
|
import Editor from '@theme/CodeEditor/Editor';
|
|
4
4
|
import BrythonCommunicator from '@theme/CodeEditor/BrythonCommunicator';
|
|
5
5
|
import clsx from 'clsx';
|
|
6
|
-
import {
|
|
6
|
+
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
7
7
|
import BrowserOnly from '@docusaurus/BrowserOnly';
|
|
8
8
|
import CodeHistory from '@theme/CodeEditor/CodeHistory';
|
|
9
9
|
const CodeEditor = (props) => {
|
|
10
|
-
const { store } =
|
|
11
|
-
const lang =
|
|
10
|
+
const { store } = useStore();
|
|
11
|
+
const lang = useScript(store, (state) => state.lang);
|
|
12
12
|
return (<BrowserOnly fallback={<div>Loading...</div>}>
|
|
13
13
|
{() => {
|
|
14
14
|
return (<div className={clsx(styles.wrapper, 'notranslate', props.className)}>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "docusaurus-live-brython",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.15",
|
|
4
4
|
"description": "Docusaurus live code block component for python.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -104,7 +104,7 @@
|
|
|
104
104
|
"prism-react-renderer": "^2.3.1",
|
|
105
105
|
"rc-slider": "^10.6.2",
|
|
106
106
|
"react-ace": "^11.0.1",
|
|
107
|
-
"react-diff-viewer": "^3.
|
|
107
|
+
"react-diff-viewer-continued": "^3.4.0",
|
|
108
108
|
"react-draggable": "^4.4.6",
|
|
109
109
|
"svg-parser": "^2.0.4",
|
|
110
110
|
"uuid": "^9.0.1"
|
|
@@ -4,7 +4,7 @@ import type { WrapperProps } from '@docusaurus/types';
|
|
|
4
4
|
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
|
|
5
5
|
import CodeEditor, { type MetaProps } from '@theme/CodeEditor';
|
|
6
6
|
|
|
7
|
-
import ScriptContext from '@theme/CodeEditor/WithScript/
|
|
7
|
+
import ScriptContext from '@theme/CodeEditor/WithScript/ScriptContext';
|
|
8
8
|
import ContextEditor from '@theme/CodeEditor/ContextEditor';
|
|
9
9
|
|
|
10
10
|
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
3
3
|
import Button, { Color } from '@theme/CodeEditor/Button';
|
|
4
4
|
import { translate } from '@docusaurus/Translate';
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
const DownloadCode = (props: {title: string}) => {
|
|
8
|
-
const { store } =
|
|
9
|
-
const code =
|
|
10
|
-
const lang =
|
|
11
|
-
const id =
|
|
8
|
+
const { store } = useStore();
|
|
9
|
+
const code = useScript(store, (state) => state.code);
|
|
10
|
+
const lang = useScript(store, (state) => state.lang);
|
|
11
|
+
const id = useScript(store, (state) => state.id);
|
|
12
12
|
return (
|
|
13
13
|
<Button
|
|
14
14
|
icon='Download'
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
3
3
|
import Button, { Color } from '@theme/CodeEditor/Button';
|
|
4
4
|
import { translate } from '@docusaurus/Translate';
|
|
5
5
|
|
|
6
6
|
const Reset = () => {
|
|
7
|
-
const { store } =
|
|
8
|
-
const pristine =
|
|
7
|
+
const { store } = useStore();
|
|
8
|
+
const pristine = useScript(store, (state) => state.pristineCode);
|
|
9
9
|
|
|
10
10
|
const onReset = () => {
|
|
11
11
|
const shouldReset = window.confirm(translate({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
3
3
|
import Button, { Color } from '@theme/CodeEditor/Button';
|
|
4
4
|
import { translate } from '@docusaurus/Translate';
|
|
5
5
|
import styles from './styles.module.css';
|
|
@@ -11,8 +11,8 @@ export interface Props {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
const RunCode = (props: Props) => {
|
|
14
|
-
const { store } =
|
|
15
|
-
const isExecuting =
|
|
14
|
+
const { store } = useStore();
|
|
15
|
+
const isExecuting = useScript(store, (state) => state.isExecuting);
|
|
16
16
|
return (
|
|
17
17
|
<Button
|
|
18
18
|
icon={isExecuting ? 'Python' : 'Play'}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
3
3
|
import Button, { Color } from '@theme/CodeEditor/Button';
|
|
4
4
|
import { translate } from '@docusaurus/Translate';
|
|
5
5
|
|
|
6
6
|
const ShowRaw = () => {
|
|
7
|
-
const { store } =
|
|
8
|
-
const showRaw =
|
|
7
|
+
const { store } = useStore();
|
|
8
|
+
const showRaw = useScript(store, (state) => state.showRaw);
|
|
9
9
|
|
|
10
10
|
return (
|
|
11
11
|
<Button
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
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
5
|
|
|
6
6
|
const ShowSyncStatus = () => {
|
|
7
|
-
const { store } =
|
|
8
|
-
const isLoaded =
|
|
9
|
-
const status =
|
|
7
|
+
const { store } = useStore();
|
|
8
|
+
const isLoaded = useScript(store, (state) => state.isLoaded);
|
|
9
|
+
const status = useScript(store, (state) => state.status);
|
|
10
10
|
|
|
11
11
|
React.useEffect(() => {
|
|
12
12
|
if (status !== Status.IDLE) {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { BRYTHON_NOTIFICATION_EVENT, DOM_ELEMENT_IDS } from "@theme/CodeEditor/constants";
|
|
3
|
-
import {
|
|
3
|
+
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
4
4
|
import { type LogMessage } from '@theme/CodeEditor/WithScript/Types';
|
|
5
5
|
|
|
6
6
|
const BrythonCommunicator = () => {
|
|
7
|
-
const { store } =
|
|
8
|
-
const codeId =
|
|
7
|
+
const { store } = useStore();
|
|
8
|
+
const codeId = useScript(store, (state) => state.codeId);
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
const ref = React.useRef<HTMLDivElement>(null);
|
|
@@ -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
9
|
import Button from '@theme/CodeEditor/Button';
|
|
10
|
-
import DiffViewer from 'react-diff-viewer';
|
|
10
|
+
import DiffViewer from 'react-diff-viewer-continued';
|
|
11
11
|
import Details from '@theme/Details';
|
|
12
12
|
|
|
13
13
|
const highlightSyntax = (str: string) => {
|
|
@@ -25,9 +25,9 @@ const highlightSyntax = (str: string) => {
|
|
|
25
25
|
|
|
26
26
|
const CodeHistory = () => {
|
|
27
27
|
const [version, setVersion] = React.useState(1);
|
|
28
|
-
const { store } =
|
|
29
|
-
const versions =
|
|
30
|
-
const versionsLoaded =
|
|
28
|
+
const { store } = useStore();
|
|
29
|
+
const versions = useScript(store, (state) => state.versions);
|
|
30
|
+
const versionsLoaded = useScript(store, (state) => state.versionsLoaded);
|
|
31
31
|
|
|
32
32
|
if (versions?.length < 2) {
|
|
33
33
|
return null;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
|
|
3
3
|
import CodeEditor, { type MetaProps } from '@theme/CodeEditor';
|
|
4
|
-
import ScriptContext from '@theme/CodeEditor/WithScript/
|
|
4
|
+
import ScriptContext from '@theme/CodeEditor/WithScript/ScriptContext';
|
|
5
5
|
import CodeBlock from '@theme/CodeBlock';
|
|
6
6
|
|
|
7
7
|
interface Props extends MetaProps {
|
|
@@ -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
|
|
|
@@ -26,12 +26,12 @@ const ALIAS_LANG_MAP_ACE = {
|
|
|
26
26
|
|
|
27
27
|
const EditorAce = (props: Props) => {
|
|
28
28
|
const eRef = React.useRef<AceEditor>(null);
|
|
29
|
-
const { store } =
|
|
30
|
-
const code =
|
|
31
|
-
const pristineCode =
|
|
32
|
-
const lang =
|
|
33
|
-
const codeId =
|
|
34
|
-
const showRaw =
|
|
29
|
+
const { store } = useStore();
|
|
30
|
+
const code = useScript(store, (state) => state.code);
|
|
31
|
+
const pristineCode = useScript(store, (state) => state.pristineCode);
|
|
32
|
+
const lang = useScript(store, (state) => state.lang);
|
|
33
|
+
const codeId = useScript(store, (state) => state.codeId);
|
|
34
|
+
const showRaw = useScript(store, (state) => state.showRaw);
|
|
35
35
|
|
|
36
36
|
React.useEffect(() => {
|
|
37
37
|
if (eRef && eRef.current) {
|
|
@@ -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 {
|
|
4
|
+
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
5
5
|
import ShowSyncStatus from '@theme/CodeEditor/Actions/ShowSyncStatus';
|
|
6
6
|
import Reset from '@theme/CodeEditor/Actions/Reset';
|
|
7
7
|
import DownloadCode from '@theme/CodeEditor/Actions/DownloadCode';
|
|
@@ -17,10 +17,10 @@ export interface Props {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
const Header = (props: Props) => {
|
|
20
|
-
const { store } =
|
|
20
|
+
const { store } = useStore();
|
|
21
21
|
|
|
22
|
-
const hasEdits =
|
|
23
|
-
const lang =
|
|
22
|
+
const hasEdits = useScript(store, (state) => state.hasEdits);
|
|
23
|
+
const lang = useScript(store, (state) => state.lang);
|
|
24
24
|
return (
|
|
25
25
|
<div className={clsx(styles.controls, props.slim && styles.slim)}>
|
|
26
26
|
{!props.slim && (
|
|
@@ -2,7 +2,7 @@ import * as React from 'react';
|
|
|
2
2
|
import { DOM_ELEMENT_IDS } from '@theme/CodeEditor/constants';
|
|
3
3
|
import Graphics from '@theme/CodeEditor/Editor/Result/Graphics';
|
|
4
4
|
import styles from './styles.module.css';
|
|
5
|
-
import {
|
|
5
|
+
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
6
6
|
import Button from '@theme/CodeEditor/Button';
|
|
7
7
|
|
|
8
8
|
const downloadCanvas = (canvasId: string) => {
|
|
@@ -26,9 +26,9 @@ const downloadCanvas = (canvasId: string) => {
|
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
const Canvas = () => {
|
|
29
|
-
const { store } =
|
|
29
|
+
const { store } = useStore();
|
|
30
30
|
// const { codeId } = useStore(store, (state) => ({codeId: state.codeId}));
|
|
31
|
-
const codeId =
|
|
31
|
+
const codeId = useScript(store, (state) => state.codeId);
|
|
32
32
|
|
|
33
33
|
return (
|
|
34
34
|
<Graphics
|
|
@@ -3,14 +3,14 @@ import styles from './styles.module.css';
|
|
|
3
3
|
import { DOM_ELEMENT_IDS } from '@theme/CodeEditor/constants';
|
|
4
4
|
import Graphics from '@theme/CodeEditor/Editor/Result/Graphics';
|
|
5
5
|
import { saveSvg } from '@theme/CodeEditor/Editor/utils/saveSvg';
|
|
6
|
-
import {
|
|
6
|
+
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
7
7
|
import Button from '@theme/CodeEditor/Button';
|
|
8
8
|
import clsx from 'clsx';
|
|
9
9
|
|
|
10
10
|
const Turtle = () => {
|
|
11
|
-
const { store } =
|
|
12
|
-
const codeId =
|
|
13
|
-
const code =
|
|
11
|
+
const { store } = useStore();
|
|
12
|
+
const codeId = useScript(store, (state) => state.codeId);
|
|
13
|
+
const code = useScript(store, (state) => state.code);
|
|
14
14
|
return (
|
|
15
15
|
<Graphics
|
|
16
16
|
controls={
|
|
@@ -3,7 +3,7 @@ import styles from './styles.module.css';
|
|
|
3
3
|
import { DOM_ELEMENT_IDS } from '@theme/CodeEditor/constants';
|
|
4
4
|
import Draggable from 'react-draggable';
|
|
5
5
|
import { checkForButtonClick } from '@theme/CodeEditor/Editor/utils/checkForButtonClick';
|
|
6
|
-
import {
|
|
6
|
+
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
7
7
|
import Button from '@theme/CodeEditor/Button';
|
|
8
8
|
import clsx from 'clsx';
|
|
9
9
|
export interface Props {
|
|
@@ -11,8 +11,8 @@ export interface Props {
|
|
|
11
11
|
main?: JSX.Element;
|
|
12
12
|
}
|
|
13
13
|
const Graphics = (props: Props) => {
|
|
14
|
-
const { store } =
|
|
15
|
-
const codeId =
|
|
14
|
+
const { store } = useStore();
|
|
15
|
+
const codeId = useScript(store, (state) => state.codeId);
|
|
16
16
|
return (
|
|
17
17
|
<Draggable
|
|
18
18
|
onStop={checkForButtonClick}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import styles from './styles.module.css';
|
|
3
3
|
import CodeBlock from '@theme/CodeBlock';
|
|
4
|
-
import {
|
|
4
|
+
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
5
5
|
|
|
6
6
|
const Result = () => {
|
|
7
|
-
const { store } =
|
|
8
|
-
const logs =
|
|
7
|
+
const { store } = useStore();
|
|
8
|
+
const logs = useScript(store, (state) => state.logs);
|
|
9
9
|
if (logs.length === 0) {
|
|
10
10
|
return null;
|
|
11
11
|
}
|
|
@@ -2,7 +2,7 @@ import * as React from "react";
|
|
|
2
2
|
import {
|
|
3
3
|
DOM_ELEMENT_IDS,
|
|
4
4
|
} from "@theme/CodeEditor/constants";
|
|
5
|
-
import {
|
|
5
|
+
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
6
6
|
import Result from "@theme/CodeEditor/Editor/Result";
|
|
7
7
|
import Turtle from "@theme/CodeEditor/Editor/Result/Graphics/Turtle";
|
|
8
8
|
import Canvas from "@theme/CodeEditor/Editor/Result/Graphics/Canvas";
|
|
@@ -24,12 +24,12 @@ export interface Props {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
const Editor = (props: Props) => {
|
|
27
|
-
const { store } =
|
|
28
|
-
const lang =
|
|
29
|
-
const codeId =
|
|
30
|
-
const hasCanvasOutput =
|
|
31
|
-
const hasTurtleOutput =
|
|
32
|
-
const isGraphicsmodalOpen =
|
|
27
|
+
const { store } = useStore();
|
|
28
|
+
const lang = useScript(store, (state) => state.lang);
|
|
29
|
+
const codeId = useScript(store, (state) => state.codeId);
|
|
30
|
+
const hasCanvasOutput = useScript(store, (state) => state.hasCanvasOutput);
|
|
31
|
+
const hasTurtleOutput = useScript(store, (state) => state.hasTurtleOutput);
|
|
32
|
+
const isGraphicsmodalOpen = useScript(store, (state) => state.isGraphicsmodalOpen);
|
|
33
33
|
|
|
34
34
|
return (
|
|
35
35
|
<React.Fragment>
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { usePluginData } from "@docusaurus/useGlobalData";
|
|
3
|
-
import { type InitState, type
|
|
3
|
+
import { type InitState, type Document } from "@theme/CodeEditor/WithScript/Types";
|
|
4
4
|
import { createStore } from "@theme/CodeEditor/WithScript/createStore";
|
|
5
|
-
export const Context = React.createContext<{store:
|
|
5
|
+
export const Context = React.createContext<{store: Document} | undefined>(undefined);
|
|
6
6
|
|
|
7
7
|
const ScriptContext = (props: InitState & { children: React.ReactNode; }) => {
|
|
8
8
|
const {libDir, syncMaxOnceEvery} = usePluginData('docusaurus-live-brython') as { libDir: string; syncMaxOnceEvery: number; };
|
|
9
|
-
const [store, setStore] = React.useState<
|
|
9
|
+
const [store, setStore] = React.useState<Document | null>(null);
|
|
10
10
|
React.useEffect(() => {
|
|
11
11
|
const store = createStore(props, libDir, syncMaxOnceEvery);
|
|
12
12
|
setStore(store);
|
|
@@ -76,7 +76,7 @@ export interface InitState {
|
|
|
76
76
|
versioned: boolean;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
export interface
|
|
79
|
+
export interface Document<T = Script> {
|
|
80
80
|
getState: () => T;
|
|
81
81
|
setState: (fn: (state: Script) => Script) => void;
|
|
82
82
|
subscribe: (listener: () => void) => () => void;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { v4 as uuidv4 } from 'uuid';
|
|
2
2
|
import { createStorageSlot } from "@docusaurus/theme-common";
|
|
3
3
|
import { getStorageScript, syncStorageScript } from "@theme/CodeEditor/WithScript/Storage";
|
|
4
|
-
import { checkCanvasOutput, checkGraphicsOutput, checkTurtleOutput,
|
|
5
|
-
import { type InitState, type LogMessage, type Script, Status, type
|
|
4
|
+
import { checkCanvasOutput, checkGraphicsOutput, checkTurtleOutput, splitPreCode as splitPreCode, sanitizePyScript } from "@theme/CodeEditor/WithScript/helpers";
|
|
5
|
+
import { type InitState, type LogMessage, type Script, Status, type Document, type StoredScript, type Version } from "@theme/CodeEditor/WithScript/Types";
|
|
6
6
|
import { DOM_ELEMENT_IDS } from "@theme/CodeEditor/constants";
|
|
7
7
|
import throttle from 'lodash/throttle';
|
|
8
8
|
|
|
9
|
-
export const createStore = (props: InitState, libDir: string, syncMaxOnceEvery: number):
|
|
9
|
+
export const createStore = (props: InitState, libDir: string, syncMaxOnceEvery: number): Document => {
|
|
10
10
|
const canSave = !!props.id;
|
|
11
11
|
const id = props.id || uuidv4();
|
|
12
12
|
const codeId = `code.${props.title || props.lang}.${id}`.replace(/(-|\.)/g, '_');
|
|
@@ -56,9 +56,9 @@ export const createStore = (props: InitState, libDir: string, syncMaxOnceEvery:
|
|
|
56
56
|
|
|
57
57
|
const prepareCode = (raw: string, config: { codeOnly?: boolean, stateNotInitialized?: boolean } = {}) => {
|
|
58
58
|
const { pre, code } = config.codeOnly
|
|
59
|
-
? { pre:
|
|
60
|
-
:
|
|
61
|
-
const hasEdits = code !== (config.stateNotInitialized ?
|
|
59
|
+
? { pre: splitPreCode(state.pristineCode).pre, code: raw }
|
|
60
|
+
: splitPreCode(raw);
|
|
61
|
+
const hasEdits = code !== (config.stateNotInitialized ? splitPreCode(props.raw).code : state.pristineCode);
|
|
62
62
|
const updatedAt = new Date();
|
|
63
63
|
const hasCanvasOutput = checkCanvasOutput(raw);
|
|
64
64
|
const hasTurtleOutput = checkTurtleOutput(raw);
|
|
@@ -243,5 +243,5 @@ run("""${sanitizePyScript(toExec || '')}""", '${codeId}', ${lineShift})
|
|
|
243
243
|
stopScript,
|
|
244
244
|
load,
|
|
245
245
|
loadVersions
|
|
246
|
-
} satisfies
|
|
246
|
+
} satisfies Document;
|
|
247
247
|
};
|
|
@@ -16,7 +16,7 @@ export const checkCanvasOutput = (raw: string): boolean => {
|
|
|
16
16
|
return CANVAS_OUTPUT_TESTER.test(raw) || GRID_IMPORTS_TESTER.test(raw);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
export const
|
|
19
|
+
export const splitPreCode = (rawcode: string) => {
|
|
20
20
|
const match = rawcode.match(/\n###\s*PRE.*?\n/);
|
|
21
21
|
if (match) {
|
|
22
22
|
return {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export {useStore as useStore} from '@theme/CodeEditor/hooks/useStore';
|
|
2
|
+
export {useScript as useScript} from '@theme/CodeEditor/hooks/useScript';
|
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { ReactContextError } from "@docusaurus/theme-common";
|
|
4
|
-
import { useContext } from "react";
|
|
1
|
+
import {Selector, type Document } from "@theme/CodeEditor/WithScript/Types";
|
|
2
|
+
import { useCallback, useSyncExternalStore } from "react";
|
|
5
3
|
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
'The Component must be a child of the ScriptContextProvider component',
|
|
12
|
-
);
|
|
13
|
-
}
|
|
14
|
-
return context;
|
|
4
|
+
export const useScript = <T, R>(store: Document<T>, selector: Selector<T, R>): R => {
|
|
5
|
+
return useSyncExternalStore(
|
|
6
|
+
store.subscribe,
|
|
7
|
+
useCallback(() => selector(store.getState()), [store, selector])
|
|
8
|
+
);
|
|
15
9
|
}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Context } from "@theme/CodeEditor/WithScript/ScriptContext";
|
|
2
|
+
import {type Document } from "@theme/CodeEditor/WithScript/Types";
|
|
3
|
+
import { ReactContextError } from "@docusaurus/theme-common";
|
|
4
|
+
import { useContext } from "react";
|
|
3
5
|
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
export function useStore(): {store: Document} {
|
|
7
|
+
const context = useContext(Context);
|
|
8
|
+
if (context === null) {
|
|
9
|
+
throw new ReactContextError(
|
|
10
|
+
'ScriptContextProvider',
|
|
11
|
+
'The Component must be a child of the ScriptContextProvider component',
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
return context;
|
|
9
15
|
}
|
|
@@ -3,7 +3,7 @@ import styles from './styles.module.css';
|
|
|
3
3
|
import Editor from '@theme/CodeEditor/Editor';
|
|
4
4
|
import BrythonCommunicator from '@theme/CodeEditor/BrythonCommunicator';
|
|
5
5
|
import clsx from 'clsx';
|
|
6
|
-
import {
|
|
6
|
+
import { useStore, useScript } from '@theme/CodeEditor/hooks';
|
|
7
7
|
import BrowserOnly from '@docusaurus/BrowserOnly';
|
|
8
8
|
import CodeHistory from '@theme/CodeEditor/CodeHistory';
|
|
9
9
|
|
|
@@ -40,8 +40,8 @@ export interface Props {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
const CodeEditor = (props: Props) => {
|
|
43
|
-
const { store } =
|
|
44
|
-
const lang =
|
|
43
|
+
const { store } = useStore();
|
|
44
|
+
const lang = useScript(store, (state) => state.lang);
|
|
45
45
|
return (
|
|
46
46
|
<BrowserOnly
|
|
47
47
|
fallback={<div>Loading...</div>}
|