docusaurus-live-brython 3.0.0-beta.8 → 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.
Files changed (175) hide show
  1. package/.devcontainer/devcontainer.json +38 -0
  2. package/.prettierignore +17 -0
  3. package/.prettierrc +9 -8
  4. package/CHANGELOG.md +5 -0
  5. package/README.md +7 -4
  6. package/lib/assets/py_back_trace.py +2 -1
  7. package/lib/index.d.ts +1 -7
  8. package/lib/index.d.ts.map +1 -0
  9. package/lib/index.js +94 -16
  10. package/lib/options.d.ts +1 -0
  11. package/lib/options.d.ts.map +1 -0
  12. package/lib/options.js +2 -2
  13. package/lib/theme/CodeBlock/index.d.ts +3 -3
  14. package/lib/theme/CodeBlock/index.d.ts.map +1 -0
  15. package/lib/theme/CodeBlock/index.jsx +24 -14
  16. package/lib/theme/CodeEditor/Actions/DownloadCode.d.ts +1 -0
  17. package/lib/theme/CodeEditor/Actions/DownloadCode.d.ts.map +1 -0
  18. package/lib/theme/CodeEditor/Actions/DownloadCode.jsx +8 -8
  19. package/lib/theme/CodeEditor/Actions/Reset.d.ts +1 -0
  20. package/lib/theme/CodeEditor/Actions/Reset.d.ts.map +1 -0
  21. package/lib/theme/CodeEditor/Actions/Reset.jsx +5 -5
  22. package/lib/theme/CodeEditor/Actions/RunCode.d.ts +2 -1
  23. package/lib/theme/CodeEditor/Actions/RunCode.d.ts.map +1 -0
  24. package/lib/theme/CodeEditor/Actions/RunCode.jsx +4 -4
  25. package/lib/theme/CodeEditor/Actions/ShowRaw.d.ts +1 -0
  26. package/lib/theme/CodeEditor/Actions/ShowRaw.d.ts.map +1 -0
  27. package/lib/theme/CodeEditor/Actions/ShowRaw.jsx +13 -7
  28. package/lib/theme/CodeEditor/Actions/ShowSyncStatus.d.ts +1 -0
  29. package/lib/theme/CodeEditor/Actions/ShowSyncStatus.d.ts.map +1 -0
  30. package/lib/theme/CodeEditor/Actions/ShowSyncStatus.jsx +21 -16
  31. package/lib/theme/CodeEditor/Actions/styles.module.css +2 -3
  32. package/lib/theme/CodeEditor/BrythonCommunicator.d.ts +2 -1
  33. package/lib/theme/CodeEditor/BrythonCommunicator.d.ts.map +1 -0
  34. package/lib/theme/CodeEditor/BrythonCommunicator.jsx +13 -9
  35. package/lib/theme/CodeEditor/Button/index.d.ts +3 -2
  36. package/lib/theme/CodeEditor/Button/index.d.ts.map +1 -0
  37. package/lib/theme/CodeEditor/Button/index.jsx +1 -1
  38. package/lib/theme/CodeEditor/Button/styles.module.css +1 -1
  39. package/lib/theme/CodeEditor/CodeHistory/index.d.ts +1 -0
  40. package/lib/theme/CodeEditor/CodeHistory/index.d.ts.map +1 -0
  41. package/lib/theme/CodeEditor/CodeHistory/index.jsx +26 -15
  42. package/lib/theme/CodeEditor/CodeHistory/styles.module.css +31 -31
  43. package/lib/theme/CodeEditor/ContextEditor/index.d.ts +22 -0
  44. package/lib/theme/CodeEditor/ContextEditor/index.d.ts.map +1 -0
  45. package/lib/theme/CodeEditor/ContextEditor/index.jsx +36 -0
  46. package/lib/theme/CodeEditor/Editor/EditorAce.d.ts +2 -1
  47. package/lib/theme/CodeEditor/Editor/EditorAce.d.ts.map +1 -0
  48. package/lib/theme/CodeEditor/Editor/EditorAce.jsx +17 -14
  49. package/lib/theme/CodeEditor/Editor/Header/index.d.ts +2 -1
  50. package/lib/theme/CodeEditor/Editor/Header/index.d.ts.map +1 -0
  51. package/lib/theme/CodeEditor/Editor/Header/index.jsx +12 -12
  52. package/lib/theme/CodeEditor/Editor/Header/styles.module.css +7 -7
  53. package/lib/theme/CodeEditor/Editor/HiddenCode/index.d.ts +8 -0
  54. package/lib/theme/CodeEditor/Editor/HiddenCode/index.d.ts.map +1 -0
  55. package/lib/theme/CodeEditor/Editor/HiddenCode/index.jsx +27 -0
  56. package/lib/theme/CodeEditor/Editor/HiddenCode/styles.module.css +52 -0
  57. package/lib/theme/CodeEditor/Editor/Result/Graphics/Canvas.d.ts +1 -0
  58. package/lib/theme/CodeEditor/Editor/Result/Graphics/Canvas.d.ts.map +1 -0
  59. package/lib/theme/CodeEditor/Editor/Result/Graphics/Canvas.jsx +8 -9
  60. package/lib/theme/CodeEditor/Editor/Result/Graphics/Turtle.d.ts +1 -0
  61. package/lib/theme/CodeEditor/Editor/Result/Graphics/Turtle.d.ts.map +1 -0
  62. package/lib/theme/CodeEditor/Editor/Result/Graphics/Turtle.jsx +11 -11
  63. package/lib/theme/CodeEditor/Editor/Result/Graphics/index.d.ts +4 -3
  64. package/lib/theme/CodeEditor/Editor/Result/Graphics/index.d.ts.map +1 -0
  65. package/lib/theme/CodeEditor/Editor/Result/Graphics/index.jsx +12 -10
  66. package/lib/theme/CodeEditor/Editor/Result/Graphics/styles.module.css +2 -2
  67. package/lib/theme/CodeEditor/Editor/Result/index.d.ts +2 -3
  68. package/lib/theme/CodeEditor/Editor/Result/index.d.ts.map +1 -0
  69. package/lib/theme/CodeEditor/Editor/Result/index.jsx +6 -9
  70. package/lib/theme/CodeEditor/Editor/Result/styles.module.css +15 -10
  71. package/lib/theme/CodeEditor/Editor/index.d.ts +6 -3
  72. package/lib/theme/CodeEditor/Editor/index.d.ts.map +1 -0
  73. package/lib/theme/CodeEditor/Editor/index.jsx +34 -28
  74. package/lib/theme/CodeEditor/Editor/styles.module.css +15 -7
  75. package/lib/theme/CodeEditor/Editor/utils/checkForButtonClick.d.ts +1 -0
  76. package/lib/theme/CodeEditor/Editor/utils/checkForButtonClick.d.ts.map +1 -0
  77. package/lib/theme/CodeEditor/Editor/utils/saveSvg.d.ts +1 -0
  78. package/lib/theme/CodeEditor/Editor/utils/saveSvg.d.ts.map +1 -0
  79. package/lib/theme/CodeEditor/Editor/utils/saveSvg.js +19 -8
  80. package/lib/theme/CodeEditor/Editor/utils/svgWithoutAnimations.d.ts +1 -0
  81. package/lib/theme/CodeEditor/Editor/utils/svgWithoutAnimations.d.ts.map +1 -0
  82. package/lib/theme/CodeEditor/Editor/utils/svgWithoutAnimations.js +43 -49
  83. package/lib/theme/CodeEditor/Icon/icons.d.ts +4 -1
  84. package/lib/theme/CodeEditor/Icon/icons.d.ts.map +1 -0
  85. package/lib/theme/CodeEditor/Icon/icons.js +3 -1
  86. package/lib/theme/CodeEditor/Icon/index.d.ts +4 -2
  87. package/lib/theme/CodeEditor/Icon/index.d.ts.map +1 -0
  88. package/lib/theme/CodeEditor/Icon/index.jsx +10 -3
  89. package/lib/theme/CodeEditor/Icon/styles.module.css +1 -1
  90. package/lib/theme/CodeEditor/WithScript/ScriptContext.d.ts +8 -0
  91. package/lib/theme/CodeEditor/WithScript/ScriptContext.d.ts.map +1 -0
  92. package/lib/theme/CodeEditor/WithScript/ScriptContext.jsx +27 -0
  93. package/lib/theme/CodeEditor/WithScript/Storage.d.ts +2 -1
  94. package/lib/theme/CodeEditor/WithScript/Storage.d.ts.map +1 -0
  95. package/lib/theme/CodeEditor/WithScript/Types.d.ts +12 -4
  96. package/lib/theme/CodeEditor/WithScript/Types.d.ts.map +1 -0
  97. package/lib/theme/CodeEditor/WithScript/bryRunner.d.ts +3 -0
  98. package/lib/theme/CodeEditor/WithScript/bryRunner.d.ts.map +1 -0
  99. package/lib/theme/CodeEditor/WithScript/bryRunner.js +29 -0
  100. package/lib/theme/CodeEditor/WithScript/createStore.d.ts +4 -0
  101. package/lib/theme/CodeEditor/WithScript/createStore.d.ts.map +1 -0
  102. package/lib/theme/CodeEditor/WithScript/{Store.jsx → createStore.js} +62 -74
  103. package/lib/theme/CodeEditor/WithScript/helpers.d.ts +1 -4
  104. package/lib/theme/CodeEditor/WithScript/helpers.d.ts.map +1 -0
  105. package/lib/theme/CodeEditor/WithScript/helpers.js +4 -14
  106. package/lib/theme/CodeEditor/constants.d.ts +1 -0
  107. package/lib/theme/CodeEditor/constants.d.ts.map +1 -0
  108. package/lib/theme/CodeEditor/hooks/index.d.ts +3 -0
  109. package/lib/theme/CodeEditor/hooks/index.d.ts.map +1 -0
  110. package/lib/theme/CodeEditor/hooks/index.js +2 -0
  111. package/lib/theme/CodeEditor/hooks/useScript.d.ts +3 -0
  112. package/lib/theme/CodeEditor/hooks/useScript.d.ts.map +1 -0
  113. package/lib/theme/CodeEditor/hooks/useScript.js +4 -0
  114. package/lib/theme/CodeEditor/hooks/useStore.d.ts +3 -0
  115. package/lib/theme/CodeEditor/hooks/useStore.d.ts.map +1 -0
  116. package/lib/theme/CodeEditor/hooks/useStore.js +10 -0
  117. package/lib/theme/CodeEditor/index.d.ts +24 -5
  118. package/lib/theme/CodeEditor/index.d.ts.map +1 -0
  119. package/lib/theme/CodeEditor/index.jsx +17 -16
  120. package/lib/theme/CodeEditor/styles.module.css +28 -30
  121. package/og-image.md +23 -0
  122. package/package.json +39 -20
  123. package/src/assets/py_back_trace.py +2 -1
  124. package/src/index.ts +96 -25
  125. package/src/options.ts +12 -12
  126. package/src/theme/CodeBlock/index.tsx +44 -68
  127. package/src/theme/CodeEditor/Actions/DownloadCode.tsx +23 -22
  128. package/src/theme/CodeEditor/Actions/Reset.tsx +14 -12
  129. package/src/theme/CodeEditor/Actions/RunCode.tsx +14 -11
  130. package/src/theme/CodeEditor/Actions/ShowRaw.tsx +17 -11
  131. package/src/theme/CodeEditor/Actions/ShowSyncStatus.tsx +32 -27
  132. package/src/theme/CodeEditor/Actions/styles.module.css +2 -3
  133. package/src/theme/CodeEditor/BrythonCommunicator.tsx +16 -19
  134. package/src/theme/CodeEditor/Button/index.tsx +17 -13
  135. package/src/theme/CodeEditor/Button/styles.module.css +1 -1
  136. package/src/theme/CodeEditor/CodeHistory/index.tsx +32 -20
  137. package/src/theme/CodeEditor/CodeHistory/styles.module.css +31 -31
  138. package/src/theme/CodeEditor/ContextEditor/index.tsx +74 -0
  139. package/src/theme/CodeEditor/Editor/EditorAce.tsx +20 -16
  140. package/src/theme/CodeEditor/Editor/Header/index.tsx +13 -19
  141. package/src/theme/CodeEditor/Editor/Header/styles.module.css +7 -7
  142. package/src/theme/CodeEditor/Editor/HiddenCode/index.tsx +49 -0
  143. package/src/theme/CodeEditor/Editor/HiddenCode/styles.module.css +52 -0
  144. package/src/theme/CodeEditor/Editor/Result/Graphics/Canvas.tsx +25 -22
  145. package/src/theme/CodeEditor/Editor/Result/Graphics/Turtle.tsx +23 -19
  146. package/src/theme/CodeEditor/Editor/Result/Graphics/index.tsx +16 -16
  147. package/src/theme/CodeEditor/Editor/Result/Graphics/styles.module.css +2 -2
  148. package/src/theme/CodeEditor/Editor/Result/index.tsx +7 -13
  149. package/src/theme/CodeEditor/Editor/Result/styles.module.css +15 -10
  150. package/src/theme/CodeEditor/Editor/index.tsx +67 -65
  151. package/src/theme/CodeEditor/Editor/styles.module.css +15 -7
  152. package/src/theme/CodeEditor/Editor/utils/checkForButtonClick.ts +5 -5
  153. package/src/theme/CodeEditor/Editor/utils/saveSvg.ts +63 -53
  154. package/src/theme/CodeEditor/Editor/utils/svgWithoutAnimations.ts +182 -201
  155. package/src/theme/CodeEditor/Icon/icons.ts +27 -13
  156. package/src/theme/CodeEditor/Icon/index.tsx +31 -11
  157. package/src/theme/CodeEditor/Icon/styles.module.css +1 -1
  158. package/src/theme/CodeEditor/WithScript/ScriptContext.tsx +36 -0
  159. package/src/theme/CodeEditor/WithScript/Storage.ts +3 -3
  160. package/src/theme/CodeEditor/WithScript/Types.ts +17 -11
  161. package/src/theme/CodeEditor/WithScript/bryRunner.ts +39 -0
  162. package/src/theme/CodeEditor/WithScript/createStore.ts +276 -0
  163. package/src/theme/CodeEditor/WithScript/helpers.ts +16 -26
  164. package/src/theme/CodeEditor/constants.ts +9 -11
  165. package/src/theme/CodeEditor/hooks/index.ts +2 -0
  166. package/src/theme/CodeEditor/hooks/useScript.ts +9 -0
  167. package/src/theme/CodeEditor/hooks/useStore.ts +15 -0
  168. package/src/theme/CodeEditor/index.tsx +45 -31
  169. package/src/theme/CodeEditor/styles.module.css +28 -30
  170. package/src/typings.d.ts +11 -0
  171. package/lib/theme/CodeEditor/WithScript/Store.d.ts +0 -15
  172. package/lib/types.d.ts +0 -28
  173. package/lib/types.js +0 -1
  174. package/src/theme/CodeEditor/WithScript/Store.tsx +0 -294
  175. package/src/types.ts +0 -29
