@dodona/papyros 3.0.2 → 4.0.0-beta-9

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 (233) hide show
  1. package/README.md +132 -72
  2. package/dist/Library.d.ts +10 -11
  3. package/dist/Library.js +9 -7
  4. package/dist/Library.js.map +1 -1
  5. package/dist/{Backend.d.ts → backend/Backend.d.ts} +3 -12
  6. package/dist/{Backend.js → backend/Backend.js} +4 -17
  7. package/dist/backend/Backend.js.map +1 -0
  8. package/dist/{workers → backend/workers}/javascript/JavaScriptWorker.js +1 -1
  9. package/dist/backend/workers/javascript/JavaScriptWorker.js.map +1 -0
  10. package/dist/backend/workers/javascript/worker.js.map +1 -0
  11. package/dist/{workers → backend/workers}/python/PythonWorker.d.ts +2 -2
  12. package/dist/{workers → backend/workers}/python/PythonWorker.js +2 -2
  13. package/dist/backend/workers/python/PythonWorker.js.map +1 -0
  14. package/dist/backend/workers/python/python_package.tar.gz.load_by_url +0 -0
  15. package/dist/backend/workers/python/worker.js.map +1 -0
  16. package/dist/communication/BackendEvent.js.map +1 -0
  17. package/dist/{BackendEventQueue.d.ts → communication/BackendEventQueue.d.ts} +1 -36
  18. package/dist/{BackendEventQueue.js → communication/BackendEventQueue.js} +2 -45
  19. package/dist/communication/BackendEventQueue.js.map +1 -0
  20. package/dist/{BackendManager.d.ts → communication/BackendManager.d.ts} +2 -2
  21. package/dist/{BackendManager.js → communication/BackendManager.js} +4 -4
  22. package/dist/communication/BackendManager.js.map +1 -0
  23. package/dist/communication/InputServiceWorker.js +37 -0
  24. package/dist/communication/InputServiceWorker.js.map +1 -0
  25. package/dist/communication/InputWorker.js.map +1 -0
  26. package/dist/frontend/components/CodeRunner.d.ts +9 -0
  27. package/dist/frontend/components/CodeRunner.js +60 -0
  28. package/dist/frontend/components/CodeRunner.js.map +1 -0
  29. package/dist/frontend/components/Debugger.d.ts +7 -0
  30. package/dist/frontend/components/Debugger.js +61 -0
  31. package/dist/frontend/components/Debugger.js.map +1 -0
  32. package/dist/frontend/components/Input.d.ts +13 -0
  33. package/dist/frontend/components/Input.js +65 -0
  34. package/dist/frontend/components/Input.js.map +1 -0
  35. package/dist/frontend/components/Output.d.ts +14 -0
  36. package/dist/frontend/components/Output.js +154 -0
  37. package/dist/frontend/components/Output.js.map +1 -0
  38. package/dist/frontend/components/PapyrosElement.d.ts +8 -0
  39. package/dist/frontend/components/PapyrosElement.js +24 -0
  40. package/dist/frontend/components/PapyrosElement.js.map +1 -0
  41. package/dist/frontend/components/app/App.d.ts +24 -0
  42. package/dist/frontend/components/app/App.js +204 -0
  43. package/dist/frontend/components/app/App.js.map +1 -0
  44. package/dist/frontend/components/app/ExamplePicker.d.ts +7 -0
  45. package/dist/frontend/components/app/ExamplePicker.js +35 -0
  46. package/dist/frontend/components/app/ExamplePicker.js.map +1 -0
  47. package/dist/frontend/components/app/LanguagePicker.d.ts +7 -0
  48. package/dist/frontend/components/app/LanguagePicker.js +35 -0
  49. package/dist/frontend/components/app/LanguagePicker.js.map +1 -0
  50. package/dist/frontend/components/app/ProgrammingLanguagePicker.d.ts +7 -0
  51. package/dist/frontend/components/app/ProgrammingLanguagePicker.js +39 -0
  52. package/dist/frontend/components/app/ProgrammingLanguagePicker.js.map +1 -0
  53. package/dist/frontend/components/app/examples/JavaScriptExamples.js.map +1 -0
  54. package/dist/frontend/components/app/examples/PythonExamples.js.map +1 -0
  55. package/dist/frontend/components/app/themes/ThemePicker.d.ts +11 -0
  56. package/dist/frontend/components/app/themes/ThemePicker.js +47 -0
  57. package/dist/frontend/components/app/themes/ThemePicker.js.map +1 -0
  58. package/dist/frontend/components/app/themes/ThemedButton.d.ts +9 -0
  59. package/dist/frontend/components/app/themes/ThemedButton.js +43 -0
  60. package/dist/frontend/components/app/themes/ThemedButton.js.map +1 -0
  61. package/dist/frontend/components/code_mirror/BatchInputEditor.d.ts +8 -0
  62. package/dist/frontend/components/code_mirror/BatchInputEditor.js +54 -0
  63. package/dist/frontend/components/code_mirror/BatchInputEditor.js.map +1 -0
  64. package/dist/frontend/components/code_mirror/CodeEditor.d.ts +24 -0
  65. package/dist/frontend/components/code_mirror/CodeEditor.js +205 -0
  66. package/dist/frontend/components/code_mirror/CodeEditor.js.map +1 -0
  67. package/dist/frontend/components/code_mirror/CodeMirrorEditor.d.ts +20 -0
  68. package/dist/frontend/components/code_mirror/CodeMirrorEditor.js +99 -0
  69. package/dist/frontend/components/code_mirror/CodeMirrorEditor.js.map +1 -0
  70. package/dist/frontend/components/code_mirror/Extensions.d.ts +15 -0
  71. package/dist/frontend/components/code_mirror/Extensions.js +169 -0
  72. package/dist/frontend/components/code_mirror/Extensions.js.map +1 -0
  73. package/dist/frontend/components/code_mirror/MaterialTheme.d.ts +5 -0
  74. package/dist/frontend/components/code_mirror/MaterialTheme.js +109 -0
  75. package/dist/frontend/components/code_mirror/MaterialTheme.js.map +1 -0
  76. package/dist/frontend/components/code_runner/ButtonLint.d.ts +9 -0
  77. package/dist/frontend/components/code_runner/ButtonLint.js +76 -0
  78. package/dist/frontend/components/code_runner/ButtonLint.js.map +1 -0
  79. package/dist/frontend/components/code_runner/Code.d.ts +7 -0
  80. package/dist/frontend/components/code_runner/Code.js +46 -0
  81. package/dist/frontend/components/code_runner/Code.js.map +1 -0
  82. package/dist/frontend/components/code_runner/RunState.d.ts +7 -0
  83. package/dist/frontend/components/code_runner/RunState.js +41 -0
  84. package/dist/frontend/components/code_runner/RunState.js.map +1 -0
  85. package/dist/frontend/components/input/BatchInput.d.ts +9 -0
  86. package/dist/frontend/components/input/BatchInput.js +53 -0
  87. package/dist/frontend/components/input/BatchInput.js.map +1 -0
  88. package/dist/frontend/components/input/InteractiveInput.d.ts +13 -0
  89. package/dist/frontend/components/input/InteractiveInput.js +73 -0
  90. package/dist/frontend/components/input/InteractiveInput.js.map +1 -0
  91. package/dist/frontend/state/Constants.d.ts +38 -0
  92. package/dist/frontend/state/Constants.js +108 -0
  93. package/dist/frontend/state/Constants.js.map +1 -0
  94. package/dist/frontend/state/Debugger.d.ts +23 -0
  95. package/dist/frontend/state/Debugger.js +84 -0
  96. package/dist/frontend/state/Debugger.js.map +1 -0
  97. package/dist/frontend/state/Examples.d.ts +11 -0
  98. package/dist/frontend/state/Examples.js +36 -0
  99. package/dist/frontend/state/Examples.js.map +1 -0
  100. package/dist/frontend/state/I18n.d.ts +16 -0
  101. package/dist/frontend/state/I18n.js +75 -0
  102. package/dist/frontend/state/I18n.js.map +1 -0
  103. package/dist/frontend/state/InputOutput.d.ts +64 -0
  104. package/dist/frontend/state/InputOutput.js +133 -0
  105. package/dist/frontend/state/InputOutput.js.map +1 -0
  106. package/dist/frontend/state/Papyros.d.ts +32 -0
  107. package/dist/frontend/state/Papyros.js +93 -0
  108. package/dist/frontend/state/Papyros.js.map +1 -0
  109. package/dist/frontend/state/Runner.d.ts +118 -0
  110. package/dist/frontend/state/Runner.js +334 -0
  111. package/dist/frontend/state/Runner.js.map +1 -0
  112. package/dist/frontend/state/Test.d.ts +11 -0
  113. package/dist/frontend/state/Test.js +59 -0
  114. package/dist/frontend/state/Test.js.map +1 -0
  115. package/dist/frontend/state/Translations.d.ts +178 -0
  116. package/dist/frontend/state/Translations.js +188 -0
  117. package/dist/frontend/state/Translations.js.map +1 -0
  118. package/dist/frontend/state/themes/blue-dark.d.ts +2 -0
  119. package/dist/frontend/state/themes/blue-dark.js +55 -0
  120. package/dist/frontend/state/themes/blue-dark.js.map +1 -0
  121. package/dist/frontend/state/themes/blue-light.d.ts +2 -0
  122. package/dist/frontend/state/themes/blue-light.js +55 -0
  123. package/dist/frontend/state/themes/blue-light.js.map +1 -0
  124. package/dist/frontend/state/themes/green-dark.d.ts +2 -0
  125. package/dist/frontend/state/themes/green-dark.js +55 -0
  126. package/dist/frontend/state/themes/green-dark.js.map +1 -0
  127. package/dist/frontend/state/themes/green-light.d.ts +2 -0
  128. package/dist/frontend/state/themes/green-light.js +55 -0
  129. package/dist/frontend/state/themes/green-light.js.map +1 -0
  130. package/dist/frontend/state/themes/red-dark.d.ts +2 -0
  131. package/dist/frontend/state/themes/red-dark.js +55 -0
  132. package/dist/frontend/state/themes/red-dark.js.map +1 -0
  133. package/dist/frontend/state/themes/red-light.d.ts +2 -0
  134. package/dist/frontend/state/themes/red-light.js +55 -0
  135. package/dist/frontend/state/themes/red-light.js.map +1 -0
  136. package/dist/util/Util.d.ts +0 -43
  137. package/dist/util/Util.js +0 -91
  138. package/dist/util/Util.js.map +1 -1
  139. package/package.json +13 -21
  140. package/dist/App.d.ts +0 -1
  141. package/dist/App.js +0 -76
  142. package/dist/App.js.map +0 -1
  143. package/dist/Backend.js.map +0 -1
  144. package/dist/BackendEvent.js.map +0 -1
  145. package/dist/BackendEventQueue.js.map +0 -1
  146. package/dist/BackendManager.js.map +0 -1
  147. package/dist/CodeRunner.d.ts +0 -188
  148. package/dist/CodeRunner.js +0 -548
  149. package/dist/CodeRunner.js.map +0 -1
  150. package/dist/Constants.d.ts +0 -31
  151. package/dist/Constants.js +0 -36
  152. package/dist/Constants.js.map +0 -1
  153. package/dist/Debugger.d.ts +0 -18
  154. package/dist/Debugger.js +0 -86
  155. package/dist/Debugger.js.map +0 -1
  156. package/dist/InputManager.d.ts +0 -38
  157. package/dist/InputManager.js +0 -101
  158. package/dist/InputManager.js.map +0 -1
  159. package/dist/InputServiceWorker.js.map +0 -1
  160. package/dist/OutputManager.d.ts +0 -90
  161. package/dist/OutputManager.js +0 -172
  162. package/dist/OutputManager.js.map +0 -1
  163. package/dist/Papyros.css +0 -657
  164. package/dist/Papyros.d.ts +0 -141
  165. package/dist/Papyros.js +0 -268
  166. package/dist/Papyros.js.map +0 -1
  167. package/dist/Translations.d.ts +0 -180
  168. package/dist/Translations.js +0 -191
  169. package/dist/Translations.js.map +0 -1
  170. package/dist/editor/BatchInputEditor.d.ts +0 -41
  171. package/dist/editor/BatchInputEditor.js +0 -80
  172. package/dist/editor/BatchInputEditor.js.map +0 -1
  173. package/dist/editor/CodeEditor.d.ts +0 -81
  174. package/dist/editor/CodeEditor.js +0 -213
  175. package/dist/editor/CodeEditor.js.map +0 -1
  176. package/dist/editor/CodeMirrorEditor.d.ts +0 -133
  177. package/dist/editor/CodeMirrorEditor.js +0 -169
  178. package/dist/editor/CodeMirrorEditor.js.map +0 -1
  179. package/dist/editor/DarkTheme.d.ts +0 -1
  180. package/dist/editor/DarkTheme.js +0 -72
  181. package/dist/editor/DarkTheme.js.map +0 -1
  182. package/dist/editor/DebugExtension.d.ts +0 -11
  183. package/dist/editor/DebugExtension.js +0 -70
  184. package/dist/editor/DebugExtension.js.map +0 -1
  185. package/dist/editor/Gutters.d.ts +0 -109
  186. package/dist/editor/Gutters.js +0 -201
  187. package/dist/editor/Gutters.js.map +0 -1
  188. package/dist/editor/LineEffectExtension.d.ts +0 -13
  189. package/dist/editor/LineEffectExtension.js +0 -48
  190. package/dist/editor/LineEffectExtension.js.map +0 -1
  191. package/dist/editor/TestCodeExtension.d.ts +0 -21
  192. package/dist/editor/TestCodeExtension.js +0 -134
  193. package/dist/editor/TestCodeExtension.js.map +0 -1
  194. package/dist/examples/Examples.d.ts +0 -6
  195. package/dist/examples/Examples.js +0 -23
  196. package/dist/examples/Examples.js.map +0 -1
  197. package/dist/examples/JavaScriptExamples.js.map +0 -1
  198. package/dist/examples/PythonExamples.js.map +0 -1
  199. package/dist/input/BatchInputHandler.d.ts +0 -55
  200. package/dist/input/BatchInputHandler.js +0 -131
  201. package/dist/input/BatchInputHandler.js.map +0 -1
  202. package/dist/input/InteractiveInputHandler.d.ts +0 -27
  203. package/dist/input/InteractiveInputHandler.js +0 -89
  204. package/dist/input/InteractiveInputHandler.js.map +0 -1
  205. package/dist/input/UserInputHandler.d.ts +0 -68
  206. package/dist/input/UserInputHandler.js +0 -39
  207. package/dist/input/UserInputHandler.js.map +0 -1
  208. package/dist/util/HTMLShapes.d.ts +0 -15
  209. package/dist/util/HTMLShapes.js +0 -25
  210. package/dist/util/HTMLShapes.js.map +0 -1
  211. package/dist/util/Rendering.d.ts +0 -120
  212. package/dist/util/Rendering.js +0 -142
  213. package/dist/util/Rendering.js.map +0 -1
  214. package/dist/workers/input/InputWorker.js.map +0 -1
  215. package/dist/workers/javascript/JavaScriptWorker.js.map +0 -1
  216. package/dist/workers/javascript/worker.js.map +0 -1
  217. package/dist/workers/python/PythonWorker.js.map +0 -1
  218. package/dist/workers/python/python_package.tar.gz.load_by_url +0 -0
  219. package/dist/workers/python/worker.js.map +0 -1
  220. /package/dist/{workers → backend/workers}/javascript/JavaScriptWorker.d.ts +0 -0
  221. /package/dist/{workers → backend/workers}/javascript/worker.d.ts +0 -0
  222. /package/dist/{workers → backend/workers}/javascript/worker.js +0 -0
  223. /package/dist/{workers → backend/workers}/python/worker.d.ts +0 -0
  224. /package/dist/{workers → backend/workers}/python/worker.js +0 -0
  225. /package/dist/{BackendEvent.d.ts → communication/BackendEvent.d.ts} +0 -0
  226. /package/dist/{BackendEvent.js → communication/BackendEvent.js} +0 -0
  227. /package/dist/{InputServiceWorker.d.ts → communication/InputServiceWorker.d.ts} +0 -0
  228. /package/dist/{workers/input → communication}/InputWorker.d.ts +0 -0
  229. /package/dist/{workers/input → communication}/InputWorker.js +0 -0
  230. /package/dist/{examples → frontend/components/app/examples}/JavaScriptExamples.d.ts +0 -0
  231. /package/dist/{examples → frontend/components/app/examples}/JavaScriptExamples.js +0 -0
  232. /package/dist/{examples → frontend/components/app/examples}/PythonExamples.d.ts +0 -0
  233. /package/dist/{examples → frontend/components/app/examples}/PythonExamples.js +0 -0
