@dodona/papyros 0.1.954-darkmode → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -13,7 +13,7 @@
13
13
  </p>
14
14
 
15
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.
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
17
  By taking away obstacles between students and coding, the learning experience becomes
18
18
  smoother and less error-prone.
19
19
 
@@ -38,22 +38,24 @@ as the user knows for what purpose Papyros is being used. For example, when used
38
38
  scope of a Python exercise in Dodona, there is no need to support other programming languages.
39
39
  The locale should also match that of the actual application.
40
40
 
41
- The easiest way to initialize Papyros is by using the static method Papyros.fromElement.
42
- This method expects a parent element that wraps the scratchpad and a PapyrosConfig object.
41
+ The easiest way to initialize Papyros is by using the static method `Papyros.fromElement`.
42
+ This method expects a parent element that wraps the scratchpad and a `PapyrosConfig` object.
43
43
  The following options are supported:
44
- - standAlone: Whether to operate in stand-alone or embedded mode as described above.
45
- - locale: The locale to use, currently English and Dutch translations are provided.
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
44
 
49
- Furthermore, you can provide fine-grained configuration in embedded mode by providing RenderOptions
45
+ - `standAlone`: Whether to operate in stand-alone or embedded mode as described above.
46
+ - `locale`: The locale to use, currently English and Dutch translations are provided.
47
+ - `programmingLanguage`: The language to use in the CodeEditor and Backend
48
+ - `inputMode`: How the users can provide input, according to the [InputMode enum](/src/InputManager.ts)
49
+
50
+ Furthermore, you can provide fine-grained configuration in embedded mode by providing `RenderOptions`
50
51
  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
+ You can also specify attributes, such as `style` or `data`, or `classNames` to be used.
52
53
  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
54
+
55
+ - `code`: the CodeEditor.
56
+ - `panel`: the StatusPanel in the CodeEditor
57
+ - `input`: the field for the user input
58
+ - `output`: the panel for output of the code
57
59
 
58
60
  ### User input
59
61
 
package/dist/Backend.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { CompletionContext, CompletionResult } from "@codemirror/autocomplete";
2
2
  import { BackendEvent } from "./BackendEvent";
3
3
  import { SyncExtras } from "comsync";
4
+ import { BackendEventQueue } from "./BackendEventQueue";
4
5
  /**
5
6
  * Interface to represent the CodeMirror CompletionContext in a worker
6
7
  */
@@ -34,9 +35,16 @@ export interface WorkerAutocompleteContext {
34
35
  text: string;
35
36
  } | null;
36
37
  }
38
+ export interface WorkerDiagnostic {
39
+ lineNr: number;
40
+ columnNr: number;
41
+ severity: "info" | "warning" | "error";
42
+ message: string;
43
+ }
37
44
  export declare abstract class Backend<Extras extends SyncExtras = SyncExtras> {
38
45
  protected extras: Extras;
39
46
  protected onEvent: (e: BackendEvent) => any;
47
+ protected queue: BackendEventQueue;
40
48
  /**
41
49
  * Constructor is limited as it is meant to be used as a WebWorker
42
50
  * Proper initialization occurs in the launch method when the worker is started
@@ -74,4 +82,17 @@ export declare abstract class Backend<Extras extends SyncExtras = SyncExtras> {
74
82
  * @param {WorkerAutocompleteContext} context Context to autcomplete in
75
83
  */
76
84
  abstract autocomplete(context: WorkerAutocompleteContext): Promise<CompletionResult | null>;
85
+ /**
86
+ * Generate linting suggestions for the given code
87
+ * @param {string} code The code to lint
88
+ */
89
+ abstract lintCode(code: string): Promise<Array<WorkerDiagnostic>>;
90
+ /**
91
+ * @return {boolean} Whether too many output events were generated
92
+ */
93
+ hasOverflow(): boolean;
94
+ /**
95
+ * @return {Array<BackendEvent>} The events that happened after overflow
96
+ */
97
+ getOverflow(): Array<BackendEvent>;
77
98
  }
