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