@@ -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
- flex-shrink: 1;
19
- flex-grow: 1;
20
- overflow-x: hidden;
21
- text-overflow: ellipsis;
22
- white-space: nowrap;
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;
@@ -0,0 +1,52 @@
1
+ .container > .toggleButton {
2
+ position: absolute;
3
+ left: 50%;
4
+ top: 0px;
5
+ z-index: var(--ifm-z-index-dropdown);
6
+ opacity: var(--show-hidden-code-toggle-opacity);
7
+ transition: opacity 0.6s ease; /* Adjust timing as needed */
8
+ padding: 0;
9
+ background: transparent;
10
+ border: 0;
11
+ color: var(--ifm-color-info-darkest);
12
+ cursor: pointer;
13
+ }
14
+ .container > .toggleButton:hover {
15
+ color: var(--ifm-color-info);
16
+ }
17
+
18
+ .container > .toggleButton.post {
19
+ left: 50%;
20
+ top: unset;
21
+ bottom: 0px;
22
+ }
23
+ .toggleButton > svg {
24
+ transition: all 0.1s ease; /* Adjust timing as needed */
25
+ }
26
+
27
+ .container > .toggleButton.open {
28
+ color: var(--ifm-color-danger);
29
+ }
30
+ .container > .toggleButton.open:hover {
31
+ color: var(--ifm-color-danger-darkest);
32
+ }
33
+
34
+ .hiddenCode {
35
+ margin-bottom: 0;
36
+ --ifm-pre-padding: 0 3em;
37
+ }
38
+ .hiddenCode pre {
39
+ border-radius: 0;
40
+ }
41
+ .hiddenCode pre > code {
42
+ background-color: var(--ifm-color-secondary-dark);
43
+ border-radius: 0;
44
+ }
45
+ .hiddenCode > div[class^='codeBlockContent'] > div[class^='buttonGroup'] {
46
+ right: 0;
47
+ top: 0;
48
+ }
49
+
50
+ html[data-theme='dark'] .hiddenCode pre > code {
51
+ background-color: var(--ifm-card-background-color);
52
+ }
@@ -1,9 +1,9 @@
1
1
  import * as React from 'react';