@@ -0,0 +1,85 @@
1
+ import { BackendEvent, BackendEventType } from "./BackendEvent";
2
+ /**
3
+ * Queue to limit the amount of messages sent between threads
4
+ * This prevents communication issues which arise either in Comlink
5
+ * or in the WebWorker message passing code
6
+ */
7
+ export declare class BackendEventQueue {
8
+ /**
9
+ * Function to process events in the queue
10
+ */
11
+ private callback;
12
+ /**
13
+ * The maximal amount of output events to send before overflowing
14
+ */
15
+ private limit;
16
+ /**
17
+ * The time in milliseconds before sending events through
18
+ */
19
+ private flushTime;
20
+ /**
21
+ * Queue storing the BackendEvents before flushing
22
+ */
23
+ private queue;
24
+ /**
25
+ * Queue storing Output-events after overflowing
26
+ */
27
+ private overflow;
28
+ /**
29
+ * Time in milliseconds when the last flush occurred
30
+ */
31
+ private lastFlushTime;
32
+ /**
33
+ * Amount of BackendEvents sent through this run
34
+ */
35
+ private sendCount;
36
+ /**
37
+ * Decoder to convert data to strings
38
+ */
39
+ private decoder;
40
+ /**
41
+ * @param {Function} callback Function to process events in the queue
42
+ * @param {number} limit The maximal amount of output lines to send before overflowing
43
+ * @param {number} flushTime The time in milliseconds before sending events through
44
+ */
45
+ constructor(callback: (e: BackendEvent) => void, limit?: number, flushTime?: number);
46
+ /**
47
+ * Add an element to the queue
48
+ * @param {BackendEventType} type The type of the event
49
+ * @param {string | BufferSource} text The data for the event
50
+ * @param {string | any} extra Extra data for the event
51
+ * If string, interpreted as the contentType
52
+ * If anything else, it should contain a contentType
53
+ * If the contentType is not textual, an error is thrown
54
+ */
55
+ put(type: BackendEventType, text: string | BufferSource, extra: string | any): void;
56
+ /**
57
+ * @return {boolean} Whether the queue contents should be flushed
58
+ */
59
+ protected shouldFlush(): boolean;
60
+ /**
61
+ * Reset the queue contents for a new run
62
+ */
63
+ reset(): void;
64
+ /**
65
+ * @param {BackendEvent} e The event put in the queue
66
+ * @return {number} The amount of lines of data in the event
67
+ */
68
+ private static lines;
69
+ /**
70
+ * Flush the queue contents using the callback
71
+ */
72
+ flush(): void;
73
+ /**
74
+ * @return {boolean} Whether too many output events were generated
75
+ */
76
+ hasOverflow(): boolean;
77
+ /**
78
+ * @return {Array<BackendEvent>} The events that happened after overflow
79
+ */
80
+ getOverflow(): Array<BackendEvent>;
81
+ /**
82
+ * @param {Function} callback The event-consuming callback
83
+ */
84
+ setCallback(callback: (e: BackendEvent) => void): void;
85
+ }
@@ -25,7 +25,7 @@ export declare abstract class BackendManager {
25
25
  * Map an event type to interested subscribers
26
26
  * Uses an Array to maintain order of subscription
27
27
  */
28
- static subscriberMap: Map<BackendEventType, Array<BackendEventListener>>;
28
+ private static subscriberMap;
29
29
  /**
30
30
  * The channel used to communicate with the SyncClients
31
31
  */
@@ -40,7 +40,13 @@ export declare abstract class BackendManager {
40
40
  * @param {ProgrammingLanguage} language The programming language supported by the backend
41
41
  * @return {SyncClient<Backend>} A SyncClient for the Backend
42
42
  */
43
- static startBackend(language: ProgrammingLanguage): SyncClient<Backend>;
43
+ static getBackend(language: ProgrammingLanguage): SyncClient<Backend>;
44
+ /**
45
+ * Remove a backend for the given language
46
+ * @param {ProgrammingLanguage} language The programming language supported by the backend
47
+ * @return {boolean} Whether the remove operation had any effect
48
+ */
49
+ static removeBackend(language: ProgrammingLanguage): boolean;
44
50
  /**
45
51
  * Register a callback for when an event of a certain type is published
46
52
  * @param {BackendEventType} type The type of event to subscribe to
@@ -1,9 +1,8 @@
1
- import { LanguageSupport } from "@codemirror/language";
2
- import { Compartment, Extension } from "@codemirror/state";
3
1
  import { ProgrammingLanguage } from "./ProgrammingLanguage";
4
- import { EditorView } from "@codemirror/view";
5
- import { CompletionSource } from "@codemirror/autocomplete";
6
2
  import { Renderable, RenderOptions } from "./util/Rendering";
3
+ import { CompletionSource } from "@codemirror/autocomplete";
4
+ import { EditorView } from "@codemirror/view";
5
+ import { Diagnostic } from "@codemirror/lint";
7
6
  /**
8
7
  * Component that provides useful features to users writing code
9
8
  */
@@ -11,55 +10,49 @@ export declare class CodeEditor extends Renderable {
11
10
  /**
12
11
  * Reference to the user interface of the editor
13
12
  */
14
- editorView: EditorView;
15
- /**
16
- * Compartment to change language at runtime
17
- */
18
- languageCompartment: Compartment;
19
- /**
20
- * Compartment to configure indentation level at runtime
21
- */
22
- indentCompartment: Compartment;
23
- /**
24
- * Compartment to configure the placeholder at runtime
25
- */
26
- placeholderCompartment: Compartment;
13
+ readonly editorView: EditorView;
27
14
  /**
28
- * Compartment to configure the panel at runtime
15
+ * Mapping from CodeEditorOptions to a configurable compartment
29
16
  */
30
- panelCompartment: Compartment;
31
- /**
32
- * Compartment to configure the autocompletion at runtime
33
- */
34
- autocompletionCompartment: Compartment;
35
- /**
36
- * Compartment to configure styling at runtime (e.g. switching to dark mode)
37
- */
38
- styleCompartent: Compartment;
17
+ private compartments;
39
18
  /**
40
19
  * Construct a new CodeEditor
41
20
  * @param {string} initialCode The initial code to display
42
21
  * @param {number} indentLength The length in spaces for the indent unit
43
22
  */
44
23
  constructor(initialCode?: string, indentLength?: number);
24
+ /**
25
+ * Helper method to dispatch configuration changes at runtime
26
+ * @param {Array<[Option, Extension]>} items Array of items to reconfigure
27
+ * The option indicates the relevant compartment
28
+ * The extension indicates the new configuration
29
+ */
30
+ private reconfigure;
31
+ /**
32
+ * Render the editor with the given options and panel
33
+ * @param {RenderOptions} options Options for rendering
34
+ * @param {HTMLElement} panel The panel to display at the bottom
35
+ * @return {HTMLElement} The rendered element
36
+ */
45
37
  protected _render(options: RenderOptions): void;
46
38
  /**
47
- * Set the language that is currently used
48
39
  * @param {ProgrammingLanguage} language The language to use
49
40
  */
50
- setLanguage(language: ProgrammingLanguage): void;
41
+ setProgrammingLanguage(language: ProgrammingLanguage): void;
51
42
  /**
52
43
  * @param {CompletionSource} completionSource Function to obtain autocomplete results
53
44
  */
54
45
  setCompletionSource(completionSource: CompletionSource): void;
55
46
  /**
56
- * Set the length in spaces of the indentation unit
57
- * @param {number} indentLength The number of spaces to use
47
+ * @param {LintSource} lintSource Function to obtain linting results
48
+ */
49
+ setLintingSource(lintSource: (view: EditorView) => readonly Diagnostic[] | Promise<readonly Diagnostic[]>): void;
50
+ /**
51
+ * @param {number} indentLength The number of spaces to use for indentation
58
52
  */
59
53
  setIndentLength(indentLength: number): void;
60
54
  /**
61
- * Set the panel that is displayed at the bottom of the editor
62
- * @param {HTMLElement} panel The panel to display
55
+ * @param {HTMLElement} panel The panel to display at the bottom of the editor
63
56
  */
64
57
  setPanel(panel: HTMLElement): void;
65
58
  /**
@@ -76,40 +69,38 @@ export declare class CodeEditor extends Renderable {
76
69
  focus(): void;
77
70
  /**
78
71
  * @param {number} indentLength The amount of spaces to use
79
- * @return {string} The indentation unit to use
72
+ * @return {string} The indentation unit to be used by CodeMirror
80
73
  */
81
- static getIndentUnit(indentLength: number): string;
74
+ private static getIndentUnit;
82
75
  /**
83
76
  * @param {ProgrammingLanguage} language The language to support
84
77
  * @return {LanguageSupport} CodeMirror LanguageSupport for the language
85
78
  */
86
- static getLanguageSupport(language: ProgrammingLanguage): LanguageSupport;
87
- /**
88
- * - [syntax highlighting depending on the language](#getLanguageSupport)
89
- * - [line numbers](#gutter.lineNumbers)
90
- * - [special character highlighting](#view.highlightSpecialChars)
91
- * - [the undo history](#history.history)
92
- * - [a fold gutter](#fold.foldGutter)
93
- * - [custom selection drawing](#view.drawSelection)
94
- * - [multiple selections](#state.EditorState^allowMultipleSelections)
95
- * - [reindentation on input](#language.indentOnInput)
96
- * - [syntax highlighting with the default highlight style]
97
- * (#highlight.defaultHighlightStyle) (as fallback)
98
- * - [bracket matching](#matchbrackets.bracketMatching)
99
- * - [bracket closing](#closebrackets.closeBrackets)
100
- * - [autocompletion](#autocomplete.autocompletion)
101
- * - [rectangular selection](#rectangular-selection.rectangularSelection)
102
- * - [active line highlighting](#view.highlightActiveLine)
103
- * - [active line gutter highlighting](#gutter.highlightActiveLineGutter)
104
- * - [selection match highlighting](#search.highlightSelectionMatches)
79
+ private static getLanguageSupport;
80
+ /**
81
+ * - line numbers
82
+ * - special character highlighting
83
+ * - the undo history
84
+ * - a fold gutter
85
+ * - gutter for linting
86
+ * - custom selection drawing
87
+ * - multiple selections
88
+ * - reindentation on input
89
+ * - bracket matching
90
+ * - bracket closing
91
+ * - autocompletion
92
+ * - rectangular selection
93
+ * - active line highlighting
94
+ * - active line gutter highlighting
95
+ * - selection match highlighting
105
96
  * Keymaps:
106
- * - [bracket closing](#commands.closeBracketsKeymap)
107
- * - [the default command bindings](#commands.defaultKeymap)
108
- * - [search](#search.searchKeymap)
109
- * - [commenting](#comment.commentKeymap)
110
- * - [linting](#lint.lintKeymap)
111
- * - [indenting with tab](#commands.indentWithTab)
97
+ * - the default command bindings
98
+ * - bracket closing
99
+ * - searching
100
+ * - linting
101
+ * - completion
102
+ * - indenting with tab
112
103
  * @return {Array<Extension} Default extensions to use
113
104
  */
114
- static getExtensions(): Array<Extension>;
105
+ private static getExtensions;
115
106
  }
@@ -1,6 +1,8 @@
1
1
  import { ProgrammingLanguage } from "./ProgrammingLanguage";
2
2
  export declare const MAIN_APP_ID: string;
3
- export declare const OUTPUT_TA_ID: string;
3
+ export declare const OUTPUT_AREA_WRAPPER_ID: string;
4
+ export declare const OUTPUT_AREA_ID: string;
5
+ export declare const OUTPUT_OVERFLOW_ID: string;
4
6
  export declare const INPUT_AREA_WRAPPER_ID: string;
5
7
  export declare const INPUT_TA_ID: string;
6
8
  export declare const USER_INPUT_WRAPPER_ID: string;
@@ -1,4 +1,3 @@
1
- import { BackendEvent } from "./BackendEvent";
2
1
  import { UserInputHandler } from "./input/UserInputHandler";
3
2
  import { Renderable, RenderOptions } from "./util/Rendering";
4
3
  export declare enum InputMode {
@@ -17,15 +16,16 @@ export declare class InputManager extends Renderable {
17
16
  getInputMode(): InputMode;
18
17
  setInputMode(inputMode: InputMode): void;
19
18
  get inputHandler(): UserInputHandler;
20
- _render(options: RenderOptions): void;
21
- waitWithPrompt(waiting: boolean, prompt?: string): void;
22
- onUserInput(): Promise<void>;
19
+ isWaiting(): boolean;
20
+ protected _render(options: RenderOptions): void;
21
+ private waitWithPrompt;
22
+ private onUserInput;
23
23
  /**
24
24
  * Asynchronously handle an input request by prompting the user for input
25
25
  * @param {BackendEvent} e Event containing the input data
26
26
  * @return {Promise<void>} Promise of handling the request
27
27
  */
28
- onInputRequest(e: BackendEvent): Promise<void>;
29
- onRunStart(): void;
30
- onRunEnd(): void;
28
+ private onInputRequest;
29
+ private onRunStart;
30
+ private onRunEnd;
31
31
  }