docusaurus-live-brython 3.0.0-beta.11 → 3.0.0-beta.5

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 (75) hide show
  1. package/lib/index.d.ts +7 -0
  2. package/lib/index.js +0 -15
  3. package/lib/theme/CodeBlock/index.jsx +2 -2
  4. package/lib/theme/CodeEditor/Actions/DownloadCode.jsx +2 -2
  5. package/lib/theme/CodeEditor/Actions/Reset.jsx +2 -2
  6. package/lib/theme/CodeEditor/Actions/RunCode.d.ts +1 -1
  7. package/lib/theme/CodeEditor/Actions/RunCode.jsx +2 -2
  8. package/lib/theme/CodeEditor/Actions/ShowRaw.jsx +2 -2
  9. package/lib/theme/CodeEditor/Actions/ShowSyncStatus.jsx +3 -3
  10. package/lib/theme/CodeEditor/BrythonCommunicator.jsx +2 -2
  11. package/lib/theme/CodeEditor/Button/index.d.ts +2 -2
  12. package/lib/theme/CodeEditor/Button/index.jsx +1 -1
  13. package/lib/theme/CodeEditor/CodeHistory/index.jsx +2 -2
  14. package/lib/theme/CodeEditor/Editor/EditorAce.jsx +2 -2
  15. package/lib/theme/CodeEditor/Editor/Header/index.d.ts +1 -1
  16. package/lib/theme/CodeEditor/Editor/Header/index.jsx +6 -6
  17. package/lib/theme/CodeEditor/Editor/Result/Graphics/Canvas.d.ts +2 -2
  18. package/lib/theme/CodeEditor/Editor/Result/Graphics/Canvas.jsx +7 -7
  19. package/lib/theme/CodeEditor/Editor/Result/Graphics/Turtle.d.ts +2 -2
  20. package/lib/theme/CodeEditor/Editor/Result/Graphics/Turtle.jsx +8 -8
  21. package/lib/theme/CodeEditor/Editor/Result/Graphics/index.d.ts +3 -3
  22. package/lib/theme/CodeEditor/Editor/Result/Graphics/index.jsx +6 -6
  23. package/lib/theme/CodeEditor/Editor/Result/index.d.ts +3 -1
  24. package/lib/theme/CodeEditor/Editor/Result/index.jsx +3 -2
  25. package/lib/theme/CodeEditor/Editor/index.d.ts +1 -1
  26. package/lib/theme/CodeEditor/Editor/index.jsx +11 -11
  27. package/lib/theme/CodeEditor/Editor/utils/saveSvg.js +1 -1
  28. package/lib/theme/CodeEditor/Icon/index.d.ts +2 -2
  29. package/lib/theme/CodeEditor/Icon/index.jsx +1 -1
  30. package/lib/theme/CodeEditor/WithScript/Storage.d.ts +1 -1
  31. package/lib/theme/CodeEditor/WithScript/Store.d.ts +7 -1
  32. package/lib/theme/CodeEditor/WithScript/Store.jsx +235 -2
  33. package/lib/theme/CodeEditor/WithScript/Types.d.ts +0 -1
  34. package/lib/theme/CodeEditor/index.d.ts +3 -3
  35. package/lib/theme/CodeEditor/index.jsx +6 -6
  36. package/lib/types.d.ts +28 -0
  37. package/lib/types.js +1 -0
  38. package/package.json +20 -74
  39. package/src/index.ts +0 -10
  40. package/src/theme/CodeBlock/index.tsx +3 -2
  41. package/src/theme/CodeEditor/Actions/DownloadCode.tsx +2 -2
  42. package/src/theme/CodeEditor/Actions/Reset.tsx +2 -2
  43. package/src/theme/CodeEditor/Actions/RunCode.tsx +3 -3
  44. package/src/theme/CodeEditor/Actions/ShowRaw.tsx +2 -2
  45. package/src/theme/CodeEditor/Actions/ShowSyncStatus.tsx +3 -3
  46. package/src/theme/CodeEditor/BrythonCommunicator.tsx +3 -3
  47. package/src/theme/CodeEditor/Button/index.tsx +3 -3
  48. package/src/theme/CodeEditor/CodeHistory/index.tsx +2 -2
  49. package/src/theme/CodeEditor/Editor/EditorAce.tsx +2 -2
  50. package/src/theme/CodeEditor/Editor/Header/index.tsx +7 -7
  51. package/src/theme/CodeEditor/Editor/Result/Graphics/Canvas.tsx +7 -7
  52. package/src/theme/CodeEditor/Editor/Result/Graphics/Turtle.tsx +8 -8
  53. package/src/theme/CodeEditor/Editor/Result/Graphics/index.tsx +7 -7
  54. package/src/theme/CodeEditor/Editor/Result/index.tsx +6 -2
  55. package/src/theme/CodeEditor/Editor/index.tsx +15 -13
  56. package/src/theme/CodeEditor/Editor/utils/saveSvg.ts +1 -1
  57. package/src/theme/CodeEditor/Editor/utils/svgWithoutAnimations.ts +1 -1
  58. package/src/theme/CodeEditor/Icon/index.tsx +2 -2
  59. package/src/theme/CodeEditor/WithScript/Storage.ts +1 -1
  60. package/src/theme/CodeEditor/WithScript/Store.tsx +269 -3
  61. package/src/theme/CodeEditor/WithScript/Types.ts +0 -1
  62. package/src/theme/CodeEditor/index.tsx +8 -8
  63. package/src/types.ts +29 -0
  64. package/lib/theme/CodeEditor/WithScript/createStore.d.ts +0 -2
  65. package/lib/theme/CodeEditor/WithScript/createStore.js +0 -223
  66. package/lib/theme/CodeEditor/hooks/index.d.ts +0 -2
  67. package/lib/theme/CodeEditor/hooks/index.js +0 -2
  68. package/lib/theme/CodeEditor/hooks/useScript.d.ts +0 -4
  69. package/lib/theme/CodeEditor/hooks/useScript.js +0 -10
  70. package/lib/theme/CodeEditor/hooks/useStore.d.ts +0 -2
  71. package/lib/theme/CodeEditor/hooks/useStore.js +0 -4
  72. package/src/theme/CodeEditor/WithScript/createStore.ts +0 -247
  73. package/src/theme/CodeEditor/hooks/index.ts +0 -2
  74. package/src/theme/CodeEditor/hooks/useScript.ts +0 -15
  75. package/src/theme/CodeEditor/hooks/useStore.ts +0 -9