2
- import { DOM_ELEMENT_IDS } from 'docusaurus-live-brython/theme/CodeEditor/constants';
3
- import Graphics from 'docusaurus-live-brython/theme/CodeEditor/Editor/Result/Graphics';
2
+ import { DOM_ELEMENT_IDS } from '@theme/CodeEditor/constants';
3
+ import Graphics from '@theme/CodeEditor/Editor/Result/Graphics';
4
4
  import styles from './styles.module.css';
5
- import { useScript, useStore } from 'docusaurus-live-brython/theme/CodeEditor/WithScript/Store';
6
- import Button from 'docusaurus-live-brython/theme/CodeEditor/Button';
5
+ import { useStore, useScript } from '@theme/CodeEditor/hooks';
6
+ import Button from '@theme/CodeEditor/Button';
7
7
 
8
8
  const downloadCanvas = (canvasId: string) => {
9
9
  const canvas = document.getElementById(canvasId) as HTMLCanvasElement;
@@ -13,49 +13,52 @@ const downloadCanvas = (canvasId: string) => {
13
13
  var dt = canvas.toDataURL('image/png');
14
14
  /* Change MIME type to trick the browser to downlaod the file instead of displaying it */
15
15
  dt = dt.replace(/^data:image\/[^;]*/, 'data:application/octet-stream');
16
-
16
+
17
17
  /* In addition to <a>'s "download" attribute, you can define HTTP-style headers */
18
- dt = dt.replace(/^data:application\/octet-stream/, 'data:application/octet-stream;headers=Content-Disposition%3A%20attachment%3B%20filename=Canvas.png');
19
-
20
- var downloadLink = document.createElement("a");
18
+ dt = dt.replace(
19
+ /^data:application\/octet-stream/,
20
+ 'data:application/octet-stream;headers=Content-Disposition%3A%20attachment%3B%20filename=Canvas.png'
21
+ );
22
+
23
+ var downloadLink = document.createElement('a');
21
24
  downloadLink.href = dt;
22
25
  downloadLink.download = `${canvasId}.png`;
23
26
  document.body.appendChild(downloadLink);
24
27
  downloadLink.click();
25
28
  document.body.removeChild(downloadLink);
26
- };
29
+ };
27
30
 