package/README.md CHANGED
@@ -12,113 +12,173 @@
12
12
  </a>
13
13
  </p>
14
14
 
15
- Papyros is a programming scratchpad in the browser. It allows running code
16
- directly in your browser, no installation required. Right now, the focus is on providing a great experience for Python, while also supporting JavaScript.
17
- By taking away obstacles between students and coding, the learning experience becomes
18
- smoother and less error-prone.
15
+ Papyros is a programming scratchpad in the browser. It allows running code directly in your browser, no installation required.
16
+ Right now, the focus is on providing a great experience for Python, while also supporting JavaScript.
17
+ By taking away obstacles between students and coding, the learning experience becomes smoother and less error-prone.
19
18
 
20
19
  Currently, Papyros provides support for the following programming languages:
21
20
  - Python, powered by [Pyodide](https://pyodide.org/en/stable/)
22
21
  - JavaScript, powered by your browser
23
22
 
24
- ## Using Papyros in your own project
23
+ ---
25
24
 
26
- You can add Papyros to your project as follows:
27
- - npm:
28
- ```shell
29
- npm install @dodona/papyros
30
- ```
31
- - yarn:
32
- ```shell
33
- yarn add @dodona/papyros
34
- ```
25
+ ## Try it Online
35
26
 
36
- Papyros currently supports two modes of operation: stand-alone and embedded.
27
+ Start coding directly in your [browser](https://papyros.dodona.be/).
37
28
 
38
- In stand-alone mode, Papyros runs as a full application in the browser.
39
- This includes extra UI elements to allow selecting a locale, a programming language, ...
29
+ ---
40
30
 
41
- In embedded mode, the layout is reduced to the minimum. Dynamic selections are not displayed,
42
- as the user knows for what purpose Papyros is being used. For example, when used in the
43
- scope of a Python exercise in Dodona, there is no need to support other programming languages.
44
- The locale should also match that of the actual application.
31
+ ## Use papyros in your project
45
32
 
46
- Using Papyros in your project is done by following a few steps. First, you create a new
47
- Papyros instance with a `PapyrosConfig` object.
48
- The following options are supported:
33
+ ### Installation
49
34
 
50
- - `standAlone`: Whether to operate in stand-alone or embedded mode as described above.
51
- - `programmingLanguage`: The [programming language](/src/ProgrammingLanguage.ts) to use in the CodeEditor and Backend.
52
- - `locale`: The locale to use, currently English and Dutch translations are provided.
53
- - `inputMode`: How the users can provide input, according to the [InputMode enum](/src/InputManager.ts)
54
- - `example`: Optional name of the selected example, only appliccable in standAlone-mode
55
- - `channelOptions`: Optional options to provide to the [sync-message](https://github.com/alexmojaki/sync-message) channel. Extra is the serviceWorkerName, which is the relative pathname to the service worker script
35
+ Install via npm or yarn:
56
36
 
57
- Furthermore, you can provide fine-grained configuration by providing `RenderOptions` to each main component in the application when rendering Papyros. You minimally need to specify the ID of the parent element.
58
- You can also specify attributes, such as `style`, `data`-attributes or `classNames` to be used.
59
- The components you can style like this are the following:
60
- - `standAloneOptions`: for the global application in standAlone mode
61
- - `codeEditorOptions`: for the CodeEditor.
62
- - `statusPanelOptions`: for the StatusPanel in the CodeEditor
63
- - `inputOptions`: for the field that handles the user input
64
- - `outputOptions`: for the panel that displays the output of the code
37
+ ```shell
38
+ npm install @dodona/papyros
39
+ # or
40
+ yarn add @dodona/papyros
41
+ ```
42
+
43
+ ### Setup input handling
65
44
 
66
- ### User input
45
+ Running interactive programs in the browser requires special handling of synchronous input.
46
+ Papyros supports two approaches (via [`sync-message`](https://github.com/alexmojaki/sync-message)):
67
47
 
68
- Important to note is that handling asynchronous input in a synchronous way is not straightforward.
69
- This requires advanced features which are not available by default in your browser. We support two options based on [sync-message](https://github.com/alexmojaki/sync-message).
48
+ #### COOP/COEP headers
49
+ Add the following HTTP headers to your server responses:
70
50
 
71
- The most efficient and practical way is using SharedArrayBuffers, which requires the presence of certain HTTP headers.
72
- The following headers must be set on resources using Papyros.
73
51
  ```yaml
74
52
  {
75
53
  "Cross-Origin-Opener-Policy": "same-origin",
76
54
  "Cross-Origin-Embedder-Policy": "require-corp"
77
55
  }
78
56
  ```
79
- If you are also embedding other components (such as iframes, videos or images) in those pages, you will also need to set the `Cross-Origin-Resource-Policy`-header to `cross-origin` to make them work correctly. If these elements come from external URLs, it will likely not be possible to keep using them. An alternative is described below.
57
+ These headers are required to enable `SharedArrayBuffer`, which is the preferred way to handle synchronous input.
58
+ They need to be set on all assets that are loaded, including scripts, images, fonts, etc.
80
59
 
81
- If you would like to use this project without enabling these HTTP headers, we provide a solution using a service worker.
82
- If your application does not use a service worker yet, you can create one based on the [service worker used in stand-alone mode](src/InputServiceWorker.ts)).
83
- If you already use a service worker, simply include our [InputWorker](src/workers/input/InputWorker.ts) in your existing service worker using imports (you can import it separately from /dist/workers/input/InputWorker). An example of how to use it can be found in our described service worker. Afterwards, inform Papyros of the location using the channelOptions described earlier.
60
+ #### Service Worker
61
+ If you cannot set these headers, you can use a service worker to handle input.
62
+ We provide a compiled and minified version of the `InputServiceWorker` in the `dist` folder.
63
+ You need to serve this file from the root of your domain (i.e. `/input-sw.js`).
64
+ You can then register the service worker in your application before launching: `papyros.serviceWorkerName = 'input-sw.js';`.
84
65
 
85
- ### Code editor
66
+ ---
86
67
 
87
- The editor used in Papyros is powered by [CodeMirror 6](https://codemirror.net/6/). It is accessible in code via an instance of Papyros and by default allows configuring many options:
88
- - the [programming language](/src/ProgrammingLanguage.ts) of the contents (for e.g. syntax higlighting)
89
- - the displayed placeholder
90
- - the indentation unit
91
- - the shown panel
92
- - the autocompletion source
93
- - the linting source
94
- - the theme used to style the editor
68
+ ## Usage
95
69
 
96
- If you need more specific functionality, this can be added in your own code by accessing the internal CodeMirror editorView.
70
+ ### Minimal setup
97
71
 
98
- ## Documentation
72
+ If you only want to use the state and runner logic without UI components:
99
73
 
100
- Visit our documentation page at <https://docs.dodona.be/papyros/>.
74
+ ```ts
75
+ import { papyros } from "@dodona/papyros";
101
76
 
102
- ## Building and developing
77
+ papyros.launch(); // heavy operation, loads workers and Pyodide
78
+ papyros.runner.code = "print(input())";
103
79
 
104
- Clone the repository using git.
105
- ```shell
106
- git@github.com:dodona-edu/papyros.git
80
+ papyros.io.subscribe(
81
+ () => (papyros.io.awaitingInput ? papyros.io.provideInput("foo") : ""),
82
+ "awaitingInput"
83
+ );
84
+
85
+ await papyros.runner.start();
86
+ console.log(papyros.runner.io.output[0].content);
107
87
  ```
108
88
 
109
- Install the required dependencies.
110
- ```shell
111
- yarn install
89
+ ### Minimal setup with components
90
+
91
+ Papyros provides four web components for visualization.
92
+ Each expects a `papyros` state instance, but defaults to the global `papyros`.
93
+
94
+ ```html
95
+ <script type="module">
96
+ import { papyros } from "@dodona/papyros";
97
+
98
+ papyros.launch();
99
+ </script>
100
+
101
+ <p-code-runner></p-code-runner>
102
+ <p-debugger></p-debugger>
103
+ <p-input></p-input>
104
+ <p-output></p-output>
112
105
  ```
113
106
 
114
- Start the local dev-server, powered by webpack.
107
+ ---
108
+
109
+ ## Theming
110
+
111
+ Papyros uses [Material Web Components](https://github.com/material-components/material-web) for buttons, inputs, sliders, etc.
112
+ All styling is driven by Material color system CSS variables (`--md-sys-color-...`).
113
+ Generate your own theme using the [Material Theme Builder](https://material-foundation.github.io/material-theme-builder/).
114
+
115
+ * Three example themes (light + dark) are provided via `papyros.constants.themes`.
116
+ * A theme picker component is available out of the box.
117
+
118
+ ---
119
+
120
+ ## Structure
121
+
122
+ The codebase organized into clear layers:
123
+
124
+ * `backend`: code execution functionality (runs in Web Workers)
125
+ * `communication`: helpers to connect frontend and backend
126
+ * `frontend`: all browser-side code
127
+ * `state`: state management (e.g. execution state, debugger, input/output)
128
+ * `components`: visualization of that state, as Lit web components
129
+
130
+ ### Components
131
+
132
+ #### `<p-code-runner>`
133
+
134
+ A [CodeMirror 6](https://codemirror.net/6/) editor to edit, run, and debug code.
135
+ Additional buttons can be added via the `.buttons` slot.
136
+
137
+ #### `<p-input>`
138
+
139
+ Lets users provide input (batch or interactive), passed to `papyros.io`.
140
+
141
+ #### `<p-output>`
142
+
143
+ Visualizes program output: stdout, stderr, and images.
144
+
145
+ #### `<p-debugger>`
146
+
147
+ Displays execution traces using [`@dodona/json-tracer`](https://github.com/dodona-edu/json-tracer).
148
+
149
+ ### State API
150
+
151
+ A `Papyros` instance contains multiple logical parts:
152
+
153
+ * `papyros.constants`: general settings, constants, and themes (can be overridden).
154
+ * `papyros.debugger`: debug frames and currently active frame.
155
+ * `papyros.examples`: available code examples.
156
+ * `papyros.i18n`: translations (extend or override as needed).
157
+ * `papyros.io`: input/output handling. Subscribe to `awaitingInput` to supply input when needed.
158
+ * `papyros.runner`: code, execution state, programming language. Run code with `papyros.runner.start()`.
159
+ * `papyros.test`: test code (appended to the code document).
160
+
161
+ ---
162
+
163
+ ## Development
164
+
115
165
  ```shell
166
+ # Clone the repository:
167
+ git clone git@github.com:dodona-edu/papyros.git
168
+ cd papyros
169
+ # Install dependencies:
170
+ yarn install
171
+ # Build the python packages:
172
+ yarn setup
173
+ # Start a local server with live reload:
116
174
  yarn start
117
175
  ```
118
176
 
119
- You can now develop with live-reloading.
120
- You can view the results in your browser by visting http://localhost:8080.
121
-
122
- ## Try it online
177
+ ## Publishing
123
178
 
124
- Start coding immediately in your [browser](https://papyros.dodona.be/).
179
+ ```shell
180
+ # Build as library
181
+ yarn build:lib
182
+ # Publish to npm
183
+ yarn publish
184
+ ```
package/dist/Library.d.ts CHANGED
@@ -1,12 +1,11 @@
1
- import { BackendEvent } from "./BackendEvent";
2
- import { CodeEditor } from "./editor/CodeEditor";
3
- import { InputManager, InputMode } from "./InputManager";
4
- import { FriendlyError, OutputManager } from "./OutputManager";
5
- import { Papyros, PapyrosConfig, PapyrosRenderOptions } from "./Papyros";
6
- import { CodeRunner, RunState } from "./CodeRunner";
7
- import { BackendManager } from "./BackendManager";
1
+ import "./frontend/components/Input";
2
+ import "./frontend/components/Output";
3
+ import "./frontend/components/CodeRunner";
4
+ import "./frontend/components/Debugger";
5
+ import { Papyros, papyros } from "./frontend/state/Papyros";
6
+ import { InputMode } from "./frontend/state/InputOutput";
7
+ import { RunMode } from "./backend/Backend";
8
8
  import { ProgrammingLanguage } from "./ProgrammingLanguage";
9
- import { WorkerDiagnostic } from "./Backend";
10
- import { ButtonOptions, RenderOptions } from "./util/Rendering";
11
- export type { BackendEvent, FriendlyError, WorkerDiagnostic, PapyrosConfig, PapyrosRenderOptions, RenderOptions, ButtonOptions };
12
- export { Papyros, ProgrammingLanguage, BackendManager, CodeEditor, CodeRunner, RunState, InputManager, InputMode, OutputManager };
9
+ import { OutputType, FriendlyError } from "./frontend/state/InputOutput";
10
+ export { Papyros, InputMode, RunMode, ProgrammingLanguage, OutputType, papyros };
11
+ export type { FriendlyError };
package/dist/Library.js CHANGED
@@ -1,9 +1,11 @@
1
- import { CodeEditor } from "./editor/CodeEditor";
2
- import { InputManager, InputMode } from "./InputManager";
3
- import { OutputManager } from "./OutputManager";
4
- import { Papyros } from "./Papyros";
5
- import { CodeRunner, RunState } from "./CodeRunner";
6
- import { BackendManager } from "./BackendManager";
1
+ import "./frontend/components/Input";
2
+ import "./frontend/components/Output";
3
+ import "./frontend/components/CodeRunner";
4
+ import "./frontend/components/Debugger";
5
+ import { Papyros, papyros } from "./frontend/state/Papyros";
6
+ import { InputMode } from "./frontend/state/InputOutput";
7
+ import { RunMode } from "./backend/Backend";
7
8
  import { ProgrammingLanguage } from "./ProgrammingLanguage";
8
- export { Papyros, ProgrammingLanguage, BackendManager, CodeEditor, CodeRunner, RunState, InputManager, InputMode, OutputManager };
9
+ import { OutputType } from "./frontend/state/InputOutput";
10
+ export { Papyros, InputMode, RunMode, ProgrammingLanguage, OutputType, papyros };
9
11
  //# sourceMappingURL=Library.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Library.js","sourceRoot":"","sources":["../src/Library.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAiB,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAuC,MAAM,WAAW,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAU5D,OAAO,EACH,OAAO,EACP,mBAAmB,EACnB,cAAc,EACd,UAAU,EACV,UAAU,EACV,QAAQ,EACR,YAAY,EACZ,SAAS,EACT,aAAa,EAChB,CAAC"}
1
+ {"version":3,"file":"Library.js","sourceRoot":"","sources":["../src/Library.ts"],"names":[],"mappings":"AAAA,OAAO,6BAA6B,CAAC;AACrC,OAAO,8BAA8B,CAAC;AACtC,OAAO,kCAAkC,CAAC;AAC1C,OAAO,gCAAgC,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAiB,MAAM,8BAA8B,CAAC;AAEzE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC"}
@@ -1,6 +1,6 @@
1
- import { BackendEvent } from "./BackendEvent";
1
+ import { BackendEvent } from "../communication/BackendEvent";
2
2
  import { SyncExtras } from "comsync";
3
- import { BackendEventQueue } from "./BackendEventQueue";
3
+ import { BackendEventQueue } from "../communication/BackendEventQueue";
4
4
  export interface WorkerDiagnostic {
5
5
  /**
6
6
  * 1-based index of the starting line containing the issue
@@ -60,10 +60,9 @@ export declare abstract class Backend<Extras extends SyncExtras = SyncExtras> {
60
60
  /**
61
61
  * Initialize the backend by doing all setup-related work
62
62
  * @param {function(BackendEvent):void} onEvent Callback for when events occur
63
- * @param {function():void} onOverflow Callback for when overflow occurs
64
63
  * @return {Promise<void>} Promise of launching
65
64
  */
66
- launch(onEvent: (e: BackendEvent) => void, onOverflow: () => void): Promise<void>;
65
+ launch(onEvent: (e: BackendEvent) => void): Promise<void>;
67
66
  /**
68
67
  * Determine whether the modes supported by this Backend are active
69
68
  * @param {string} code The current code in the editor
@@ -83,14 +82,6 @@ export declare abstract class Backend<Extras extends SyncExtras = SyncExtras> {
83
82
  * @param {string} code The code to lint
84
83
  */
85
84
  abstract lintCode(code: string): Promise<Array<WorkerDiagnostic>>;
86
- /**
87
- * @return {boolean} Whether too many output events were generated
88
- */
89
- hasOverflow(): boolean;
90
- /**
91
- * @return {Array<BackendEvent>} The events that happened after overflow
92
- */
93
- getOverflow(): Array<BackendEvent>;
94
85
  /**
95
86
  * Provide files to be used by the backend
96
87
  * @param {Record<string, string>} inlineFiles Map of file names to their contents
@@ -7,9 +7,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { BackendEventType } from "./BackendEvent";
10
+ import { BackendEventType } from "../communication/BackendEvent";
11
11
  import { syncExpose } from "comsync";
12
- import { BackendEventQueue } from "./BackendEventQueue";
12
+ import { BackendEventQueue } from "../communication/BackendEventQueue";
13
13
  export var RunMode;
14
14
  (function (RunMode) {
15
15
  RunMode["Run"] = "run";
@@ -39,10 +39,9 @@ export class Backend {
39
39
  /**
40
40
  * Initialize the backend by doing all setup-related work
41
41
  * @param {function(BackendEvent):void} onEvent Callback for when events occur
42
- * @param {function():void} onOverflow Callback for when overflow occurs
43
42
  * @return {Promise<void>} Promise of launching
44
43
  */
45
- launch(onEvent, onOverflow) {
44
+ launch(onEvent) {
46
45
  return __awaiter(this, void 0, void 0, function* () {
47
46
  this.onEvent = (e) => {
48
47
  onEvent(e);
@@ -53,7 +52,7 @@ export class Backend {
53
52
  return this.extras.readMessage();
54
53
  }
55
54
  };
56
- this.queue = new BackendEventQueue(this.onEvent.bind(this), onOverflow);
55
+ this.queue = new BackendEventQueue(this.onEvent.bind(this));
57
56
  return Promise.resolve();
58
57
  });
59
58
  }
@@ -66,18 +65,6 @@ export class Backend {
66
65
  runModes(code) {
67
66
  return [];
68
67
  }
69
- /**
70
- * @return {boolean} Whether too many output events were generated
71
- */
72
- hasOverflow() {
73
- return this.queue.hasOverflow();
74
- }
75
- /**
76
- * @return {Array<BackendEvent>} The events that happened after overflow
77
- */
78
- getOverflow() {
79
- return this.queue.getOverflow();
80
- }
81
68
  /**
82
69
  * Provide files to be used by the backend
83
70
  * @param {Record<string, string>} inlineFiles Map of file names to their contents
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Backend.js","sourceRoot":"","sources":["../../src/backend/Backend.ts"],"names":[],"mappings":";;;;;;;;;AAAA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AAI,CAAC,CAAC,CAAC;YAC5D,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;QAC7B,CAAC;KAAA;IAED;;;;OAIG;IACH,6DAA6D;IACtD,QAAQ,CAAC,IAAY;QACxB,OAAO,EAAE,CAAC;IACd,CAAC;IAiBD;;;;;OAKG;IACH,6DAA6D;IACtD,YAAY,CAAC,WAAmC,EAAE,SAAiC;QACtF,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC;CACJ"}
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { Backend } from "../../Backend";
11
- import { BackendEventType } from "../../BackendEvent";
11
+ import { BackendEventType } from "../../../communication/BackendEvent";
12
12
  /**
13
13
  * Implementation of a JavaScript backend for Papyros
14
14
  * by using eval and overriding some builtins
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JavaScriptWorker.js","sourceRoot":"","sources":["../../../../src/backend/workers/javascript/JavaScriptWorker.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAoB,MAAM,eAAe,CAAC;AAE1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAGvE;;;GAGG;AACH,MAAM,OAAO,gBAAiB,SAAQ,OAAmB;IACrD;;;;OAIG;IACK,MAAM,CAAC,SAAS,CAAC,GAAG,IAAW;QACnC,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;YAC1B,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;gBACnB,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;YAC7B,CAAC;iBAAM,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE,CAAC;gBACjC,OAAO,CAAC,CAAC;YACb,CAAC;iBAAM,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;gBAC/B,OA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nC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,MAAM,MAAM,GAAG,IAAI,gBAAgB,EAAE,CAAC;AACtC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { Backend, RunMode, WorkerDiagnostic } from "../../Backend";
2
- import { BackendEvent } from "../../BackendEvent";
2
+ import { BackendEvent } from "../../../communication/BackendEvent";
3
3
  import { PyodideExtras } from "pyodide-worker-runner";
4
4
  /**
5
5
  * Implementation of a Python backend for Papyros
@@ -19,7 +19,7 @@ export declare class PythonWorker extends Backend<PyodideExtras> {
19
19
  */
20
20
  protected syncExpose(): any;
21
21
  private static getPyodide;
22
- launch(onEvent: (e: BackendEvent) => void, onOverflow: () => void): Promise<void>;
22
+ launch(onEvent: (e: BackendEvent) => void): Promise<void>;
23
23
  /**
24
24
  * Helper method to install imports and prevent race conditions with double downloading
25
25
  * @param {string} code The code containing import statements
@@ -35,12 +35,12 @@ export class PythonWorker extends Backend {
35
35
  return yield loadPyodideAndPackage({ url: pythonPackageUrl, format: ".tgz" });
36
36
  });
37
37
  }
38
- launch(onEvent, onOverflow) {
38
+ launch(onEvent) {
39
39
  const _super = Object.create(null, {
40
40
  launch: { get: () => super.launch }
41
41
  });
42
42
  return __awaiter(this, void 0, void 0, function* () {
43
- yield _super.launch.call(this, onEvent, onOverflow);
43
+ yield _super.launch.call(this, onEvent);
44
44
  this.pyodide = yield PythonWorker.getPyodide();
45
45
  // Python calls our function with a PyProxy dict or a Js Map,
46
46
  // These must be converted to a PapyrosEvent (JS Object) to allow message passing
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PythonWorker.js","sourceRoot":"","sources":["../../../../src/backend/workers/python/PythonWorker.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAoB,MAAM,eAAe,CAAC;AAInE,OAAO,EAAE,aAAa,EAAiB,qBAAqB,EAAE,MAAM,uB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AAc,CAAC,IAAI,CAAC,CAAC;YAChC,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,UAAU,CAAC;gBAC3C,WAAW,EAAE,IAAI;gBACjB,IAAI,EAAE,IAAI;aACb,CAAC,CAAC;QACP,CAAC;KAAA;IAEqB,QAAQ,CAAC,IAAY;;YACvC,MAAM,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;YAChC,OAAO,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACzD,CAAC;KAAA;IAEqB,YAAY,CAAC,WAAmC,EAAE,SAAiC;;YACrG,MAAM,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,UAAU,CAAC;gBACxC,YAAY,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC;gBACzC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC;aACxC,CAAC,CAAC;QACP,CAAC;KAAA;CACJ"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker.js","sourceRoot":"","sources":["../../../../src/backend/workers/python/worker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,MAAM,MAAM,GAAG,IAAI,YAAY,EAAE,CAAC;AAClC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BackendEvent.js","sourceRoot":"","sources":["../../src/communication/BackendEvent.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAN,IAAY,gBAYX;AAZD,WAAY,gBAAgB;IACxB,mCAAe,CAAA;IACf,+BAAW,CAAA;IACX,mCAAe,CAAA;IACf,qCAAiB,CAAA;IACjB,mCAAe,CAAA;IACf,mCAAe,CAAA;IACf,2CAAuB,CAAA;IACvB,uCAAmB,CAAA;IACnB,mCAAe,CAAA;IACf,gDAA4B,CAAA;IAC5B,iCAAa,CAAA;AACjB,CAAC,EAZW,gBAAgB,KAAhB,gBAAgB,QAY3B"}
@@ -9,10 +9,6 @@ export declare class BackendEventQueue {
9
9
  * Function to process events in the queue
10
10
  */
11
11
  private callback;
12
- /**
13
- * The maximal amount of output events to send before overflowing
14
- */
15
- private limit;
16
12
  /**
17
13
  * The time in milliseconds before sending events through
18
14
  */
@@ -21,37 +17,19 @@ export declare class BackendEventQueue {
21
17
  * Queue storing the BackendEvents before flushing
22
18
  */
23
19
  private queue;
24
- /**
25
- * Queue storing Output-events after overflowing
26
- */
27
- private overflow;
28
- /**
29
- * Callback for when overflow occurs
30
- */
31
- private onOverflow;
32
- /**
33
- * Keep track whether the queue reached its limit this run
34
- */
35
- private overflown;
36
20
  /**
37
21
  * Time in milliseconds when the last flush occurred
38
22
  */
39
23
  private lastFlushTime;
40
- /**
41
- * Amount of BackendEvents sent through this run
42
- */
43
- private sendCount;
44
24
  /**
45
25
  * Decoder to convert data to strings
46
26
  */
47
27
  private decoder;
48
28
  /**
49
29
  * @param {function(BackendEvent):void} callback Function to process events in the queue
50
- * @param {function():void} onOverflow Callback for when overflow occurs
51
- * @param {number} limit The maximal amount of output lines to send before overflowing
52
30
  * @param {number} flushTime The time in milliseconds before sending events through
53
31
  */
54
- constructor(callback: (e: BackendEvent) => void, onOverflow: () => void, limit?: number, flushTime?: number);
32
+ constructor(callback: (e: BackendEvent) => void, flushTime?: number);
55
33
  /**
56
34
  * Add an element to the queue
57
35
  * @param {BackendEventType} type The type of the event
@@ -70,23 +48,10 @@ export declare class BackendEventQueue {
70
48
  * Reset the queue contents for a new run
71
49
  */
72
50
  reset(): void;
73
- /**
74
- * @param {BackendEvent} e The event put in the queue
75
- * @return {number} The amount of lines of data in the event
76
- */
77
- private static lines;
78
51
  /**
79
52
  * Flush the queue contents using the callback
80
53
  */
81
54
  flush(): void;
82
- /**
83
- * @return {boolean} Whether too many output events were generated
84
- */
85
- hasOverflow(): boolean;
86
- /**
87
- * @return {Array<BackendEvent>} The events that happened after overflow
88
- */
89
- getOverflow(): Array<BackendEvent>;
90
55
  /**
91
56
  * @param {Function} callback The event-consuming callback
92
57
  */
@@ -1,4 +1,3 @@
1
- import { BackendEventType } from "./BackendEvent";
2
1
  /**
3
2
  * Queue to limit the amount of messages sent between threads
4
3
  * This prevents communication issues which arise either in Comlink
@@ -7,20 +6,13 @@ import { BackendEventType } from "./BackendEvent";
7
6
  export class BackendEventQueue {
8
7
  /**
9
8
  * @param {function(BackendEvent):void} callback Function to process events in the queue
10
- * @param {function():void} onOverflow Callback for when overflow occurs
11
- * @param {number} limit The maximal amount of output lines to send before overflowing
12
9
  * @param {number} flushTime The time in milliseconds before sending events through
13
10
  */
14
- constructor(callback, onOverflow, limit = 1000, flushTime = 100) {
11
+ constructor(callback, flushTime = 100) {
15
12
  this.callback = callback;
16
- this.limit = limit;
17
13
  this.flushTime = flushTime;
18
14
  this.queue = [];
19
- this.overflow = [];
20
- this.onOverflow = onOverflow;
21
- this.overflown = false;
22
15
  this.lastFlushTime = new Date().getTime();
23
- this.sendCount = 0;
24
16
  this.decoder = new TextDecoder();
25
17
  }
26
18
  /**
@@ -81,53 +73,18 @@ export class BackendEventQueue {
81
73
  */
82
74
  reset() {
83
75
  this.queue = [];
84
- this.overflow = [];
85
- this.overflown = false;
86
76
  this.lastFlushTime = new Date().getTime();
87
- this.sendCount = 0;
88
- }
89
- /**
90
- * @param {BackendEvent} e The event put in the queue
91
- * @return {number} The amount of lines of data in the event
92
- */
93
- static lines(e) {
94
- return (e.data.match(/\n/g) || []).length + 1;
95
77
  }
96
78
  /**
97
79
  * Flush the queue contents using the callback
98
80
  */
99
81
  flush() {
100
82
  this.queue.forEach(e => {
101
- if (e.type === BackendEventType.Output) {
102
- this.overflow.push(e);
103
- if (this.sendCount < this.limit) {
104
- this.sendCount += BackendEventQueue.lines(e);
105
- this.callback(e);
106
- }
107
- else if (!this.overflown) {
108
- this.overflown = true;
109
- this.onOverflow();
110
- }
111
- }
112
- else {
113
- this.callback(e);
114
- }
83
+ this.callback(e);
115
84
  });
116
85
  this.queue = [];
117
86
  this.lastFlushTime = new Date().getTime();
118
87
  }
119
- /**
120
- * @return {boolean} Whether too many output events were generated
121
- */
122
- hasOverflow() {
123
- return this.overflown;
124
- }
125
- /**
126
- * @return {Array<BackendEvent>} The events that happened after overflow
127
- */
128
- getOverflow() {
129
- return this.overflow;
130
- }
131
88
  /**
132
89
  * @param {Function} callback The event-consuming callback
133
90
  */
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BackendEventQueue.js","sourceRoot":"","sources":["../../src/communication/BackendEventQueue.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,OAAO,iBAAiB;IAsB1B;;;OAGG;IACH,YAAY,QAAmC,EAAE,SAAS,GAAG,GAAG;QAC5D,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAE3B,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC,aAAa,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;QAC1C,IAAI,CAAC,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;IACrC,CAAC;IAED;;;;;;;;OAQG;IACI,GAAG,CAAC,IAAsB,EAAE,IAAoC,EAAE,KAAmB;QACxF,IAAI,UAAU,GAAG,EAAE,CAAC;QACpB,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC3B,UAAU,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;QACjC,CAAC;aAAM,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YAClC,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC3C,CAAC;aAAM,CAAC;YACJ,UAAU,GAAG,IAAI,CAAC;QACtB,CAAC;QACD,IAAI,SAAS,GAA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AAI,CAAC,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC;IACnE,CAAC;IAED;;OAEG;IACI,KAAK;QACR,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC,aAAa,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;IAC9C,CAAC;IAED;;OAEG;IACI,KAAK;QACR,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;YACnB,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QACrB,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC,aAAa,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;IAC9C,CAAC;IAED;;OAEG;IACI,WAAW,CAAC,QAAmC;QAClD,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;CACJ"}
@@ -1,5 +1,5 @@
1
- import { Backend } from "./Backend";
2
- import { ProgrammingLanguage } from "./ProgrammingLanguage";
1
+ import { Backend } from "../backend/Backend";
2
+ import { ProgrammingLanguage } from "../ProgrammingLanguage";
3
3
  import { BackendEvent, BackendEventType } from "./BackendEvent";
4
4
  import { Channel } from "sync-message";
5
5
  import { SyncClient } from "comsync";