@dodona/papyros 0.1.7-rc → 0.1.8-tar

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 (63) hide show
  1. package/README.md +37 -12
  2. package/dist/{Main.d.ts → App.d.ts} +0 -0
  3. package/dist/Backend.d.ts +73 -14
  4. package/dist/BackendEvent.d.ts +33 -0
  5. package/dist/BackendManager.d.ts +47 -3
  6. package/dist/CodeEditor.d.ts +107 -2
  7. package/dist/CodeRunner.d.ts +102 -0
  8. package/dist/Constants.d.ts +17 -12
  9. package/dist/InputManager.d.ts +32 -0
  10. package/dist/InputServiceWorker.d.ts +1 -0
  11. package/dist/Library.d.ts +10 -0
  12. package/dist/OutputManager.d.ts +75 -0
  13. package/dist/Papyros.d.ts +131 -47
  14. package/dist/ProgrammingLanguage.d.ts +3 -2
  15. package/dist/RunListener.d.ts +13 -0
  16. package/dist/examples/Examples.d.ts +6 -0
  17. package/dist/examples/JavaScriptExamples.d.ts +5 -0
  18. package/dist/examples/PythonExamples.d.ts +12 -0
  19. package/dist/index.js +2 -0
  20. package/dist/index.js.LICENSE.txt +7 -0
  21. package/dist/input/BatchInputHandler.d.ts +31 -0
  22. package/dist/input/InteractiveInputHandler.d.ts +20 -0
  23. package/dist/input/UserInputHandler.d.ts +61 -0
  24. package/dist/inputServiceWorker.js +1 -0
  25. package/dist/util/HTMLShapes.d.ts +15 -0
  26. package/dist/util/Logging.d.ts +9 -0
  27. package/dist/util/Util.d.ts +107 -0
  28. package/dist/workers/input/InputWorker.d.ts +22 -0
  29. package/dist/workers/javascript/JavaScriptWorker.worker.d.ts +2 -1
  30. package/dist/workers/python/Pyodide.d.ts +32 -0
  31. package/dist/workers/python/PythonWorker.worker.d.ts +4 -1
  32. package/dist/workers/python/package.tar +0 -0
  33. package/package.json +36 -31
  34. package/dist/Backend.js +0 -133
  35. package/dist/Backend.js.map +0 -1
  36. package/dist/BackendManager.js +0 -39
  37. package/dist/BackendManager.js.map +0 -1
  38. package/dist/CodeEditor.js +0 -146
  39. package/dist/CodeEditor.js.map +0 -1
  40. package/dist/Constants.js +0 -16
  41. package/dist/Constants.js.map +0 -1
  42. package/dist/Main.js +0 -42
  43. package/dist/Main.js.map +0 -1
  44. package/dist/Papyros.css +0 -9
  45. package/dist/Papyros.js +0 -390
  46. package/dist/Papyros.js.map +0 -1
  47. package/dist/PapyrosEvent.d.ts +0 -5
  48. package/dist/PapyrosEvent.js +0 -2
  49. package/dist/PapyrosEvent.js.map +0 -1
  50. package/dist/ProgrammingLanguage.js +0 -23
  51. package/dist/ProgrammingLanguage.js.map +0 -1
  52. package/dist/Translations.d.ts +0 -40
  53. package/dist/Translations.js +0 -39
  54. package/dist/Translations.js.map +0 -1
  55. package/dist/util/Logging.js +0 -48
  56. package/dist/util/Logging.js.map +0 -1
  57. package/dist/workers/javascript/JavaScriptWorker.worker.js +0 -91
  58. package/dist/workers/javascript/JavaScriptWorker.worker.js.map +0 -1
  59. package/dist/workers/python/PythonWorker.worker.js +0 -161
  60. package/dist/workers/python/PythonWorker.worker.js.map +0 -1
  61. package/dist/workers/python/init.py.d.ts +0 -1
  62. package/dist/workers/python/init.py.js +0 -2
  63. package/dist/workers/python/init.py.js.map +0 -1