28
31
  const Canvas = () => {
29
- const { store } = useScript();
30
- // const { codeId } = useStore(store, (state) => ({codeId: state.codeId}));
31
- const codeId = useStore(store, (state) => state.codeId);
32
+ const store = useStore();
33
+ const codeId = useScript(store, 'codeId');
32
34
 
33
35
  return (
34
36
  <Graphics
35
37
  controls={
36
38
  <Button
37
- icon='Download'
38
- iconSize='12px'
39
+ icon="Download"
40
+ iconSize="12px"
39
41
  onClick={() => {
40
- downloadCanvas(DOM_ELEMENT_IDS.canvasContainer(codeId))
42
+ downloadCanvas(DOM_ELEMENT_IDS.canvasContainer(codeId));
41
43
  }}
42
44
  title="Download SVG"
43
45
  className={styles.slimStrippedButton}
44
46
  />
45
47
  }
46
48
  main={
47
- <canvas
48
- id={DOM_ELEMENT_IDS.canvasContainer(codeId)}
49
+ <canvas
50
+ id={DOM_ELEMENT_IDS.canvasContainer(codeId)}
49
51
  width="500"
50
52
  height="500"
51
53
  style={{
52
- display: 'block',
53
- width: '500px',
54
+ display: 'block',
55
+ width: '500px',
54
56
  height: '500px'
55
- }}></canvas>
57
+ }}
58
+ ></canvas>
56
59
  }