@@ -1,6 +1,232 @@
1
- import React from "react";
1
+ import React, { useCallback } from "react";
2
+ import { useSyncExternalStore } from "react";
3
+ import { v4 as uuidv4 } from 'uuid';
4
+ import { checkCanvasOutput, checkGraphicsOutput, checkTurtleOutput, getPreCode, sanitizePyScript } from "./helpers";
5
+ import { ReactContextError, createStorageSlot } from "@docusaurus/theme-common";
2
6
  import { usePluginData } from "@docusaurus/useGlobalData";
3
- import { createStore } from "@theme/CodeEditor/WithScript/createStore";
7
+ import { DOM_ELEMENT_IDS } from "../constants";
8
+ import throttle from 'lodash/throttle';
9
+ import { getStorageScript, syncStorageScript } from "./Storage";
10
+ import { Status } from "./Types";
11
+ export const createStore = (props, libDir, syncMaxOnceEvery) => {
12
+ const canSave = !!props.id;
13
+ const id = props.id || uuidv4();
14
+ const codeId = `code.${props.title || props.lang}.${id}`.replace(/(-|\.)/g, '_');
15
+ const createdAt = new Date();
16
+ const storageKey = `code.${props.title || 'code_block'}.${id}`;
17
+ const storage = createStorageSlot(storageKey);
18
+ storage.listen((e) => {
19
+ if (e.key === storageKey) {
20
+ try {
21
+ if (e.newValue) {
22
+ const script = JSON.parse(e.newValue);
23
+ if (new Date(script.updatedAt) > state.updatedAt) {
24
+ loadData(storage);
25
+ }
26
+ }
27
+ }
28
+ catch (err) {
29
+ console.warn(err);
30
+ }
31
+ }
32
+ });
33
+ const loadData = (store) => {
34
+ setState((s) => ({ ...s, status: canSave ? Status.SYNCING : s.status }));
35
+ const script = getStorageScript(store);
36
+ const loadedCode = script?.code ? prepareCode(script.code, { codeOnly: true }) : {};
37
+ addVersion.cancel();
38
+ if (!state.isLoaded) {
39
+ setState((s) => ({
40
+ ...s,
41
+ isLoaded: true,
42
+ ...(script || {}),
43
+ ...loadedCode,
44
+ versions: script?.versions || [],
45
+ versionsLoaded: true,
46
+ status: canSave ? Status.SUCCESS : s.status
47
+ }));
48
+ return Status.SUCCESS;
49
+ }
50
+ if (script) {
51
+ setState((s) => ({ ...s, ...script, ...loadedCode, status: canSave ? Status.SUCCESS : s.status, versionsLoaded: true }));
52
+ return Status.SUCCESS;
53
+ }
54
+ setState((s) => ({ ...s, status: canSave ? Status.ERROR : s.status }));
55
+ return Status.ERROR;
56
+ };
57
+ const prepareCode = (raw, config = {}) => {
58
+ const { pre, code } = config.codeOnly
59
+ ? { pre: getPreCode(state.pristineCode).pre, code: raw }
60
+ : getPreCode(raw);
61
+ const hasEdits = code !== (config.stateNotInitialized ? getPreCode(props.raw).code : state.pristineCode);
62
+ const updatedAt = new Date();
63
+ const hasCanvasOutput = checkCanvasOutput(raw);
64
+ const hasTurtleOutput = checkTurtleOutput(raw);
65
+ const hasGraphicsOutput = checkGraphicsOutput(raw);
66
+ if (props.versioned && !config.stateNotInitialized) {
67
+ addVersion({ code: code, createdAt: updatedAt, version: state.versions.length + 1 });
68
+ }
69
+ return {
70
+ code: code,
71
+ preCode: pre,
72
+ hasCanvasOutput: hasCanvasOutput,
73
+ hasTurtleOutput: hasTurtleOutput,
74
+ hasGraphicsOutput: hasGraphicsOutput,
75
+ hasEdits: hasEdits,
76
+ updatedAt: updatedAt
77
+ };
78
+ };
79
+ const setCode = (raw, action) => {
80
+ if (state.isPasted && action === 'remove') {
81
+ return;
82
+ }
83
+ const data = prepareCode(raw);
84
+ setState((state) => ({
85
+ ...state,
86
+ ...data
87
+ }));
88
+ if (props.id) {
89
+ const toStore = { code: data.code, createdAt: state.createdAt, updatedAt: data.updatedAt, versions: state.versions };
90
+ if (state.isPasted) {
91
+ addVersion.flush();
92
+ if (toStore.versions.length > 0) {
93
+ toStore.versions[toStore.versions.length - 1].pasted = true;
94
+ }
95
+ set(toStore);
96
+ set.flush();
97
+ state.isPasted = false;
98
+ }
99
+ else {
100
+ set(toStore);
101
+ }
102
+ }
103
+ };
104
+ const execScript = () => {
105
+ const toExec = `${state.code}`;
106
+ const lineShift = state.preCode.split(/\n/).length;
107
+ const src = `from brython_runner import run
108
+ run("""${sanitizePyScript(toExec || '')}""", '${codeId}', ${lineShift})
109
+ `;
110
+ if (!window.__BRYTHON__) {
111
+ alert('Brython not loaded');
112
+ return;
113
+ }
114
+ setState((s) => ({ ...s, isExecuting: true, isGraphicsmodalOpen: state.hasGraphicsOutput }));
115
+ const active = document.getElementById(DOM_ELEMENT_IDS.communicator(state.codeId));
116
+ active.setAttribute('data--start-time', `${Date.now()}`);
117
+ /**
118
+ * ensure that the script is executed after the current event loop.
119
+ * Otherwise, the brython script will not be able to access the graphics output.
120
+ */
121
+ setTimeout(() => {
122
+ window.__BRYTHON__.runPythonSource(src, {
123
+ pythonpath: [libDir]
124
+ });
125
+ }, 0);
126
+ };
127
+ const load = async () => {
128
+ return loadData(storage);
129
+ };
130
+ const _set = async (script) => {
131
+ setState((s) => ({ ...s, status: canSave ? Status.SYNCING : s.status }));
132
+ if (syncStorageScript(script, storage)) {
133
+ setState((s) => ({ ...s, status: canSave ? Status.SUCCESS : s.status }));
134
+ return Status.SUCCESS;
135
+ }
136
+ setState((s) => ({ ...s, status: canSave ? Status.ERROR : s.status }));
137
+ return Status.ERROR;
138
+ };
139
+ const set = throttle(_set, syncMaxOnceEvery, { leading: false, trailing: true });
140
+ const _addVersion = (version) => {
141
+ if (!props.versioned || !props.id) {
142
+ return;
143
+ }
144
+ const versions = [...state.versions];
145
+ versions.push(version);
146
+ setState((s) => ({ ...s, versions: versions }));
147
+ };
148
+ const addVersion = throttle(_addVersion, syncMaxOnceEvery, { leading: false, trailing: true });
149
+ const saveNow = async () => {
150
+ addVersion.flush();
151
+ return set.flush();
152
+ };
153
+ const del = async () => {
154
+ storage.del();
155
+ return Status.SUCCESS;
156
+ };
157
+ const codeData = prepareCode(props.raw, { stateNotInitialized: true });
158
+ const setExecuting = (isExecuting) => {
159
+ setState((s) => ({ ...s, isExecuting: isExecuting }));
160
+ };
161
+ const addLogMessage = (log) => {
162
+ setState((s) => ({ ...s, logs: [...s.logs, log] }));
163
+ };
164
+ const clearLogMessages = () => {
165
+ setState((s) => ({ ...s, logs: [] }));
166
+ };
167
+ const closeGraphicsModal = () => {
168
+ setState((s) => ({ ...s, isGraphicsmodalOpen: false }));
169
+ };
170
+ const stopScript = () => {
171
+ const code = document.getElementById(DOM_ELEMENT_IDS.communicator(state.codeId));
172
+ if (code) {
173
+ code.removeAttribute('data--start-time');
174
+ }
175
+ };
176
+ let state = {
177
+ id: id,
178
+ codeId: codeId,
179
+ lang: props.lang,
180
+ showRaw: false,
181
+ pristineCode: codeData.code,
182
+ isExecuting: false,
183
+ logs: [],
184
+ isGraphicsmodalOpen: false,
185
+ hasEdits: false,
186
+ createdAt: createdAt,
187
+ isLoaded: false,
188
+ status: Status.IDLE,
189
+ versions: [],
190
+ versionsLoaded: false,
191
+ isPasted: false,
192
+ ...codeData
193
+ };
194
+ const getState = () => state;
195
+ const listeners = new Set();
196
+ const setState = (fn) => {
197
+ state = fn(state);
198
+ listeners.forEach((l) => l());
199
+ };
200
+ const subscribe = (listener) => {
201
+ listeners.add(listener);
202
+ return () => listeners.delete(listener);
203
+ };
204
+ const loadVersions = async () => {
205
+ // noop
206
+ state.isLoaded = false;
207
+ load();
208
+ setState((s) => ({ ...s, versionsLoaded: true }));
209
+ return Promise.resolve();
210
+ };
211
+ return {
212
+ getState,
213
+ setState,
214
+ subscribe,
215
+ saveNow,
216
+ addLogMessage,
217
+ clearLogMessages,
218
+ closeGraphicsModal,
219
+ setCode,
220
+ execScript,
221
+ setExecuting,
222
+ stopScript,
223
+ load,
224
+ loadVersions
225
+ };
226
+ };
227
+ export const useStore = (store, selector) => {
228
+ return useSyncExternalStore(store.subscribe, useCallback(() => selector(store.getState()), [store, selector]));
229
+ };
4
230
  export const Context = React.createContext(undefined);
