@dodona/papyros 0.4.2 → 0.5.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.
@@ -40,9 +40,9 @@ export interface LoadingData {
40
40
  */
41
41
  modules: Array<string>;
42
42
  /**
43
- * Whether the modules are being loaded or have been loaded
43
+ * The status of the import
44
44
  */
45
- loading: boolean;
45
+ status: "loading" | "loaded" | "failed";
46
46
  }
47
47
  /**
48
48
  * Helper component to manage and visualize the current RunState
@@ -84,6 +84,10 @@ export declare class CodeRunner extends Renderable<CodeRunnerRenderOptions> {
84
84
  * Previous state to restore when loading is done
85
85
  */
86
86
  private previousState;
87
+ /**
88
+ * Time at which the setState call occurred
89
+ */
90
+ private runStartTime;
87
91
  /**
88
92
  * Construct a new RunStateManager with the given listeners
89
93
  * @param {ProgrammingLanguage} programmingLanguage The language to use
@@ -104,15 +108,10 @@ export declare class CodeRunner extends Renderable<CodeRunnerRenderOptions> {
104
108
  * @param {ProgrammingLanguage} programmingLanguage The language to use
105
109
  */
106
110
  setProgrammingLanguage(programmingLanguage: ProgrammingLanguage): Promise<void>;
107
- getProgrammingLanguage(): ProgrammingLanguage;
108
111
  /**
109
- * Get the button to run the code
112
+ * @return {ProgrammingLanguage} The current programming language
110
113
  */
111
- get runButton(): HTMLButtonElement;
112
- /**
113
- * Get the button to interrupt the code
114
- */
115
- get stopButton(): HTMLButtonElement;
114
+ getProgrammingLanguage(): ProgrammingLanguage;
116
115
  /**
117
116
  * Show or hide the spinning circle, representing a running animation
118
117
  * @param {boolean} show Whether to show the spinner
@@ -124,14 +123,30 @@ export declare class CodeRunner extends Renderable<CodeRunnerRenderOptions> {
124
123
  * @param {string} message Optional message to indicate the state
125
124
  */
126
125
  setState(state: RunState, message?: string): void;
126
+ /**
127
+ * @return {RunState} The state of the current run
128
+ */
127
129
  getState(): RunState;
128
- removeButton(id: string): void;
130
+ /**
131
+ * Remove a button from the internal button list. Requires a re-render to update
132
+ * @param {string} id Identifier of the button to remove
133
+ */
134
+ private removeButton;
129
135
  /**
130
136
  * Add a button to display to the user
131
137
  * @param {ButtonOptions} options Options for rendering the button
132
138
  * @param {function} onClick Listener for click events on the button
133
139
  */
134
140
  addButton(options: ButtonOptions, onClick: () => void): void;
141
+ /**
142
+ * Generate a button that the user can click to process code
143
+ * Can either run the code or interrupt it if already running
144
+ * @return {DynamicButton} A button to interact with the code according to the current state
145
+ */
146
+ private getCodeActionButton;
147
+ /**
148
+ * Specific helper method to render only the buttons required by the user
149
+ */
135
150
  private renderButtons;
136
151
  protected _render(options: CodeRunnerRenderOptions): HTMLElement;
137
152
  /**
@@ -145,5 +160,6 @@ export declare class CodeRunner extends Renderable<CodeRunnerRenderOptions> {
145
160
  * @param {BackendEvent} e The loading event
146
161
  */
147
162
  private onLoad;
163
+ private onStart;
148
164
  }
149
165
  export {};
@@ -22,6 +22,7 @@ export declare class InputManager extends Renderable<InputManagerRenderOptions>
22
22
  private buildInputHandlerMap;
23
23
  getInputMode(): InputMode;
24
24
  setInputMode(inputMode: InputMode): void;
25
+ getInputHandler(inputMode: InputMode): UserInputHandler;
25
26
  get inputHandler(): UserInputHandler;
26
27
  isWaiting(): boolean;
27
28
  protected _render(options: InputManagerRenderOptions): void;
@@ -1,27 +1,41 @@
1
1
  import { CodeMirrorEditor } from "./CodeMirrorEditor";
2
2
  import { UsedInputGutterInfo } from "./Gutters";
3
+ import { ViewUpdate } from "@codemirror/view";
3
4
  /**
4
- * Editor to handle and highlight user input
5
+ * Arguments used to higlight lines in the Editor
5
6
  */