57
60
  />
58
- )
61
+ );
59
62
  };
60
63
 
61
- export default Canvas;
64
+ export default Canvas;
@@ -1,39 +1,43 @@
1
1
  import * as React from 'react';
2
2
  import styles from './styles.module.css';
3
- import { DOM_ELEMENT_IDS } from 'docusaurus-live-brython/theme/CodeEditor/constants';
4
- import Graphics from 'docusaurus-live-brython/theme/CodeEditor/Editor/Result/Graphics';
5
- import { saveSvg } from 'docusaurus-live-brython/theme/CodeEditor/Editor/utils/saveSvg';
6
- import { useScript, useStore } from 'docusaurus-live-brython/theme/CodeEditor/WithScript/Store';
7
- import Button from 'docusaurus-live-brython/theme/CodeEditor/Button';
3
+ import { DOM_ELEMENT_IDS } from '@theme/CodeEditor/constants';
4
+ import Graphics from '@theme/CodeEditor/Editor/Result/Graphics';
5
+ import { saveSvg } from '@theme/CodeEditor/Editor/utils/saveSvg';
6
+ import { useStore, useScript } from '@theme/CodeEditor/hooks';
7
+ import Button from '@theme/CodeEditor/Button';
8
8
  import clsx from 'clsx';
9
9
 
10
10
  const Turtle = () => {
11
- const { store } = useScript();
12
- const codeId = useStore(store, (state) => state.codeId);
13
- const code = useStore(store, (state) => state.code);
11
+ const store = useStore();
12
+ const codeId = useScript(store, 'codeId');
13
+ const code = useScript(store, 'code');
14
14
  return (
15
15
  <Graphics
16
16
  controls={
17
17
  <React.Fragment>
18
18
  <Button
19
- icon='AnimationPlay'
19
+ icon="AnimationPlay"
20
20
  onClick={() => {
21
- const turtleResult = (document.getElementById(DOM_ELEMENT_IDS.turtleSvgContainer(codeId)) as any) as SVGSVGElement;
21
+ const turtleResult = document.getElementById(
22
+ DOM_ELEMENT_IDS.turtleSvgContainer(codeId)
23
+ ) as any as SVGSVGElement;
22
24
  if (turtleResult) {
23
- saveSvg(turtleResult, `${codeId}`, code, true)
25
+ saveSvg(turtleResult, `${codeId}`, code, true);
24
26
  }
25
27
  }}
26
28
  className={clsx(styles.slimStrippedButton)}
27
- iconSize='12px'
29
+ iconSize="12px"
28
30
  title="Download Animated SVG"
29
31
  />
30
32
  <Button
31
- icon='Download'
32
- iconSize='12px'
33
+ icon="Download"
34
+ iconSize="12px"
33
35
  onClick={() => {
34
- const turtleResult = (document.getElementById(DOM_ELEMENT_IDS.turtleSvgContainer(codeId)) as any) as SVGSVGElement;
36
+ const turtleResult = document.getElementById(
37
+ DOM_ELEMENT_IDS.turtleSvgContainer(codeId)
38
+ ) as any as SVGSVGElement;
35
39
  if (turtleResult) {
36
- saveSvg(turtleResult, `${codeId}`, code)
40
+ saveSvg(turtleResult, `${codeId}`, code);
37
41
  }
38
42
  }}
39
43
  title="Download SVG"
@@ -42,7 +46,7 @@ const Turtle = () => {
42
46
  </React.Fragment>
43
47
  }
44
48
  />
45
- )
46
- }
49
+ );
50
+ };
47
51
 