package/README.md CHANGED
@@ -12,29 +12,22 @@
12
12
  </a>
13
13
  </p>
14
14
 
15
- Papyros is a programming scratchpad in the browser. It allows running arbitrary
16
- in various programming languages directly in your browser, no installation required.
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 in on providing a great experience for Python, while also supporting JavaScript.
17
17
  By taking away obstacles between students and coding, the learning experience becomes
18
- smoother and less error-prone.
19
-
20
- Papyros aims to be:
21
-
22
- - **Easy to use** by having minimal installation instructions and an intuitive user interface
23
- - **Flexible** to support many programming languages
18
+ smoother and less error-prone.
24
19
 
25
20
  Currently, Papyros provides support for the following programming languages:
26
21
  - Python, powered by [Pyodide](https://pyodide.org/en/stable/)
27
22
  - JavaScript, powered by your browser
28
23
 
29
- ## Installation
24
+ ## Using Papyros in your own project
30
25
 
31
26
  You can install Papyros on your system using npm:
32
27
  ```shell
33
28
  npm install -g @dodona/papyros
34
29
  ```
35
30
 
36
- ## Usage
37
-
38
31
  Papyros currently supports two modes of operation: stand-alone and embedded.
39
32
 
40
33
  In stand-alone mode, Papyros runs as a full application in the browser.
@@ -51,6 +44,38 @@ The following options are supported:
51
44
  - standAlone: Whether to operate in stand-alone or embedded mode as described above.
52
45
  - locale: The locale to use, currently English and Dutch translations are provided.
53
46
  - programmingLanguage: The language to use in the CodeEditor and Backend
47
+ - inputMode: How the users can provide input, according to the [InputMode enum](/src/InputManager.ts)
48
+
49
+ Furthermore, you can provide fine-grained configuration in embedded mode by providing RenderOptions
50
+ to each main component in the application. You minimally need to specify the ID of the parent element.
51
+ You can also specify attributes, such as style or data, or classNames to be used.
52
+ The main components are the following:
53
+ - code -> the CodeEditor
54
+ - panel -> the StatusPanel in the CodeEditor
55
+ - input -> The field for the user input
56
+ - output -> The panel for output of the code
57
+
58
+ ### User input
59
+
60
+ Important to note is that handling asynchronous input in a synchronous way is not straightforward.
61
+ This requires advanced features which are not available by default in your browser. We support two options
62
+
63
+ The most efficient and practical way is using SharedArrayBuffers, which requires the presence of certain HTTP headers.
64
+ The following headers must be set on resources using Papyros.
65
+ ```json
66
+ 'Cross-Origin-Opener-Policy': 'same-origin',
67
+ 'Cross-Origin-Embedder-Policy': 'require-corp'
68
+ ```
69
+ If you are also embedding other components (such as iframes) in those pages, you will also need to set
70
+ 'Cross-Origin-Resource-Policy' to 'cross-origin' to make them work correctly. In order to limit the effect of this
71
+ change, it is advised to restrict access using the 'Access-Control-Allow-Origin'-header to prevent abuse of including code.
72
+
73
+ If you would like to use this project without enabling these HTTP headers, we provide a solution using a service worker.
74
+ If your application does not use a service worker yet, a default service worker is pre-built and included in the package.
75
+ Simply copy the file located [here](dist/inputServiceWorker.js) to a location of choice in your application where it can be served.
76
+ Then, before launching your instance of Papyros, make a call to configureInput with the location of the folder and the name of the file.
77
+
78
+ If you already use a service worker, simply include our functionality in your existing worker using imports. An example can be found [here](src/InputServiceWorker.ts). Afterwards, inform Papyros of this using configureInput as above.
54
79
 
55
80
  ## Documentation
56
81
 
@@ -78,4 +103,4 @@ You can view the results in your browser by visting http://localhost:8080.
78
103
 
79
104
  ## Try it online
80
105
 
81
- Start coding immediately in your [browser](https://docs.dodona.be/papyros/).
106
+ Start coding immediately in your [browser](https://papyros.dodona.be/).
File without changes
package/dist/Backend.d.ts CHANGED
@@ -1,22 +1,81 @@
1
- import { PapyrosEvent } from "./PapyrosEvent";
1
+ import { CompletionContext, CompletionResult } from "@codemirror/autocomplete";
2
+ import { BackendEvent } from "./BackendEvent";
3
+ import { SyncExtras } from "comsync";
4
+ /**
5
+ * Interface to represent the CodeMirror CompletionContext in a worker
6
+ */
7
+ export interface WorkerAutocompleteContext {
8
+ /**
9
+ * Whether the autocompletion was explicitly requested (using keybindings)
10
+ */
11
+ explicit: boolean;
12
+ /**
13
+ * The absolute position in the CodeMirror document
14
+ */
15
+ pos: number;
16
+ /**
17
+ * The line number of the cursor while completing (1-based)
18
+ */
19
+ line: number;
20
+ /**
21
+ * The column number of the cursor while completing (1-based)
22
+ */
23
+ column: number;
24
+ /**
25
+ * The full text to autocomplete for
26
+ */
27
+ text: string;
28
+ /**
29
+ * The match before the cursor (determined by a regex)
30
+ */
31
+ before: {
32
+ from: number;
33
+ to: number;
34
+ text: string;
35
+ } | null;
36
+ }
2
37
  export declare abstract class Backend {
3
- onEvent: (e: PapyrosEvent) => any;
4
- runId: number;
5
- constructor();
6
- /**
7
- * Initialize the backend, setting up any globals required
8
- * @param {function(PapyrosEvent):void} onEvent Callback for when events occur
9
- * @param {Uint8Array} inputTextArray Optional shared buffer for input
10
- * @param {Int32Array} inputMetaData Optional shared buffer for metadata about input
38
+ protected syncExtras: SyncExtras;
39
+ protected onEvent: (e: BackendEvent) => any;
40
+ /**
41
+ * Constructor is limited as it is meant to be used as a WebWorker
42
+ * These are then exposed via Comlink. Proper initialization occurs
43
+ * in the launch method when the worker is started
44
+ * @param {Array<string>} syncMethods The methods to expose
45
+ */
46
+ constructor(syncMethods?: string[]);
47
+ /**
48
+ * @return {any} The function to expose methods for Comsync to allow interrupting
49
+ */
50
+ protected syncExpose(): any;
51
+ /**
52
+ * Expose all the methods that should support being interrupted
53
+ * @param {Array<string>} syncMethods The names of the methods to expose
54
+ */
55
+ protected exposeMethods(syncMethods: Array<string>): void;
56
+ /**
57
+ * Initialize the backend by doing all setup-related work
58
+ * @param {function(BackendEvent):void} onEvent Callback for when events occur
11
59
  * @return {Promise<void>} Promise of launching
12
60
  */
13
- launch(onEvent: (e: PapyrosEvent) => void, inputTextArray?: Uint8Array, inputMetaData?: Int32Array): Promise<void>;
14
- abstract _runCodeInternal(code: string): Promise<any>;
61
+ launch(onEvent: (e: BackendEvent) => void): Promise<void>;
15
62
  /**
16
- * Validate and run arbitrary code
63
+ * Executes the given code
17
64
  * @param {string} code The code to run
18
- * @param {string} runId The uuid for this execution
19
65
  * @return {Promise<void>} Promise of execution
20
66
  */
21
- runCode(code: string, runId: number): Promise<void>;
67
+ abstract runCode(extras: SyncExtras, code: string): Promise<void>;
68
+ /**
69
+ * Converts the context to a cloneable object containing useful properties
70
+ * to generate autocompletion suggestions with
71
+ * @param {CompletionContext} context Current context to autocomplete for
72
+ * @param {RegExp} expr Expression to match the previous token with
73
+ * @return {WorkerAutocompleteContext} Completion context that can be passed as a message
74
+ */
75
+ static convertCompletionContext(context: CompletionContext, expr?: RegExp): WorkerAutocompleteContext;
76
+ /**
77
+ * Generate autocompletion suggestions for the given context
78
+ * @param {WorkerAutocompleteContext} context Context to autcomplete in
79
+ */
80
+ abstract autocomplete(context: WorkerAutocompleteContext): Promise<CompletionResult | null>;
22
81
  }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Enum representing all possible types for supported events
3
+ */
4
+ export declare enum BackendEventType {
5
+ Start = "start",
6
+ End = "end",
7
+ Input = "input",
8
+ Output = "output",
9
+ Sleep = "sleep",
10
+ Error = "error",
11
+ Interrupt = "interrupt"
12
+ }
13
+ /**
14
+ * All possible types for ease of iteration
15
+ */
16
+ export declare const BACKEND_EVENT_TYPES: BackendEventType[];
17
+ /**
18
+ * Interface for events used for communication between threads
19
+ */
20
+ export interface BackendEvent {
21
+ /**
22
+ * The type of action generating this event
23
+ */
24
+ type: BackendEventType;
25
+ /**
26
+ * The actual data stored in this event
27
+ */
28
+ data: string;
29
+ /**
30
+ * The format used for the data to help with parsing
31
+ */
32
+ contentType: string;
33
+ }
@@ -1,5 +1,49 @@
1
- import { Remote } from "comlink";
2
1
  import { Backend } from "./Backend";
3
2
  import { ProgrammingLanguage } from "./ProgrammingLanguage";
4
- export declare function getBackend(language: ProgrammingLanguage): Remote<Backend>;
5
- export declare function stopBackend(backend: Remote<Backend>): void;
3
+ import { BackendEvent, BackendEventType } from "./BackendEvent";
4
+ import { Channel } from "sync-message";
5
+ import { SyncClient } from "comsync";
6
+ /**
7
+ * Callback type definition for subscribers
8
+ * @param {BackendEvent} e The published event
9
+ */
10
+ declare type BackendEventListener = (e: BackendEvent) => void;
11
+ declare class Cacheable<T> {
12
+ private cached;
13
+ private createFn;
14
+ constructor(createFn: () => T);
15
+ get(): T;
16
+ }
17
+ /**
18
+ * Abstract class to implement the singleton pattern
19
+ * Static methods group functionality
20
+ */
21
+ export declare abstract class BackendManager {
22
+ static createWorkerMap: Map<ProgrammingLanguage, Cacheable<SyncClient<Backend>>>;
23
+ static channel: Channel;
24
+ /**
25
+ * Map an event type to interested subscribers
26
+ * Uses an Array to maintain order of subscription
27
+ */
28
+ static subscriberMap: Map<BackendEventType, Array<BackendEventListener>>;
29
+ private static buildSyncClientMap;
30
+ /**
31
+ * Start a backend for the given language, while storing the worker
32
+ * @param {ProgrammingLanguage} language The programming language supported by the backend
33
+ * @return {Remote<Backend>} A Comlink proxy for the Backend
34
+ */
35
+ static startBackend(language: ProgrammingLanguage): SyncClient<Backend>;
36
+ /**
37
+ * Register a callback for when an event of a certain type is published
38
+ * @param {BackendEventType} type The type of event to subscribe to
39
+ * @param {BackendEventListener} subscriber Callback for when an event
40
+ * of the given type is published
41
+ */
42
+ static subscribe(type: BackendEventType, subscriber: BackendEventListener): void;
43
+ /**
44
+ * Publish an event, notifying all listeners for its type
45
+ * @param {BackendEventType} e The event to publish
46
+ */
47
+ static publish(e: BackendEvent): void;
48
+ }
49
+ export {};
@@ -1,12 +1,117 @@
1
- import { Compartment } from "@codemirror/state";
1
+ import { LanguageSupport } from "@codemirror/language";
2
+ import { Compartment, Extension } from "@codemirror/state";
2
3
  import { ProgrammingLanguage } from "./ProgrammingLanguage";
3
4
  import { EditorView } from "@codemirror/view";
5
+ import { CompletionSource } from "@codemirror/autocomplete";
6
+ import { RenderOptions } from "./util/Util";
7
+ /**
8
+ * Component that provides useful features to users writing code
9
+ */
4
10
  export declare class CodeEditor {
11
+ /**
12
+ * Reference to the user interface of the editor
13
+ */
5
14
  editorView: EditorView;
15
+ /**
16
+ * Compartment to change language at runtime
17
+ */
6
18
  languageCompartment: Compartment;
19
+ /**
20
+ * Compartment to configure indentation level at runtime
21
+ */
7
22
  indentCompartment: Compartment;
8
- constructor(element: HTMLElement, language: ProgrammingLanguage, initialCode?: string, indentLength?: number);
23
+ /**
24
+ * Compartment to configure the placeholder at runtime
25
+ */
26
+ placeholderCompartment: Compartment;
27
+ /**
28
+ * Compartment to configure the panel at runtime
29
+ */
30
+ panelCompartment: Compartment;
31
+ /**
32
+ * Compartment to configure the autocompletion at runtime
33
+ */
34
+ autocompletionCompartment: Compartment;
35
+ /**
36
+ * Construct a new CodeEditor
37
+ * @param {ProgrammingLanguage} language The used programming language
38
+ * @param {string} editorPlaceHolder The placeholder for the editor
39
+ * @param {string} initialCode The initial code to display
40
+ * @param {number} indentLength The length in spaces for the indent unit
41
+ */
42
+ constructor(initialCode?: string, indentLength?: number);
43
+ /**
44
+ * Render the editor with the given options and panel
45
+ * @param {RenderOptions} options Options for rendering
46
+ * @param {HTMLElement} panel The panel to display at the bottom
47
+ * @return {HTMLElement} The rendered element
48
+ */
49
+ render(options: RenderOptions, panel?: HTMLElement): HTMLElement;
50
+ /**
51
+ * Set the language that is currently used
52
+ * @param {ProgrammingLanguage} language The language to use
53
+ */
9
54
  setLanguage(language: ProgrammingLanguage): void;
55
+ /**
56
+ * @param {CompletionSource} completionSource Function to obtain autocomplete results
57
+ */
58
+ setCompletionSource(completionSource: CompletionSource): void;
59
+ /**
60
+ * Set the length in spaces of the indentation unit
61
+ * @param {number} indentLength The number of spaces to use
62
+ */
10
63
  setIndentLength(indentLength: number): void;
64
+ /**
65
+ * Set the panel that is displayed at the bottom of the editor
66
+ * @param {HTMLElement} panel The panel to display
67
+ */
68
+ setPanel(panel: HTMLElement): void;
69
+ /**
70
+ * @return {string} The code within the editor
71
+ */
11
72
  getCode(): string;
73
+ /**
74
+ * @param {string} code The new code to be shown in the editor
75
+ */
76
+ setCode(code: string): void;
77
+ /**
78
+ * Put focus on the CodeEditor
79
+ */
80
+ focus(): void;
81
+ /**
82
+ * @param {number} indentLength The amount of spaces to use
83
+ * @return {string} The indentation unit to use
84
+ */
85
+ static getIndentUnit(indentLength: number): string;
86
+ /**
87
+ * @param {ProgrammingLanguage} language The language to support
88
+ * @return {LanguageSupport} CodeMirror LanguageSupport for the language
89
+ */
90
+ static getLanguageSupport(language: ProgrammingLanguage): LanguageSupport;
91
+ /**
92
+ * - [syntax highlighting depending on the language](#getLanguageSupport)
93
+ * - [line numbers](#gutter.lineNumbers)
94
+ * - [special character highlighting](#view.highlightSpecialChars)
95
+ * - [the undo history](#history.history)
96
+ * - [a fold gutter](#fold.foldGutter)
97
+ * - [custom selection drawing](#view.drawSelection)
98
+ * - [multiple selections](#state.EditorState^allowMultipleSelections)
99
+ * - [reindentation on input](#language.indentOnInput)
100
+ * - [the default highlight style](#highlight.defaultHighlightStyle) (as fallback)
101
+ * - [bracket matching](#matchbrackets.bracketMatching)
102
+ * - [bracket closing](#closebrackets.closeBrackets)
103
+ * - [autocompletion](#autocomplete.autocompletion)
104
+ * - [rectangular selection](#rectangular-selection.rectangularSelection)
105
+ * - [active line highlighting](#view.highlightActiveLine)
106
+ * - [active line gutter highlighting](#gutter.highlightActiveLineGutter)
107
+ * - [selection match highlighting](#search.highlightSelectionMatches)
108
+ * Keymaps:
109
+ * - [the default command bindings](#commands.defaultKeymap)
110
+ * - [search](#search.searchKeymap)
111
+ * - [commenting](#comment.commentKeymap)
112
+ * - [linting](#lint.lintKeymap)
113
+ * - [indenting with tab](#commands.indentWithTab)
114
+ * @return {Array<Extension} Default extensions to use
115
+ */
116
+ static getExtensions(): Array<Extension>;
12
117
  }
@@ -0,0 +1,102 @@
1
+ import { CodeEditor } from "./CodeEditor";
2
+ import { InputManager } from "./InputManager";
3
+ import { ProgrammingLanguage } from "./ProgrammingLanguage";
4
+ import { ButtonOptions, RenderOptions } from "./util/Util";
5
+ /**
6
+ * Enum representing the possible states while processing code
7
+ */
8
+ export declare enum RunState {
9
+ Loading = "loading",
10
+ Running = "running",
11
+ AwaitingInput = "awaiting_input",
12
+ Stopping = "stopping",
13
+ Ready = "ready"
14
+ }
15
+ /**
16
+ * Helper component to manage and visualize the current RunState
17
+ */
18
+ export declare class CodeRunner {
19
+ /**
20
+ * The currently used programming language
21
+ */
22
+ private programmingLanguage;
23
+ /**
24
+ * The editor in which the code is written
25
+ */
26
+ readonly editor: CodeEditor;
27
+ /**
28
+ * Component to request and handle input from the user
29
+ */
30
+ readonly inputManager: InputManager;
31
+ /**
32
+ * The backend that executes the code asynchronously
33
+ */
34
+ private backend;
35
+ /**
36
+ * Current state of the program
37
+ */
38
+ private state;
39
+ /**
40
+ * Buttons managed by this component
41
+ */
42
+ private buttons;
43
+ /**
44
+ * Construct a new RunStateManager with the given listeners
45
+ * @param {ProgrammingLanguage} programmingLanguage The language to use
46
+ */
47
+ constructor(programmingLanguage: ProgrammingLanguage);
48
+ /**
49
+ * Start the backend to enable running code
50
+ */
51
+ start(): Promise<void>;
52
+ /**
53
+ * Interrupt the currently running code
54
+ * @return {Promise<void>} Promise of stopping
55
+ */
56
+ stop(): Promise<void>;
57
+ /**
58
+ * Set the used programming language to the given one to allow editing and running code
59
+ * @param {ProgrammingLanguage} programmingLanguage The language to use
60
+ */
61
+ setProgrammingLanguage(programmingLanguage: ProgrammingLanguage): Promise<void>;
62
+ getProgrammingLanguage(): ProgrammingLanguage;
63
+ /**
64
+ * Get the button to run the code
65
+ */
66
+ get runButton(): HTMLButtonElement;
67
+ /**
68
+ * Get the button to interrupt the code
69
+ */
70
+ get stopButton(): HTMLButtonElement;
71
+ /**
72
+ * Show or hide the spinning circle, representing a running animation
73
+ * @param {boolean} show Whether to show the spinner
74
+ */
75
+ showSpinner(show: boolean): void;
76
+ /**
77
+ * Show the current state of the program to the user
78
+ * @param {RunState} state The current state of the run
79
+ * @param {string} message Optional message to indicate the state
80
+ */
81
+ setState(state: RunState, message?: string): void;
82
+ getState(): RunState;
83
+ /**
84
+ * Add a button to display to the user
85
+ * @param {ButtonOptions} options Options for rendering the button
86
+ * @param {function} onClick Listener for click events on the button
87
+ */
88
+ addButton(options: ButtonOptions, onClick: () => void): void;
89
+ /**
90
+ * Render the RunStateManager with the given options
91
+ * @param {RenderOptions} statusPanelOptions Options for rendering the panel
92
+ * @param {RenderOptions} inputOptions Options for rendering the InputManager
93
+ * @param {RenderOptions} codeEditorOptions Options for rendering the editor
94
+ * @return {HTMLElement} The rendered RunStateManager
95
+ */
96
+ render(statusPanelOptions: RenderOptions, inputOptions: RenderOptions, codeEditorOptions: RenderOptions): HTMLElement;
97
+ /**
98
+ * Run the code that is currently present in the editor
99
+ * @return {Promise<void>} Promise of running the code
100
+ */
101
+ runCode(): Promise<void>;
102
+ }
@@ -1,15 +1,20 @@
1
1
  import { ProgrammingLanguage } from "./ProgrammingLanguage";
2
- export declare const MAIN_APP_ID = "papyros";
3
- export declare const OUTPUT_TA_ID = "code-output-area";
4
- export declare const INPUT_TA_ID = "code-input-area";
5
- export declare const EDITOR_WRAPPER_ID = "code-area";
6
- export declare const STATE_SPINNER_ID = "state-spinner";
7
- export declare const APPLICATION_STATE_TEXT_ID = "application-state-text";
8
- export declare const RUN_BTN_ID = "run-code-btn";
9
- export declare const TERMINATE_BTN_ID = "terminate-btn";
10
- export declare const PROGRAMMING_LANGUAGE_SELECT_ID = "programming-language-select";
2
+ export declare const MAIN_APP_ID: string;
3
+ export declare const OUTPUT_TA_ID: string;
4
+ export declare const INPUT_AREA_WRAPPER_ID: string;
5
+ export declare const INPUT_TA_ID: string;
6
+ export declare const USER_INPUT_WRAPPER_ID: string;
7
+ export declare const EDITOR_WRAPPER_ID: string;
8
+ export declare const PANEL_WRAPPER_ID: string;
9
+ export declare const STATE_SPINNER_ID: string;
10
+ export declare const APPLICATION_STATE_TEXT_ID: string;
11
+ export declare const RUN_BTN_ID: string;
12
+ export declare const STOP_BTN_ID: string;
13
+ export declare const SEND_INPUT_BTN_ID: string;
14
+ export declare const SWITCH_INPUT_MODE_A_ID: string;
15
+ export declare const EXAMPLE_SELECT_ID: string;
16
+ export declare const LOCALE_SELECT_ID: string;
17
+ export declare const PROGRAMMING_LANGUAGE_SELECT_ID: string;
11
18
  export declare const DEFAULT_PROGRAMMING_LANGUAGE = ProgrammingLanguage.Python;
12
- export declare const LOCALE_SELECT_ID = "locale-select";
13
19
  export declare const DEFAULT_LOCALE = "nl";
14
- export declare const INPUT_RELATIVE_URL = "/__papyros_input";
15
- export declare const SERVICE_WORKER_PATH = "./inputServiceWorker.js";
20
+ export declare const DEFAULT_SERVICE_WORKER = "inputServiceWorker.js";
@@ -0,0 +1,32 @@
1
+ import { BackendEvent } from "./BackendEvent";
2
+ import { RenderOptions } from "./util/Util";
3
+ import { UserInputHandler } from "./input/UserInputHandler";
4
+ export declare enum InputMode {
5
+ Interactive = "interactive",
6
+ Batch = "batch"
7
+ }
8
+ export declare const INPUT_MODES: InputMode[];
9
+ export declare class InputManager {
10
+ private inputMode;
11
+ private inputHandlers;
12
+ private renderOptions;
13
+ private waiting;
14
+ private prompt;
15
+ private sendInput;
16
+ constructor(sendInput: (input: string) => void);
17
+ private buildInputHandlerMap;
18
+ getInputMode(): InputMode;
19
+ setInputMode(inputMode: InputMode): void;
20
+ get inputHandler(): UserInputHandler;
21
+ render(options: RenderOptions): void;
22
+ waitWithPrompt(waiting: boolean, prompt?: string): void;
23
+ onUserInput(): Promise<void>;
24
+ /**
25
+ * Asynchronously handle an input request by prompting the user for input
26
+ * @param {BackendEvent} e Event containing the input data
27
+ * @return {Promise<void>} Promise of handling the request
28
+ */
29
+ onInputRequest(e: BackendEvent): Promise<void>;
30
+ onRunStart(): void;
31
+ onRunEnd(): void;
32
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import { BackendEvent } from "./BackendEvent";
2
+ import { CodeEditor } from "./CodeEditor";
3
+ import { InputManager, InputMode } from "./InputManager";
4
+ import { OutputManager } from "./OutputManager";
5
+ import { Papyros } from "./Papyros";
6
+ import { CodeRunner, RunState } from "./CodeRunner";
7
+ import { InputWorker } from "./workers/input/InputWorker";
8
+ export * from "./ProgrammingLanguage";
9
+ export type { BackendEvent };
10
+ export { Papyros, CodeEditor, RunState, CodeRunner, InputManager, InputMode, OutputManager, InputWorker };
@@ -0,0 +1,75 @@
1
+ import { BackendEvent } from "./BackendEvent";
2
+ import { RenderOptions } from "./util/Util";
3
+ /**
4
+ * Shape of Error objects that are easy to interpret
5
+ */
6
+ export interface FriendlyError {
7
+ /**
8
+ * The name of the Error
9
+ */
10
+ name: string;
11
+ /**
12
+ * Traceback for where in the code the Error occurred
13
+ */
14
+ traceback?: string;
15
+ /**
16
+ * General information about this type of Error
17
+ */
18
+ info?: string;
19
+ /**
20
+ * Information about what went wrong in this case
21
+ */
22
+ what?: string;
23
+ /**
24
+ * Information about why this is wrong and how to fix it
25
+ */
26
+ why?: string;
27
+ /**
28
+ * Where specifically in the source code the Error occurred
29
+ */
30
+ where?: string;
31
+ }
32
+ /**
33
+ * Component for displaying code output or errors to the user
34
+ */
35
+ export declare class OutputManager {
36
+ options: RenderOptions;
37
+ constructor();
38
+ /**
39
+ * Retrieve the parent element containing all output parts
40
+ */
41
+ get outputArea(): HTMLElement;
42
+ /**
43
+ * Render an element in the next position of the output area
44
+ * @param {string} html Safe string version of the next child to render
45
+ */
46
+ renderNextElement(html: string): void;
47
+ /**
48
+ * Convert a piece of text to a span element for displaying
49
+ * @param {string} text The text content for the span
50
+ * @param {boolean} ignoreEmpty Whether to remove empty lines in the text
51
+ * @param {string} className Optional class name for the span
52
+ * @return {string} String version of the created span
53
+ */
54
+ spanify(text: string, ignoreEmpty?: boolean, className?: string): string;
55
+ /**
56
+ * Display output to the user, based on its content type
57
+ * @param {BackendEvent} output Event containing the output data
58
+ */
59
+ showOutput(output: BackendEvent): void;
60
+ /**
61
+ * Display an error to the user
62
+ * @param {BackendEvent} error Event containing the error data
63
+ */
64
+ showError(error: BackendEvent): void;
65
+ /**
66
+ * Render the OutputManager with the given options
67
+ * @param {RenderOptions} options Options for rendering
68
+ * @return {HTMLElement} The rendered output area
69
+ */
70
+ render(options: RenderOptions): HTMLElement;
71
+ /**
72
+ * Clear the contents of the output area
73
+ */
74
+ reset(): void;
75
+ }