5
231
  const ScriptContext = (props) => {
6
232
  const { libDir, syncMaxOnceEvery } = usePluginData('docusaurus-live-brython');
@@ -17,4 +243,11 @@ const ScriptContext = (props) => {
17
243
  {props.children}
18
244
  </Context.Provider>);
19
245
  };
246
+ export function useScript() {
247
+ const context = React.useContext(Context);
248
+ if (context === null) {
249
+ throw new ReactContextError('ScriptContextProvider', 'The Component must be a child of the CodeContextProvider component');
250
+ }
251
+ return context;
252
+ }
20
253
  export default ScriptContext;
@@ -10,7 +10,6 @@ export interface StoredScript {
10
10
  updatedAt: Date;
11
11
  versions: Version[];
12
12
  }
13
- export type Selector<T, R> = (state: T) => R;
14
13
  export interface Script extends StoredScript {
15
14
  /**
16
15
  * this is normally a uuid
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- export interface Props {
2
+ interface Props {
3
3
  slim: boolean;
4
4
  readonly: boolean;
5
5
  children: React.ReactNode;
@@ -14,5 +14,5 @@ export interface Props {
14
14
  maxLines?: number;
15
15
  noHistory: boolean;
16
16
  }
17
- declare const CodeEditor: (props: Props) => React.JSX.Element;
18
- export default CodeEditor;
17
+ declare const PyAceEditor: (props: Props) => React.JSX.Element;
18
+ export default PyAceEditor;
@@ -1,12 +1,12 @@
1
1
  import * as React from 'react';
2
2
  import styles from './styles.module.css';
3
- import Editor from '@theme/CodeEditor/Editor';
4
- import BrythonCommunicator from '@theme/CodeEditor/BrythonCommunicator';
3
+ import Editor from './Editor';
4
+ import BrythonCommunicator from './BrythonCommunicator';
5
5
  import clsx from 'clsx';
6
- import { useScript, useStore } from '@theme/CodeEditor/hooks';
6
+ import { useScript, useStore } from './WithScript/Store';
7
7
  import BrowserOnly from '@docusaurus/BrowserOnly';
8
- import CodeHistory from '@theme/CodeEditor/CodeHistory';
9
- const CodeEditor = (props) => {
8
+ import CodeHistory from './CodeHistory';
9
+ const PyAceEditor = (props) => {
10
10
  const { store } = useScript();
11
11
  const lang = useStore(store, (state) => state.lang);
12
12
  return (<BrowserOnly fallback={<div>Loading...</div>}>
@@ -21,4 +21,4 @@ const CodeEditor = (props) => {
21
21
  }}
22
22
  </BrowserOnly>);
23
23
  };
24
- export default CodeEditor;
24
+ export default PyAceEditor;
package/lib/types.d.ts ADDED
@@ -0,0 +1,28 @@
1
+ export type ThemeOptions = {
2
+ /**
3
+ * The path to the brython source file.
4
+ * @default 'https://raw.githack.com/brython-dev/brython/master/www/src/brython.js
5
+ */
6
+ brython_src?: string;
7
+ /**
8
+ * The path to the brython standard library source file.
9
+ * @default 'https://raw.githack.com/brython-dev/brython/master/www/src/brython_stdlib.js'
10
+ */
11
+ brython_stdlib_src?: string;
12
+ /**
13
+ * The folder path to brython specific libraries.
14
+ * When a python file imports a module, the module is searched in the libDir directory.
15
+ * By default, the libDir is created in the static folder and the needed python files are copied there.
16
+ * This can be changed by setting skipCopyAssetsToLibDir to true and setting libDir to a custom path.
17
+ * Make sure to copy the needed python files to the custom libDir.
18
+ * @default '/bry-libs/'
19
+ */
20
+ libDir?: string;
21
+ /**
22
+ * Skip copying the brython specific libraries to the libDir.
23
+ * Make sure to copy the needed python files to the custom libDir yourself.
24
+ * @ref [needed python files](https://github.com/lebalz/docusaurus-live-brython/tree/main/src/assets)
25
+ * @default false
26
+ */
27
+ skipCopyAssetsToLibDir?: boolean;
28
+ };
package/lib/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docusaurus-live-brython",
3
- "version": "3.0.0-beta.11",
3
+ "version": "3.0.0-beta.5",
4
4
  "description": "Docusaurus live code block component for python.",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -13,66 +13,8 @@