6
- export declare class BatchInputEditor extends CodeMirrorEditor {
7
+ interface HighlightArgs {
7
8
  /**
8
- * Style classes used to highlight lines
9
+ * Whether the user's code is currently running and using input
9
10
  */
10
- private static HIGHLIGHT_CLASSES;
11
+ running: boolean;
12
+ /**
13
+ * Function to obtain gutter info per line (1-based indexing)
14
+ */
15
+ getInfo: (lineInfo: number) => UsedInputGutterInfo;
16
+ }
17
+ /**
18
+ * Editor to handle and highlight user input
19
+ */
20
+ export declare class BatchInputEditor extends CodeMirrorEditor {
11
21
  /**
12
22
  * Gutters to show which lines were used
13
23
  */
14
24
  private usedInputGutters;
25
+ private lastHighlightArgs?;
15
26
  constructor();
27
+ private getLastHighlightArgs;
28
+ protected onViewUpdate(v: ViewUpdate): void;
16
29
  /**
17
30
  * Apply highlighting to the lines in the Editor
18
- * @param {function(number): UsedInputGutterInfo} getInfo Function to obtain gutter
19
- * info per line (1-based indexing)
31
+ * @param {HightlightArgs} args Arguments for highlighting
32
+ * @param {Array<string>} highlightClasses HTML classes to use for consumed lines
20
33
  */
21
- highlight(getInfo: (lineNr: number) => UsedInputGutterInfo): void;
34
+ highlight(args: HighlightArgs, highlightClasses?: string[]): void;
22
35
  /**
23
36
  * @return {Array<string>} Array of valid user input
24
37
  * Data in the last line that is not terminated by a newline is omitted
25
38
  */
26
39
  getLines(): Array<string>;
27
40
  }
41
+ export {};
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { Compartment, Extension } from "@codemirror/state";
3
- import { EditorView } from "@codemirror/view";
3
+ import { EditorView, ViewUpdate } from "@codemirror/view";
4
4
  import { Renderable, RenderOptions } from "../util/Rendering";
5
5
  import { StyleSpec } from "style-mod";
6
6
  /**
@@ -62,6 +62,7 @@ export declare abstract class CodeMirrorEditor extends Renderable {
62
62
  static STYLE: string;
63
63
  static PLACEHOLDER: string;
64
64
  static THEME: string;
65
+ static LANGUAGE: string;
65
66
  /**
66
67
  * CodeMirror EditorView representing the internal editor
67
68
  */
@@ -83,6 +84,7 @@ export declare abstract class CodeMirrorEditor extends Renderable {
83
84
  * @param {EditorStyling} styling Data to style this editor
84
85
  */
85
86
  constructor(compartments: Set<string>, styling: EditorStyling);
87
+ protected onViewUpdate(v: ViewUpdate): void;
86
88
  /**
87
89
  * @param {Extension} extension The extension to add to the Editor
88
90
  */
@@ -0,0 +1 @@
1
+ export declare const darkTheme: import("@codemirror/state").Extension;
@@ -23,6 +23,10 @@ export interface IGutterConfig<Info extends GutterInfo> {
23
23
  * Name of this Gutter
24
24
  */
25
25
  name: string;
26
+ /**
27
+ * HTML class names for the marker icons
28
+ */
29
+ markerClasses?: string;
26
30
  /**
27
31
  * Handler for when a Gutter element is clicked
28
32
  */
@@ -53,12 +57,19 @@ export declare abstract class Gutters<Info extends GutterInfo = GutterInfo, Conf
53
57
  * Will only be called when info.on is True
54
58
  */
55
59
  protected abstract marker(info: Info): GutterMarker;
60
+ private applyClasses;
61
+ hasMarker(view: EditorView, lineNr: number): boolean;
56
62
  /**
57
63
  * Set a marker with the given info
58
64
  * @param {EditorView} view View in which the Gutters live
59
65
  * @param {Info} info Info used to render the marker
60
66
  */
61
67
  setMarker(view: EditorView, info: Info): void;
68
+ /**
69
+ * @param {EditorView} view The view in which the Gutters live
70
+ * @return {Set<number>} The 1-based line numbers with a breakpoint
71
+ */
72
+ getMarkedLines(view: EditorView): Set<number>;
62
73
  /**
63
74
  * @return {Extension} The Gutters as a CodeMirror Extension
64
75
  */
@@ -70,11 +81,6 @@ export declare abstract class Gutters<Info extends GutterInfo = GutterInfo, Conf
70
81
  export declare class BreakpointsGutter extends Gutters {
71
82
  constructor();
72
83
  protected marker(): GutterMarker;
73
- /**
74
- * @param {EditorView} view The view in which the Gutters live
75
- * @return {Set<number>} The 1-based line numbers with a breakpoint
76
- */
77
- getBreakpoints(view: EditorView): Set<number>;
78
84
  }
79
85
  /**
80
86
  * Extra data used to represent input gutters
@@ -10,6 +10,10 @@ export declare class BatchInputHandler extends UserInputHandler {
10
10
  * Messages used when asking for user input
11
11
  */
12
12
  private prompts;
13
+ /**
14
+ * Whether a run is occurring
15
+ */
16
+ private running;
13
17
  /**
14
18
  * Editor containing the input of the user
15
19
  */
@@ -23,7 +27,7 @@ export declare class BatchInputHandler extends UserInputHandler {
23
27
  * Construct a new BatchInputHandler
24
28
  * @param {function()} inputCallback Callback for when the user has entered a value
25
29
  */
26
- constructor(inputCallback: () => void);
30
+ constructor(inputCallback: (line: string) => void);
27
31
  /**
28
32
  * Handle new input, potentially sending it to the awaiting receiver
29
33
  * @param {string} newInput The new user input
@@ -11,12 +11,12 @@ export declare abstract class UserInputHandler extends Renderable<InputManagerRe
11
11
  /**
12
12
  * Function to call when the user provided new input
13
13
  */
14
- protected inputCallback: () => void;
14
+ protected inputCallback: (line: string) => void;
15
15
  /**
16
16
  * Construct a new UserInputHandler
17
17
  * @param {function()} inputCallback Callback for when the user has entered a value
18
18
  */
19
- constructor(inputCallback: () => void);
19
+ constructor(inputCallback: (line: string) => void);
20
20
  /**
21
21
  * Whether this handler has input ready
22
22
  */
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@dodona/papyros",
3
- "version": "0.4.2",
3
+ "version": "0.5.1",
4
4
  "private": false,
5
- "homepage": ".",
5
+ "homepage": "https://papyros.dodona.be/",
6
6
  "devDependencies": {
7
7
  "@types/escape-html": "^1.0.1",
8
8
  "@types/i18n-js": "^3.8.2",