@dodona/papyros 0.4.1 → 0.5.0

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/dist/Papyros.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./Papyros.css";
2
- import { InputMode } from "./InputManager";
2
+ import { InputManagerRenderOptions, InputMode } from "./InputManager";
3
3
  import { ProgrammingLanguage } from "./ProgrammingLanguage";
4
4
  import { RunState, CodeRunner } from "./CodeRunner";
5
5
  import { AtomicsChannelOptions, ServiceWorkerChannelOptions } from "sync-message";
@@ -54,7 +54,7 @@ export interface PapyrosRenderOptions {
54
54
  /**
55
55
  * RenderOptions for the input field
56
56
  */
57
- inputOptions?: RenderOptions;
57
+ inputOptions?: InputManagerRenderOptions;
58
58
  /**
59
59
  * RenderOptions for the output field
60
60
  */
@@ -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
  */
@@ -116,9 +118,9 @@ export declare abstract class CodeMirrorEditor extends Renderable {
116
118
  setDarkMode(darkMode: boolean): void;
117
119
  /**
118
120
  * Override the style used by this Editor
119
- * @param {any} styling Object with keys of EditorStyling to override styles
121
+ * @param {Partial<EditorStyling>} styling Object with keys of EditorStyling to override styles
120
122
  */
121
- setStyling(styling: any): void;
123
+ setStyling(styling: Partial<EditorStyling>): void;
122
124
  protected _render(options: RenderOptions): void;
123
125
  /**
124
126
  * Process the changes by informing the listeners of the new contents
@@ -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
@@ -1,6 +1,5 @@
1
- import { InputMode } from "../InputManager";
1
+ import { InputManagerRenderOptions, InputMode } from "../InputManager";
2
2
  import { UserInputHandler } from "./UserInputHandler";
3
- import { RenderOptions } from "../util/Rendering";
4
3
  import { BatchInputEditor } from "../editor/BatchInputEditor";
5
4
  export declare class BatchInputHandler extends UserInputHandler {
6
5
  /**
@@ -11,6 +10,10 @@ export declare class BatchInputHandler extends UserInputHandler {
11
10
  * Messages used when asking for user input
12
11
  */
13
12
  private prompts;
13
+ /**
14
+ * Whether a run is occurring
15
+ */
16
+ private running;
14
17
  /**
15
18
  * Editor containing the input of the user
16
19
  */
@@ -24,7 +27,7 @@ export declare class BatchInputHandler extends UserInputHandler {
24
27
  * Construct a new BatchInputHandler
25
28
  * @param {function()} inputCallback Callback for when the user has entered a value
26
29
  */
27
- constructor(inputCallback: () => void);
30
+ constructor(inputCallback: (line: string) => void);
28
31
  /**
29
32
  * Handle new input, potentially sending it to the awaiting receiver
30
33
  * @param {string} newInput The new user input
@@ -45,5 +48,5 @@ export declare class BatchInputHandler extends UserInputHandler {
45
48
  waitWithPrompt(waiting: boolean, prompt?: string): void;
46
49
  protected setPlaceholder(placeholderValue: string): void;
47
50
  focus(): void;
48
- protected _render(options: RenderOptions): void;
51
+ protected _render(options: InputManagerRenderOptions): void;
49
52
  }
@@ -9,12 +9,19 @@ export declare class InteractiveInputHandler extends UserInputHandler {
9
9
  * Retrieve the button that users can click to send their input
10
10
  */
11
11
  private get sendButton();
12
+ /**
13
+ * Retrieve the HTMLInputElement for this InputHandler
14
+ */
15
+ private get inputArea();
12
16
  getInputMode(): InputMode;
13
17
  hasNext(): boolean;
14
18
  next(): string;
15
19
  waitWithPrompt(waiting: boolean, prompt?: string): void;
20
+ protected setPlaceholder(placeholder: string): void;
21
+ focus(): void;
16
22
  toggle(): void;
17
23
  onRunStart(): void;
18
24
  onRunEnd(): void;
19
25
  protected _render(options: RenderOptions): void;
26
+ protected reset(): void;
20
27
  }
@@ -1,19 +1,22 @@
1
- import { InputMode } from "../InputManager";
1
+ import { InputManagerRenderOptions, InputMode } from "../InputManager";
2
2
  import { Renderable } from "../util/Rendering";
3
3
  /**
4
4
  * Base class for components that handle input from the user
5
5
  */
6
- export declare abstract class UserInputHandler extends Renderable {
6
+ export declare abstract class UserInputHandler extends Renderable<InputManagerRenderOptions> {
7
7
  /**
8
8
  * Whether we are waiting for the user to input data
9
9
  */
10
10
  protected waiting: boolean;
11
- protected inputCallback: () => void;
11
+ /**
12
+ * Function to call when the user provided new input
13
+ */
14
+ protected inputCallback: (line: string) => void;
12
15
  /**
13
16
  * Construct a new UserInputHandler
14
17
  * @param {function()} inputCallback Callback for when the user has entered a value
15
18
  */
16
- constructor(inputCallback: () => void);
19
+ constructor(inputCallback: (line: string) => void);
17
20
  /**
18
21
  * Whether this handler has input ready
19
22
  */
@@ -44,18 +47,14 @@ export declare abstract class UserInputHandler extends Renderable {
44
47
  * @param {boolean} active Whether this component is active
45
48
  */
46
49
  abstract toggle(active: boolean): void;
47
- /**
48
- * Retrieve the HTMLInputElement for this InputHandler
49
- */
50
- get inputArea(): HTMLInputElement;
51
50
  /**
52
51
  * @param {string} placeholder The placeholder to show
53
52
  */
54
- protected setPlaceholder(placeholder: string): void;
53
+ protected abstract setPlaceholder(placeholder: string): void;
55
54
  /**
56
55
  * Focus the area in which the user enters input
57
56
  */
58
- focus(): void;
57
+ abstract focus(): void;
59
58
  /**
60
59
  * Wait for input of the user for a certain prompt
61
60
  * @param {boolean} waiting Whether we are waiting for input
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@dodona/papyros",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
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",