13
13
  "types": "./lib/index.d.ts",
14
14
  "default": "./lib/index.js"
15
15
  },
16
- "./theme/CodeEditor/hooks": {
17
- "types": "./lib/theme/CodeEditor/hooks/index.d.ts",
18
- "default": "./lib/theme/CodeEditor/hooks/index.js"
19
- },
20
- "./theme/CodeEditor/Editor": {
21
- "types": "./lib/theme/CodeEditor/Editor/index.d.ts",
22
- "default": "./lib/theme/CodeEditor/Editor/index.jsx"
23
- },
24
- "./theme/CodeEditor/Editor/Result": {
25
- "types": "./lib/theme/CodeEditor/Editor/Result/index.d.ts",
26
- "default": "./lib/theme/CodeEditor/Editor/Result/index.jsx"
27
- },
28
- "./theme/CodeEditor/Editor/Header": {
29
- "types": "./lib/theme/CodeEditor/Editor/Header/index.d.ts",
30
- "default": "./lib/theme/CodeEditor/Editor/Header/index.jsx"
31
- },
32
- "./theme/CodeEditor/Editor/Result/Graphics": {
33
- "types": "./lib/theme/CodeEditor/Editor/Result/Graphics/index.d.ts",
34
- "default": "./lib/theme/CodeEditor/Editor/Result/Graphics/index.jsx"
35
- },
36
- "./theme/CodeEditor/CodeHistory": {
37
- "types": "./lib/theme/CodeEditor/CodeHistory/index.d.ts",
38
- "default": "./lib/theme/CodeEditor/CodeHistory/index.jsx"
39
- },
40
- "./theme/CodeEditor/Icon": {
41
- "types": "./lib/theme/CodeEditor/Icon/index.d.ts",
42
- "default": "./lib/theme/CodeEditor/Icon/index.jsx"
43
- },
44
- "./theme/CodeEditor/Button": {
45
- "types": "./lib/theme/CodeEditor/Button/index.d.ts",
46
- "default": "./lib/theme/CodeEditor/Button/index.jsx"
47
- },
48
- "./theme/CodeEditor/constants": {
49
- "types": "./lib/theme/CodeEditor/constants.d.ts",
50
- "default": "./lib/theme/CodeEditor/constants.js"
51
- },
52
- "./theme/CodeEditor/Icon/icons": {
53
- "types": "./lib/theme/CodeEditor/Icon/icons.d.ts",
54
- "default": "./lib/theme/CodeEditor/Icon/icons.js"
55
- },
56
- "./theme/CodeEditor": {
57
- "types": "./lib/theme/CodeEditor/index.d.ts",
58
- "default": "./lib/theme/CodeEditor/index.jsx"
59
- },
60
- "./theme/CodeEditor/Editor/utils/*": {
61
- "types": "./lib/theme/CodeEditor/Editor/utils/*.d.ts",
62
- "default": "./lib/theme/CodeEditor/Editor/utils/*.js"
63
- },
64
- "./theme/CodeEditor/WithScript/Store": {
65
- "types": "./lib/theme/CodeEditor/WithScript/Store.d.ts",
66
- "default": "./lib/theme/CodeEditor/WithScript/Store.jsx"
67
- },
68
- "./theme/CodeEditor/WithScript/*": {
69
- "types": "./lib/theme/CodeEditor/WithScript/*.d.ts",
70
- "default": "./lib/theme/CodeEditor/WithScript/*.js"
71
- },
72
- "./theme/CodeEditor/*": {
73
- "types": "./lib/theme/CodeEditor/*.d.ts",
74
- "default": "./lib/theme/CodeEditor/*.jsx"
75
- }
16
+ "./lib/*": "./lib/*",
17
+ "./src/*": "./src/*"
76
18
  },