48
- export default Turtle;
52
+ export default Turtle;
@@ -1,24 +1,23 @@
1
1
  import * as React from 'react';
2
2
  import styles from './styles.module.css';
3
- import { DOM_ELEMENT_IDS } from 'docusaurus-live-brython/theme/CodeEditor/constants';
3
+ import { DOM_ELEMENT_IDS } from '@theme/CodeEditor/constants';
4
4
  import Draggable from 'react-draggable';
5
- import { checkForButtonClick } from 'docusaurus-live-brython/theme/CodeEditor/Editor/utils/checkForButtonClick';
6
- import { useScript, useStore } from 'docusaurus-live-brython/theme/CodeEditor/WithScript/Store';
7
- import Button from 'docusaurus-live-brython/theme/CodeEditor/Button';
5
+ import { checkForButtonClick } from '@theme/CodeEditor/Editor/utils/checkForButtonClick';
6
+ import { useStore, useScript } from '@theme/CodeEditor/hooks';
7
+ import Button from '@theme/CodeEditor/Button';
8
8
  import clsx from 'clsx';
9
- interface Props {
10
- controls?: JSX.Element;
11
- main?: JSX.Element;
9
+ export interface Props {
10
+ controls?: React.ReactNode;
11
+ main?: React.ReactNode;
12
12
  }
13
13
  const Graphics = (props: Props) => {
14
- const { store } = useScript();
15
- const codeId = useStore(store, (state) => state.codeId);
14
+ const store = useStore();
15
+ const codeId = useScript(store, 'codeId');
16
+ const graphicsModalExecutionNr = useScript(store, 'graphicsModalExecutionNr');
17
+ const nodeRef = React.useRef(null);
16
18
  return (
17
- <Draggable
18
- onStop={checkForButtonClick}
19
- positionOffset={{ x: 0, y: '-50%' }}
20
- >
21
- <div className={styles.brythonGraphicsResult}>
19
+ <Draggable onStop={checkForButtonClick} positionOffset={{ x: '15%', y: '25%' }} nodeRef={nodeRef}>
20
+ <div className={styles.brythonGraphicsResult} ref={nodeRef}>
22
21
  <div className={styles.brythonGraphicsResultHead}>
23
22
  <span>Output</span>
24
23
  <span className={styles.spacer}></span>
@@ -30,12 +29,13 @@ const Graphics = (props: Props) => {
30
29
  store.stopScript();
31
30
  store.closeGraphicsModal();
32
31
  }}
33
- iconSize='12px'
32
+ iconSize="12px"
34
33
  />
35
34
  </div>
36
35
  <div
37
36
  id={DOM_ELEMENT_IDS.graphicsResult(codeId)}
38
37
  className="brython-graphics-result"
38
+ key={`exec-${graphicsModalExecutionNr}`}
39
39
  >
40
40
  {props.main}
41
41
  </div>
@@ -44,4 +44,4 @@ const Graphics = (props: Props) => {
44
44
  );
45
45
  };
46
46
 
47
- export default Graphics;
47
+ export default Graphics;
@@ -38,6 +38,6 @@
38
38
  margin-right: 0;
39
39
  }
40
40
 
41
- html[data-theme='dark'] .brythonGraphicsResult {
41
+ html[data-theme='dark'] .brythonGraphicsResult {
42
42
  background-color: rgba(179, 179, 179, 0.671);
43
- }
43
+ }
@@ -1,21 +1,17 @@
1
1
  import * as React from 'react';
2
2
  import styles from './styles.module.css';
3
- // @ts-ignore
4
3
  import CodeBlock from '@theme/CodeBlock';
5
- import { useScript, useStore } from 'docusaurus-live-brython/theme/CodeEditor/WithScript/Store';
4
+ import { useStore, useScript } from '@theme/CodeEditor/hooks';
6
5
 