77
19
  "scripts": {
78
20
  "build": "tsc --build && node ./bin/copyUntypedFiles.js && prettier --config ./.prettierrc --write \"lib/theme/**/*.js\"",
@@ -89,26 +31,23 @@
89
31
  "bugs": "https://github.com/lebalz/docusaurus-live-brython/issues",
90
32
  "homepage": "https://lebalz.github.io/docusaurus-live-brython/",
91
33
  "dependencies": {
92
- "@docusaurus/core": "3.3.2",
93
- "@docusaurus/theme-classic": "3.3.2",
94
- "@docusaurus/theme-common": "3.3.2",
95
- "@docusaurus/theme-translations": "3.3.2",
96
- "@docusaurus/utils-validation": "3.3.2",
97
- "ace-builds": "^1.34.2",
34
+ "ace-builds": "^1.4.12",
98
35
  "clsx": "^2.1.1",
99
36
  "lodash": "^4.17.21",
100
- "prism-react-renderer": "^2.3.1",
101
37
  "rc-slider": "^10.6.2",
102
- "react-ace": "^11.0.1",
38
+ "react-ace": "^9.4.3",
103
39
  "react-diff-viewer": "^3.1.1",
104
- "react-draggable": "^4.4.6",
40
+ "react-draggable": "^4.4.3",
105
41
  "svg-parser": "^2.0.4",
106
42
  "uuid": "^9.0.1"
107
43
  },
108
44
  "devDependencies": {
109
- "@docusaurus/module-type-aliases": "3.3.2",
110
- "@docusaurus/tsconfig": "3.3.2",
111
- "@docusaurus/types": "3.3.2",
45
+ "@docusaurus/core": "^3.3.2",
46
+ "@docusaurus/module-type-aliases": "^3.3.2",
47
+ "@docusaurus/theme-classic": "^3.3.2",
48
+ "@docusaurus/theme-common": "^3.3.2",
49
+ "@docusaurus/tsconfig": "^3.3.2",
50
+ "@docusaurus/types": "^3.3.2",
112
51
  "@types/fs-extra": "^11.0.4",
113
52
  "@types/lodash": "^4.17.4",
114
53
  "@types/svg-parser": "^2.0.6",
@@ -118,7 +57,14 @@
118
57
  "fs-extra": "^11.2.0",
119
58
  "npm-run-all": "^4.1.5",
120
59
  "prettier": "^3.2.5",
121
- "typescript": "^5.4.5"
60
+ "prism-react-renderer": "^2.3.1",
61
+ "typescript": "^5.4.2"
62
+ },
63
+ "peerDependencies": {
64
+ "@docusaurus/core": "^3.3.2",
65
+ "@docusaurus/theme-common": "^3.3.2",
66
+ "prism-react-renderer": "^2.1",
67
+ "webpack": "^5.0.0"
122
68
  },
123
69
  "engines": {
124
70
  "node": ">=18"
package/src/index.ts CHANGED
@@ -14,7 +14,6 @@
14
14
  *
15
15
  */
16
16
 
17
- import {readDefaultCodeTranslationMessages} from '@docusaurus/theme-translations';
18
17
  import type { HtmlTags, LoadContext, Plugin } from '@docusaurus/types';
19
18
  // eslint-disable-next-line import/no-extraneous-dependencies, import/order
20
19
  import logger from '@docusaurus/logger';
@@ -31,9 +30,6 @@ const theme: Plugin<{ remoteHeadTags: HtmlTags[] }> = (
31
30
  context: LoadContext,
32
31
  options: ThemeOptions,
33
32
  ) => {
34
- const {
35
- i18n: {currentLocale},
36
- } = context;
37
33
  const libDir = options.libDir || DEFAULT_LIB_DIR;
38
34
  return {
39
35
  name: NAME,
@@ -53,12 +49,6 @@ const theme: Plugin<{ remoteHeadTags: HtmlTags[] }> = (
53
49
  }
54
50
  }
55
51
  },
56
- getDefaultCodeTranslationMessages() {
57
- return readDefaultCodeTranslationMessages({
58
- locale: currentLocale,
59
- name: NAME,
60
- });
61
- },
62
52
  async contentLoaded({ content, actions }) {
63
53
  const { setGlobalData } = actions;
64
54
  const libDir = (options.libDir || DEFAULT_LIB_DIR).replace(/(\/|\\)/g, '');
@@ -1,10 +1,11 @@
1
1
  import React from 'react';
2
2
  import CodeBlock, {type Props as CodeBlockType} from '@theme-init/CodeBlock';
3
+ // @ts-ignore
3
4
  import type { WrapperProps } from '@docusaurus/types';
4
5
  import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
5
- import CodeEditor from '@theme/CodeEditor';
6
+ import CodeEditor from '../CodeEditor';
6
7
 
7
- import ScriptContext from '@theme/CodeEditor/WithScript/Store';
8
+ import ScriptContext from '../CodeEditor/WithScript/Store';
8
9
 
9
10
 
10
11
  type Props = WrapperProps<typeof CodeBlockType>;
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
- import { useScript, useStore } from '@theme/CodeEditor/hooks';
3
- import Button, { Color } from '@theme/CodeEditor/Button';
2
+ import { useScript, useStore } from '../WithScript/Store';
3
+ import Button, { Color } from '../Button';
4
4
  import { translate } from '@docusaurus/Translate';
5
5
 
6
6
 
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
- import { useScript, useStore } from '@theme/CodeEditor/hooks';
3
- import Button, { Color } from '@theme/CodeEditor/Button';
2
+ import { useScript, useStore } from '../WithScript/Store';
3
+ import Button, { Color } from '../Button';
4
4
  import { translate } from '@docusaurus/Translate';
5
5
 
6
6
  const Reset = () => {
@@ -1,11 +1,11 @@
1
1
  import * as React from 'react';
2
- import { useScript, useStore } from '@theme/CodeEditor/hooks';
3
- import Button, { Color } from '@theme/CodeEditor/Button';
2
+ import { useScript, useStore } from '../WithScript/Store';
3
+ import Button, { Color } from '../Button';
4
4
  import { translate } from '@docusaurus/Translate';
5
5
  import styles from './styles.module.css';
6
6
  import clsx from 'clsx';
7
7
 
8
- export interface Props {
8
+ interface Props {
9
9
  title: string;
10
10
  slim: boolean;
11
11
  }
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
- import { useScript, useStore } from '@theme/CodeEditor/hooks';
3
- import Button, { Color } from '@theme/CodeEditor/Button';
2
+ import { useScript, useStore } from '../WithScript/Store';
3
+ import Button, { Color } from '../Button';
4
4
  import { translate } from '@docusaurus/Translate';
5
5
 
6
6
  const ShowRaw = () => {
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
- import { useScript, useStore } from '@theme/CodeEditor/hooks';
3
- import Icon, { Color } from '@theme/CodeEditor/Icon';
4
- import { Status } from '@theme/CodeEditor/WithScript/Types';
2
+ import { useScript, useStore } from '../WithScript/Store';
3
+ import Icon, { Color } from '../Icon';
4
+ import { Status } from '../WithScript/Types';
5
5
 
6
6
  const ShowSyncStatus = () => {
7
7
  const { store } = useScript();
@@ -1,7 +1,7 @@
1
1
  import * as React from "react";
2
- import { BRYTHON_NOTIFICATION_EVENT, DOM_ELEMENT_IDS } from "@theme/CodeEditor/constants";
3
- import { useScript, useStore } from '@theme/CodeEditor/hooks';
4
- import { type LogMessage } from '@theme/CodeEditor/WithScript/Types';
2
+ import { BRYTHON_NOTIFICATION_EVENT, DOM_ELEMENT_IDS } from "./constants";
3
+ import { useScript, useStore } from './WithScript/Store';
4
+ import { type LogMessage } from './WithScript/Types';
5
5
 
6
6
  const BrythonCommunicator = () => {
7
7
  const { store } = useScript();
@@ -1,8 +1,8 @@
1
1
  import * as React from 'react';
2
- import * as Icons from '@theme/CodeEditor/Icon/icons';
2
+ import * as Icons from '../Icon/icons';
3
3
  import styles from './styles.module.css';
4
4
  import clsx from 'clsx';
5
- import Icon from '@theme/CodeEditor/Icon';
5
+ import Icon from '../Icon';
6
6
 
7
7
  export enum Color {
8
8
  Primary = 'button--primary',
@@ -18,7 +18,7 @@ export enum Size {
18
18
  Large = 'button--lg',
19
19
  }
20
20
 
21
- export interface Props {
21
+ interface Props {
22
22
  icon: keyof typeof Icons;
23
23
  title?: string;
24
24
  onClick?: React.MouseEventHandler<HTMLButtonElement>;
@@ -4,9 +4,9 @@ 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 { useScript, useStore } from '@theme/CodeEditor/hooks';
7
+ import { useScript, useStore } from '../WithScript/Store';
8
8
  import Translate, { translate } from '@docusaurus/Translate';
9
- import Button from '@theme/CodeEditor/Button';
9
+ import Button from '../Button';
10
10
  import DiffViewer from 'react-diff-viewer';
11
11
  import Details from '@theme/Details';
12
12
 
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import clsx from 'clsx';
3
3
  import styles from './styles.module.css';
4
- import { DOM_ELEMENT_IDS } from '@theme/CodeEditor/constants';
4
+ import { DOM_ELEMENT_IDS } from '../constants';
5
5
  import AceEditor from 'react-ace';
6
6
  import 'ace-builds/src-noconflict/ext-searchbox';
7
7
  import 'ace-builds/src-noconflict/mode-python';
@@ -10,7 +10,7 @@ import 'ace-builds/src-noconflict/mode-svg';
10
10
  import 'ace-builds/src-noconflict/theme-dracula';
11
11
  import 'ace-builds/src-noconflict/ext-language_tools';
12
12
  import 'ace-builds/webpack-resolver';
13
- import { useScript, useStore } from '@theme/CodeEditor/hooks';
13
+ import { useScript, useStore } from '../WithScript/Store';
14
14
  // import 'ace-builds/src-noconflict/theme-textmate';
15
15
  // import('ace-builds/src-noconflict/snippets/python'),
16
16
 
@@ -1,14 +1,14 @@
1
1
  import * as React from 'react';
2
2
  import clsx from 'clsx';
3
3
  import styles from './styles.module.css';
4
- import { useScript, useStore } from '@theme/CodeEditor/hooks';
5
- import ShowSyncStatus from '@theme/CodeEditor/Actions/ShowSyncStatus';
6
- import Reset from '@theme/CodeEditor/Actions/Reset';
7
- import DownloadCode from '@theme/CodeEditor/Actions/DownloadCode';
8
- import ShowRaw from '@theme/CodeEditor/Actions/ShowRaw';
9
- import RunCode from '@theme/CodeEditor/Actions/RunCode';
4
+ import { useScript, useStore } from '../../WithScript/Store';
5
+ import ShowSyncStatus from '../../Actions/ShowSyncStatus';
6
+ import Reset from '../../Actions/Reset';
7
+ import DownloadCode from '../../Actions/DownloadCode';
8
+ import ShowRaw from '../../Actions/ShowRaw';
9
+ import RunCode from '../../Actions/RunCode';
10
10
 
11
- export interface Props {
11
+ interface Props {
12
12
  slim: boolean;
13
13
  title: string;
14
14
  resettable: boolean;