7
- interface Props {
8
- }
9
-
10
- const Result = (props: Props) => {
11
- const { store } = useScript();
12
- const logs = useStore(store, (state) => state.logs);
6
+ const Result = () => {
7
+ const store = useStore();
8
+ const logs = useScript(store, 'logs');
13
9
  if (logs.length === 0) {
14
10
  return null;
15
11
  }
16
- const errors: string[] = []
12
+ const errors: string[] = [];
17
13
  let lineNr = 1;
18
- const code = logs.map((msg) => {
14
+ const code = logs.slice().map((msg) => {
19
15
  const msgLen = (msg.output || '').split('\n').length - 1;
20
16
  if (msg.type === 'stderr') {
21
17
  errors.push(`${lineNr}-${lineNr + msgLen}`);
@@ -25,9 +21,7 @@ const Result = (props: Props) => {
25
21
  });
26
22
  return (
27
23
  <div className={styles.result}>
28
- <CodeBlock metastring={`{${errors.join(',')}}`}>
29
- {code.join('')}
30
- </CodeBlock>
24
+ <CodeBlock metastring={`{${errors.join(',')}}`}>{code.join('')}</CodeBlock>
31
25
  </div>
32
26
  );
33
27
  };
@@ -1,19 +1,24 @@
1
1
  .result {
2
- grid-area: result;
3
- max-width: 100%;
4
- overflow-x: auto;
2
+ grid-area: result;
3
+ max-width: 100%;
4
+ overflow-x: auto;
5
5
  --ifm-leading: 0;
6
6
  flex-grow: 1;
7
7
  flex-basis: 80ch;
8
8
  }
9
9
 
10
- .result>pre {
11
- margin-bottom: 0px;
12
- border-top-left-radius: 0;
13
- border-top-right-radius: 0;
10
+ .result > pre {
11
+ margin-bottom: 0px;
12
+ border-top-left-radius: 0;
13
+ border-top-right-radius: 0;
14
14
  }
15
15
 
16
16
  .result :global(.theme-code-block-highlighted-line) {
17
- color: var(--ifm-color-danger-darker) !important;
18
- background: transparent;
19
- }
17
+ color: var(--ifm-color-danger-darker) !important;
18
+ background: transparent;
19
+ }
20
+
21
+ .result pre {
22
+ border-top-left-radius: 0;
23
+ border-top-right-radius: 0;
24
+ }
@@ -1,71 +1,73 @@
1
- import * as React from "react";
2
- import {
3
- DOM_ELEMENT_IDS,
4
- } from "docusaurus-live-brython/theme/CodeEditor/constants";
5
- import { useScript, useStore } from 'docusaurus-live-brython/theme/CodeEditor/WithScript/Store';
6
- import Result from "docusaurus-live-brython/theme/CodeEditor/Editor/Result";
7
- import Turtle from "docusaurus-live-brython/theme/CodeEditor/Editor/Result/Graphics/Turtle";
8
- import Canvas from "docusaurus-live-brython/theme/CodeEditor/Editor/Result/Graphics/Canvas";
9
- import Graphics from "docusaurus-live-brython/theme/CodeEditor/Editor/Result/Graphics";
10
- import Header from "docusaurus-live-brython/theme/CodeEditor/Editor/Header";
11
- import EditorAce from "docusaurus-live-brython/theme/CodeEditor/Editor/EditorAce";
1
+ import * as React from 'react';
2
+ import { DOM_ELEMENT_IDS } from '@theme/CodeEditor/constants';
3
+ import { useStore, useScript } from '@theme/CodeEditor/hooks';
4
+ import Result from '@theme/CodeEditor/Editor/Result';
5
+ import Turtle from '@theme/CodeEditor/Editor/Result/Graphics/Turtle';
6
+ import Canvas from '@theme/CodeEditor/Editor/Result/Graphics/Canvas';
7
+ import Graphics from '@theme/CodeEditor/Editor/Result/Graphics';
8
+ import Header from '@theme/CodeEditor/Editor/Header';
9
+ import EditorAce from '@theme/CodeEditor/Editor/EditorAce';
10
+ import clsx from 'clsx';
11
+ import styles from './styles.module.css';
12
+ import HiddenCode from '@theme/CodeEditor/Editor/HiddenCode';
12
13
 
13
- interface Props {
14
- slim: boolean;
15
- title: string;
16
- resettable: boolean;
17
- showLineNumbers: boolean;
18
- download: boolean;
19
- lang: string;
20
- noCompare: boolean;
21
- precode: string;
22
- maxLines?: number;
23
- versioned?: boolean;
14
+ export interface Props {
15
+ slim: boolean;
16
+ title: string;
17
+ resettable: boolean;
18
+ showLineNumbers: boolean;
19
+ download: boolean;
20
+ lang: string;
21
+ noCompare: boolean;
22
+ preCode: string;
23
+ postCode: string;
24
+ maxLines?: number;
25
+ versioned?: boolean;
26
+ onChange?: (code: string) => void;
24
27
  }
25
28
 
26
29
  const Editor = (props: Props) => {
27
- const { store } = useScript();
28
- const lang = useStore(store, (state) => state.lang);
29
- const codeId = useStore(store, (state) => state.codeId);
30
- const hasCanvasOutput = useStore(store, (state) => state.hasCanvasOutput);
31
- const hasTurtleOutput = useStore(store, (state) => state.hasTurtleOutput);
32
- const isGraphicsmodalOpen = useStore(store, (state) => state.isGraphicsmodalOpen);
33
-
34
- return (
35
- <React.Fragment>
36
- <Header
37
- slim={props.slim}
38
- title={props.title}
39
- resettable={props.resettable}
40
- download={props.download}
41
- noCompare={props.noCompare}
42
- />
43
- <EditorAce
44
- showLineNumbers={props.showLineNumbers}
45
- maxLines={props.maxLines}
46
- versioned={props.versioned}
47
- />
48
- {lang === 'python' &&
49
- <>
50
- <Result />
51
- <div id={DOM_ELEMENT_IDS.outputDiv(codeId)}></div>
52
- {isGraphicsmodalOpen && (
53
- <>
54
- {hasTurtleOutput && (
55
- <Turtle />
56
- )}
57
- {hasCanvasOutput && (
58
- <Canvas />
59
- )}
60
- {!hasCanvasOutput && !hasTurtleOutput && (
61
- <Graphics />
62
- )}
63
- </>
64
- )}
65
- </>
66
- }
67
- </React.Fragment>
68
- );
30
+ const store = useStore();
31
+ const lang = useScript(store, 'lang');
32
+ const codeId = useScript(store, 'codeId');
33
+ const hasCanvasOutput = useScript(store, 'hasCanvasOutput');
34
+ const hasTurtleOutput = useScript(store, 'hasTurtleOutput');
35
+ const graphicsModalExecutionNr = useScript(store, 'graphicsModalExecutionNr');
36
+
37
+ return (
38
+ <React.Fragment>
39
+ <Header
40
+ slim={props.slim}
41
+ title={props.title}
42
+ resettable={props.resettable}
43
+ download={props.download}
44
+ noCompare={props.noCompare}
45
+ />
46
+ <div className={clsx(styles.editorContainer)}>
47
+ <HiddenCode type="pre" code={props.preCode} />
48
+ <EditorAce
49
+ showLineNumbers={props.showLineNumbers}
50
+ maxLines={props.maxLines}
51
+ versioned={props.versioned}
52
+ onChange={props.onChange}
53
+ />
54
+ <HiddenCode type="post" code={props.postCode} />
55
+ </div>
56
+ {lang === 'python' && (
57
+ <>
58
+ <Result />
59
+ <div id={DOM_ELEMENT_IDS.outputDiv(codeId)}></div>
60
+ {graphicsModalExecutionNr > 0 && (
61
+ <>
62
+ {hasTurtleOutput && <Turtle />}
63
+ {hasCanvasOutput && <Canvas />}
64
+ {!hasCanvasOutput && !hasTurtleOutput && <Graphics />}
65
+ </>
66
+ )}
67
+ </>
68
+ )}
69
+ </React.Fragment>
70
+ );
69
71
  };
70
72
 
71
- export default Editor;
73
+ export default Editor;
@@ -1,20 +1,28 @@
1
+ .editorContainer {
2
+ grid-area: editor;
3
+ position: relative;
4
+ --show-hidden-code-toggle-opacity: 0;
5
+ }
1
6
  .editor {
2
- grid-area: editor;
3
7
  display: flex;
4
8
  flex-wrap: wrap;
5
9
  }
6
10
 
7
11
  .editor .noGutter :global(.ace_scroller) {
8
- left: 4px !important;
12
+ left: 4px !important;
9
13
  }
10
14
 
11
15
  .editor :global(.ace_scrollbar.ace_scrollbar-h) {
12
- overflow-x: hidden !important;
16
+ overflow-x: hidden !important;
13
17
  }
14
18
 
15
19
  .brythonEditor {
16
- flex-grow: 1;
17
- flex-basis: 80ch;
18
- /*rtl:ignore*/
19
- direction: ltr;
20
+ flex-grow: 1;
21
+ flex-basis: 80ch;
22
+ /*rtl:ignore*/
23
+ direction: ltr;
24
+ }
25
+
26
+ .editorContainer:hover {
27
+ --show-hidden-code-toggle-opacity: 1;
20
28
  }
@@ -1,8 +1,8 @@
1
- import {DraggableEvent} from 'react-draggable';
1
+ import { DraggableEvent } from 'react-draggable';
2
2
  /**
3
3
  * When using react-draggable, the click-event is not propagated
4
4
  * to the button on touch devices. Fix this by clicking the button
5
- * programmatically.
5
+ * programmatically.
6
6
  */
7
7
  const checkForButtonClick = (event: DraggableEvent) => {
8
8
  if (!event.type || event.type.toLowerCase() !== 'touchend') {
@@ -19,7 +19,7 @@ const checkForButtonClick = (event: DraggableEvent) => {
19
19
  }
20
20
  if (elem.tagName.toLowerCase() === 'div') {
21
21
  if (elem.classList.contains('react-draggable')) {
22
- elem = null
22
+ elem = null;
23
23
  break;
24
24
  }
25
25
  }
@@ -28,6 +28,6 @@ const checkForButtonClick = (event: DraggableEvent) => {
28
28
  // add the click to the end of the event queue
29
29
  setTimeout(() => elem?.click(), 1);
30
30
  }
31
- }
31
+ };
32
32
 
33
- export { checkForButtonClick }
33
+ export { checkForButtonClick };