@dodona/papyros 0.3.8 → 0.4.2
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/LICENSE +0 -0
- package/README.md +0 -0
- package/dist/App.d.ts +0 -0
- package/dist/Backend.d.ts +12 -1
- package/dist/BackendEvent.d.ts +0 -0
- package/dist/BackendEventQueue.d.ts +0 -0
- package/dist/BackendManager.d.ts +0 -0
- package/dist/CodeRunner.d.ts +9 -5
- package/dist/Constants.d.ts +2 -0
- package/dist/InputManager.d.ts +12 -5
- package/dist/InputServiceWorker.d.ts +0 -0
- package/dist/Library.d.ts +1 -1
- package/dist/Library.js +1 -1
- package/dist/OutputManager.d.ts +0 -0
- package/dist/Papyros.d.ts +2 -2
- package/dist/ProgrammingLanguage.d.ts +0 -0
- package/dist/editor/BatchInputEditor.d.ts +27 -0
- package/dist/{CodeEditor.d.ts → editor/CodeEditor.d.ts} +10 -41
- package/dist/editor/CodeMirrorEditor.d.ts +132 -0
- package/dist/editor/Gutters.d.ts +94 -0
- package/dist/examples/Examples.d.ts +0 -0
- package/dist/examples/JavaScriptExamples.d.ts +0 -0
- package/dist/examples/PythonExamples.d.ts +0 -0
- package/dist/input/BatchInputHandler.d.ts +20 -3
- package/dist/input/InteractiveInputHandler.d.ts +7 -0
- package/dist/input/UserInputHandler.d.ts +11 -4
- package/dist/util/HTMLShapes.d.ts +0 -0
- package/dist/util/Logging.d.ts +0 -0
- package/dist/util/Rendering.d.ts +0 -0
- package/dist/util/Util.d.ts +6 -0
- package/dist/workers/input/InputWorker.d.ts +0 -0
- package/dist/workers/input/InputWorker.js +1 -1
- package/dist/workers/javascript/JavaScriptWorker.worker.d.ts +0 -0
- package/dist/workers/python/PythonWorker.worker.d.ts +0 -0
- package/package.json +3 -3
package/dist/OutputManager.d.ts
CHANGED
|
File without changes
|
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?:
|
|
57
|
+
inputOptions?: InputManagerRenderOptions;
|
|
58
58
|
/**
|
|
59
59
|
* RenderOptions for the output field
|
|
60
60
|
*/
|
|
File without changes
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CodeMirrorEditor } from "./CodeMirrorEditor";
|
|
2
|
+
import { UsedInputGutterInfo } from "./Gutters";
|
|
3
|
+
/**
|
|
4
|
+
* Editor to handle and highlight user input
|
|
5
|
+
*/
|
|
6
|
+
export declare class BatchInputEditor extends CodeMirrorEditor {
|
|
7
|
+
/**
|
|
8
|
+
* Style classes used to highlight lines
|
|
9
|
+
*/
|
|
10
|
+
private static HIGHLIGHT_CLASSES;
|
|
11
|
+
/**
|
|
12
|
+
* Gutters to show which lines were used
|
|
13
|
+
*/
|
|
14
|
+
private usedInputGutters;
|
|
15
|
+
constructor();
|
|
16
|
+
/**
|
|
17
|
+
* 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)
|
|
20
|
+
*/
|
|
21
|
+
highlight(getInfo: (lineNr: number) => UsedInputGutterInfo): void;
|
|
22
|
+
/**
|
|
23
|
+
* @return {Array<string>} Array of valid user input
|
|
24
|
+
* Data in the last line that is not terminated by a newline is omitted
|
|
25
|
+
*/
|
|
26
|
+
getLines(): Array<string>;
|
|
27
|
+
}
|
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
import { ProgrammingLanguage } from "
|
|
2
|
-
import { Renderable, RenderOptions } from "./util/Rendering";
|
|
1
|
+
import { ProgrammingLanguage } from "../ProgrammingLanguage";
|
|
3
2
|
import { CompletionSource } from "@codemirror/autocomplete";
|
|
4
3
|
import { EditorView } from "@codemirror/view";
|
|
5
4
|
import { Diagnostic } from "@codemirror/lint";
|
|
5
|
+
import { CodeMirrorEditor } from "./CodeMirrorEditor";
|
|
6
6
|
/**
|
|
7
7
|
* Component that provides useful features to users writing code
|
|
8
8
|
*/
|
|
9
|
-
export declare class CodeEditor extends
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
* Mapping from CodeEditorOptions to a configurable compartment
|
|
16
|
-
*/
|
|
17
|
-
private compartments;
|
|
9
|
+
export declare class CodeEditor extends CodeMirrorEditor {
|
|
10
|
+
static PROGRAMMING_LANGUAGE: string;
|
|
11
|
+
static INDENTATION: string;
|
|
12
|
+
static PANEL: string;
|
|
13
|
+
static AUTOCOMPLETION: string;
|
|
14
|
+
static LINTING: string;
|
|
18
15
|
/**
|
|
19
16
|
* Construct a new CodeEditor
|
|
20
17
|
* @param {Function} onRunRequest Callback for when the user wants to run the code
|
|
@@ -22,20 +19,7 @@ export declare class CodeEditor extends Renderable {
|
|
|
22
19
|
* @param {number} indentLength The length in spaces for the indent unit
|
|
23
20
|
*/
|
|
24
21
|
constructor(onRunRequest: () => void, initialCode?: string, indentLength?: number);
|
|
25
|
-
|
|
26
|
-
* Helper method to dispatch configuration changes at runtime
|
|
27
|
-
* @param {Array<[Option, Extension]>} items Array of items to reconfigure
|
|
28
|
-
* The option indicates the relevant compartment
|
|
29
|
-
* The extension indicates the new configuration
|
|
30
|
-
*/
|
|
31
|
-
private reconfigure;
|
|
32
|
-
/**
|
|
33
|
-
* Render the editor with the given options and panel
|
|
34
|
-
* @param {RenderOptions} options Options for rendering
|
|
35
|
-
* @param {HTMLElement} panel The panel to display at the bottom
|
|
36
|
-
* @return {HTMLElement} The rendered element
|
|
37
|
-
*/
|
|
38
|
-
protected _render(options: RenderOptions): void;
|
|
22
|
+
setDarkMode(darkMode: boolean): void;
|
|
39
23
|
/**
|
|
40
24
|
* @param {ProgrammingLanguage} language The language to use
|
|
41
25
|
*/
|
|
@@ -52,26 +36,10 @@ export declare class CodeEditor extends Renderable {
|
|
|
52
36
|
* @param {number} indentLength The number of spaces to use for indentation
|
|
53
37
|
*/
|
|
54
38
|
setIndentLength(indentLength: number): void;
|
|
55
|
-
/**
|
|
56
|
-
* @param {Function} onChange Listener that performs actions on the new contents
|
|
57
|
-
*/
|
|
58
|
-
onChange(onChange: ((newContent: string) => void)): void;
|
|
59
39
|
/**
|
|
60
40
|
* @param {HTMLElement} panel The panel to display at the bottom of the editor
|
|
61
41
|
*/
|
|
62
42
|
setPanel(panel: HTMLElement): void;
|
|
63
|
-
/**
|
|
64
|
-
* @return {string} The code within the editor
|
|
65
|
-
*/
|
|
66
|
-
getCode(): string;
|
|
67
|
-
/**
|
|
68
|
-
* @param {string} code The new code to be shown in the editor
|
|
69
|
-
*/
|
|
70
|
-
setCode(code: string): void;
|
|
71
|
-
/**
|
|
72
|
-
* Put focus on the CodeEditor
|
|
73
|
-
*/
|
|
74
|
-
focus(): void;
|
|
75
43
|
/**
|
|
76
44
|
* @param {number} indentLength The amount of spaces to use
|
|
77
45
|
* @return {string} The indentation unit to be used by CodeMirror
|
|
@@ -97,6 +65,7 @@ export declare class CodeEditor extends Renderable {
|
|
|
97
65
|
* - active line highlighting
|
|
98
66
|
* - active line gutter highlighting
|
|
99
67
|
* - selection match highlighting
|
|
68
|
+
* - gutter for linting
|
|
100
69
|
* Keymaps:
|
|
101
70
|
* - the default command bindings
|
|
102
71
|
* - bracket closing
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Compartment, Extension } from "@codemirror/state";
|
|
3
|
+
import { EditorView } from "@codemirror/view";
|
|
4
|
+
import { Renderable, RenderOptions } from "../util/Rendering";
|
|
5
|
+
import { StyleSpec } from "style-mod";
|
|
6
|
+
/**
|
|
7
|
+
* Data structure containing common elements for styling
|
|
8
|
+
*/
|
|
9
|
+
export interface EditorStyling {
|
|
10
|
+
/**
|
|
11
|
+
* Array of HTML classes to apply to this editor
|
|
12
|
+
*/
|
|
13
|
+
classes: Array<string>;
|
|
14
|
+
/**
|
|
15
|
+
* The maximum height of the editor
|
|
16
|
+
*/
|
|
17
|
+
maxHeight: string;
|
|
18
|
+
/**
|
|
19
|
+
* The minimum height of the editor
|
|
20
|
+
*/
|
|
21
|
+
minHeight: string;
|
|
22
|
+
/**
|
|
23
|
+
* Extra theme options to be passed to EditorView.theme
|
|
24
|
+
*/
|
|
25
|
+
theme?: {
|
|
26
|
+
[selectorSpec: string]: StyleSpec;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Interface for listeners to textual changes in the editor
|
|
31
|
+
*/
|
|
32
|
+
export interface DocChangeListener {
|
|
33
|
+
/**
|
|
34
|
+
* Method to call with the new document value
|
|
35
|
+
*/
|
|
36
|
+
onChange: (code: string) => void;
|
|
37
|
+
/**
|
|
38
|
+
* How many milliseconds should pass since the last change
|
|
39
|
+
* before notifying (in case computations are expensive)
|
|
40
|
+
*/
|
|
41
|
+
delay?: number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Interface for storing data related to delayed function calls
|
|
45
|
+
*/
|
|
46
|
+
interface TimeoutData {
|
|
47
|
+
/**
|
|
48
|
+
* The time in ms at which the last call occurred
|
|
49
|
+
*/
|
|
50
|
+
lastCalled: number;
|
|
51
|
+
/**
|
|
52
|
+
* The timeout identifier associated with the delayed call
|
|
53
|
+
* null if not currently scheduled
|
|
54
|
+
*/
|
|
55
|
+
timeout: NodeJS.Timeout | null;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Base class for Editors implemented using CodeMirror 6
|
|
59
|
+
* https://codemirror.net/6/
|
|
60
|
+
*/
|
|
61
|
+
export declare abstract class CodeMirrorEditor extends Renderable {
|
|
62
|
+
static STYLE: string;
|
|
63
|
+
static PLACEHOLDER: string;
|
|
64
|
+
static THEME: string;
|
|
65
|
+
/**
|
|
66
|
+
* CodeMirror EditorView representing the internal editor
|
|
67
|
+
*/
|
|
68
|
+
readonly editorView: EditorView;
|
|
69
|
+
/**
|
|
70
|
+
* Mapping of strings to Compartments associated with that property
|
|
71
|
+
*/
|
|
72
|
+
protected compartments: Map<string, Compartment>;
|
|
73
|
+
/**
|
|
74
|
+
* Data to style this Editor
|
|
75
|
+
*/
|
|
76
|
+
protected styling: EditorStyling;
|
|
77
|
+
/**
|
|
78
|
+
* Mapping for each change listener to its timeout identifier and last call time
|
|
79
|
+
*/
|
|
80
|
+
protected listenerTimeouts: Map<DocChangeListener, TimeoutData>;
|
|
81
|
+
/**
|
|
82
|
+
* @param {Set<string>} compartments Identifiers for configurable extensions
|
|
83
|
+
* @param {EditorStyling} styling Data to style this editor
|
|
84
|
+
*/
|
|
85
|
+
constructor(compartments: Set<string>, styling: EditorStyling);
|
|
86
|
+
/**
|
|
87
|
+
* @param {Extension} extension The extension to add to the Editor
|
|
88
|
+
*/
|
|
89
|
+
protected addExtension(extension: Extension): void;
|
|
90
|
+
/**
|
|
91
|
+
* @return {string} The text within the editor
|
|
92
|
+
*/
|
|
93
|
+
getText(): string;
|
|
94
|
+
/**
|
|
95
|
+
* @param {string} text The new value to be shown in the editor
|
|
96
|
+
*/
|
|
97
|
+
setText(text: string): void;
|
|
98
|
+
/**
|
|
99
|
+
* Helper method to dispatch configuration changes at runtime
|
|
100
|
+
* @param {Array<[Option, Extension]>} items Array of items to reconfigure
|
|
101
|
+
* The option indicates the relevant compartment
|
|
102
|
+
* The extension indicates the new configuration
|
|
103
|
+
*/
|
|
104
|
+
reconfigure(...items: Array<[string, Extension]>): void;
|
|
105
|
+
/**
|
|
106
|
+
* Apply focus to the Editor
|
|
107
|
+
*/
|
|
108
|
+
focus(): void;
|
|
109
|
+
/**
|
|
110
|
+
* @param {string} placeholderValue The contents of the placeholder
|
|
111
|
+
*/
|
|
112
|
+
setPlaceholder(placeholderValue: string): void;
|
|
113
|
+
/**
|
|
114
|
+
* @param {boolean} darkMode Whether to use dark mode
|
|
115
|
+
*/
|
|
116
|
+
setDarkMode(darkMode: boolean): void;
|
|
117
|
+
/**
|
|
118
|
+
* Override the style used by this Editor
|
|
119
|
+
* @param {Partial<EditorStyling>} styling Object with keys of EditorStyling to override styles
|
|
120
|
+
*/
|
|
121
|
+
setStyling(styling: Partial<EditorStyling>): void;
|
|
122
|
+
protected _render(options: RenderOptions): void;
|
|
123
|
+
/**
|
|
124
|
+
* Process the changes by informing the listeners of the new contents
|
|
125
|
+
*/
|
|
126
|
+
private handleChange;
|
|
127
|
+
/**
|
|
128
|
+
* @param {DocChangeListener} changeListener Listener that performs actions on the new contents
|
|
129
|
+
*/
|
|
130
|
+
onChange(changeListener: DocChangeListener): void;
|
|
131
|
+
}
|
|
132
|
+
export {};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { StateEffectType, StateField } from "@codemirror/state";
|
|
2
|
+
import { Extension } from "@codemirror/state";
|
|
3
|
+
import { GutterMarker } from "@codemirror/view";
|
|
4
|
+
import { EditorView } from "@codemirror/view";
|
|
5
|
+
/**
|
|
6
|
+
* Data used in Gutter elements
|
|
7
|
+
*/
|
|
8
|
+
export interface GutterInfo {
|
|
9
|
+
/**
|
|
10
|
+
* The number of the line (1-based)
|
|
11
|
+
*/
|
|
12
|
+
lineNr: number;
|
|
13
|
+
/**
|
|
14
|
+
* Whether the Gutter element should be shown
|
|
15
|
+
*/
|
|
16
|
+
on: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Configuration for Gutters
|
|
20
|
+
*/
|
|
21
|
+
export interface IGutterConfig<Info extends GutterInfo> {
|
|
22
|
+
/**
|
|
23
|
+
* Name of this Gutter
|
|
24
|
+
*/
|
|
25
|
+
name: string;
|
|
26
|
+
/**
|
|
27
|
+
* Handler for when a Gutter element is clicked
|
|
28
|
+
*/
|
|
29
|
+
onClick?: (view: EditorView, info: Info) => void;
|
|
30
|
+
/**
|
|
31
|
+
* Extra extensions to use for the Gutters
|
|
32
|
+
*/
|
|
33
|
+
extraExtensions?: Extension;
|
|
34
|
+
}
|
|
35
|
+
export declare abstract class Gutters<Info extends GutterInfo = GutterInfo, Config extends IGutterConfig<Info> = IGutterConfig<Info>> {
|
|
36
|
+
/**
|
|
37
|
+
* Config used to initialize the Gutters
|
|
38
|
+
*/
|
|
39
|
+
protected config: Config;
|
|
40
|
+
/**
|
|
41
|
+
* Effect to signal changes in the Gutters
|
|
42
|
+
*/
|
|
43
|
+
protected effect: StateEffectType<Info>;
|
|
44
|
+
/**
|
|
45
|
+
* Current state of the Gutters
|
|
46
|
+
* Consists of a mapping for line numbers to Info objects
|
|
47
|
+
*/
|
|
48
|
+
protected state: StateField<Map<number, Info>>;
|
|
49
|
+
constructor(config: Config);
|
|
50
|
+
/**
|
|
51
|
+
* Render a marker with the given info
|
|
52
|
+
* @param {Info} info Info used to render the marker
|
|
53
|
+
* Will only be called when info.on is True
|
|
54
|
+
*/
|
|
55
|
+
protected abstract marker(info: Info): GutterMarker;
|
|
56
|
+
/**
|
|
57
|
+
* Set a marker with the given info
|
|
58
|
+
* @param {EditorView} view View in which the Gutters live
|
|
59
|
+
* @param {Info} info Info used to render the marker
|
|
60
|
+
*/
|
|
61
|
+
setMarker(view: EditorView, info: Info): void;
|
|
62
|
+
/**
|
|
63
|
+
* @return {Extension} The Gutters as a CodeMirror Extension
|
|
64
|
+
*/
|
|
65
|
+
toExtension(): Extension;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Gutters to show and allow toggling of breakpoints
|
|
69
|
+
*/
|
|
70
|
+
export declare class BreakpointsGutter extends Gutters {
|
|
71
|
+
constructor();
|
|
72
|
+
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
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Extra data used to represent input gutters
|
|
81
|
+
*/
|
|
82
|
+
export interface UsedInputGutterInfo extends GutterInfo {
|
|
83
|
+
/**
|
|
84
|
+
* Text value to display when hovering over the Gutter element
|
|
85
|
+
*/
|
|
86
|
+
title: string;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Gutters to show a checkmark for used input
|
|
90
|
+
*/
|
|
91
|
+
export declare class UsedInputGutters extends Gutters<UsedInputGutterInfo> {
|
|
92
|
+
constructor();
|
|
93
|
+
protected marker(info: UsedInputGutterInfo): GutterMarker;
|
|
94
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
import { InputMode } from "../InputManager";
|
|
1
|
+
import { InputManagerRenderOptions, InputMode } from "../InputManager";
|
|
2
2
|
import { UserInputHandler } from "./UserInputHandler";
|
|
3
|
-
import {
|
|
3
|
+
import { BatchInputEditor } from "../editor/BatchInputEditor";
|
|
4
4
|
export declare class BatchInputHandler extends UserInputHandler {
|
|
5
5
|
/**
|
|
6
6
|
* The index of the next line in lines to send
|
|
7
7
|
*/
|
|
8
8
|
private lineNr;
|
|
9
|
+
/**
|
|
10
|
+
* Messages used when asking for user input
|
|
11
|
+
*/
|
|
12
|
+
private prompts;
|
|
13
|
+
/**
|
|
14
|
+
* Editor containing the input of the user
|
|
15
|
+
*/
|
|
16
|
+
readonly batchEditor: BatchInputEditor;
|
|
9
17
|
/**
|
|
10
18
|
* The previous input of the user
|
|
11
19
|
* Is restored upon switching back to InputMode.Batch
|
|
@@ -16,6 +24,11 @@ export declare class BatchInputHandler extends UserInputHandler {
|
|
|
16
24
|
* @param {function()} inputCallback Callback for when the user has entered a value
|
|
17
25
|
*/
|
|
18
26
|
constructor(inputCallback: () => void);
|
|
27
|
+
/**
|
|
28
|
+
* Handle new input, potentially sending it to the awaiting receiver
|
|
29
|
+
* @param {string} newInput The new user input
|
|
30
|
+
*/
|
|
31
|
+
private handleInputChanged;
|
|
19
32
|
toggle(active: boolean): void;
|
|
20
33
|
getInputMode(): InputMode;
|
|
21
34
|
/**
|
|
@@ -24,8 +37,12 @@ export declare class BatchInputHandler extends UserInputHandler {
|
|
|
24
37
|
*/
|
|
25
38
|
protected get lines(): Array<string>;
|
|
26
39
|
hasNext(): boolean;
|
|
40
|
+
private highlight;
|
|
27
41
|
next(): string;
|
|
28
42
|
onRunStart(): void;
|
|
29
43
|
onRunEnd(): void;
|
|
30
|
-
|
|
44
|
+
waitWithPrompt(waiting: boolean, prompt?: string): void;
|
|
45
|
+
protected setPlaceholder(placeholderValue: string): void;
|
|
46
|
+
focus(): void;
|
|
47
|
+
protected _render(options: InputManagerRenderOptions): void;
|
|
31
48
|
}
|
|
@@ -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,13 +1,16 @@
|
|
|
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
|
+
/**
|
|
12
|
+
* Function to call when the user provided new input
|
|
13
|
+
*/
|
|
11
14
|
protected inputCallback: () => void;
|
|
12
15
|
/**
|
|
13
16
|
* Construct a new UserInputHandler
|
|
@@ -45,9 +48,13 @@ export declare abstract class UserInputHandler extends Renderable {
|
|
|
45
48
|
*/
|
|
46
49
|
abstract toggle(active: boolean): void;
|
|
47
50
|
/**
|
|
48
|
-
*
|
|
51
|
+
* @param {string} placeholder The placeholder to show
|
|
52
|
+
*/
|
|
53
|
+
protected abstract setPlaceholder(placeholder: string): void;
|
|
54
|
+
/**
|
|
55
|
+
* Focus the area in which the user enters input
|
|
49
56
|
*/
|
|
50
|
-
|
|
57
|
+
abstract focus(): void;
|
|
51
58
|
/**
|
|
52
59
|
* Wait for input of the user for a certain prompt
|
|
53
60
|
* @param {boolean} waiting Whether we are waiting for input
|
|
File without changes
|
package/dist/util/Logging.d.ts
CHANGED
|
File without changes
|
package/dist/util/Rendering.d.ts
CHANGED
|
File without changes
|
package/dist/util/Util.d.ts
CHANGED
|
@@ -45,4 +45,10 @@ export declare function downloadResults(data: string, filename: string): void;
|
|
|
45
45
|
* @return {string} The current url
|
|
46
46
|
*/
|
|
47
47
|
export declare function cleanCurrentUrl(endingSlash?: boolean): string;
|
|
48
|
+
/**
|
|
49
|
+
* Focus an element, setting the user's caret at the end of the contents
|
|
50
|
+
* Needed to ensure focusing a contenteditable element works as expected
|
|
51
|
+
* @param {HTMLElement} el The element to focus
|
|
52
|
+
*/
|
|
53
|
+
export declare function placeCaretAtEnd(el: HTMLElement): void;
|
|
48
54
|
export {};
|
|
File without changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Papyros=t():e.Papyros=t()}(self,(()=>(()=>{var e={137:e=>{self,e.exports=(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{isServiceWorkerRequest:()=>s,serviceWorkerFetchListener:()=>i,asyncSleep:()=>u,ServiceWorkerError:()=>
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Papyros=t():e.Papyros=t()}(self,(()=>(()=>{var e={137:e=>{self,e.exports=(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{isServiceWorkerRequest:()=>s,serviceWorkerFetchListener:()=>i,asyncSleep:()=>u,ServiceWorkerError:()=>c,writeMessageAtomics:()=>a,writeMessageServiceWorker:()=>f,writeMessage:()=>d,makeChannel:()=>l,makeAtomicsChannel:()=>y,makeServiceWorkerChannel:()=>p,readMessage:()=>h,syncSleep:()=>v,uuidv4:()=>g});var r=function(e,t,r,n){return new(r||(r=Promise))((function(o,s){function i(e){try{c(n.next(e))}catch(e){s(e)}}function u(e){try{c(n.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,u)}c((n=n.apply(e,t||[])).next())}))};const n="__SyncMessageServiceWorkerInput__",o="__sync-message-v2__";function s(e){return"string"!=typeof e&&(e=e.request.url),e.includes(n)}function i(){const e={},t={};return n=>{const{url:i}=n.request;return!!s(i)&&(n.respondWith(function(){return r(this,void 0,void 0,(function*(){function r(e){const t={message:e,version:o};return new Response(JSON.stringify(t),{status:200})}if(i.endsWith("/read")){const{messageId:o,timeout:s}=yield n.request.json(),i=e[o];return i?(delete e[o],r(i)):yield new Promise((e=>{t[o]=e,setTimeout((function(){delete t[o],e(new Response("",{status:408}))}),s)}))}if(i.endsWith("/write")){const{message:o,messageId:s}=yield n.request.json(),i=t[s];return i?(i(r(o)),delete t[s]):e[s]=o,r({early:!i})}if(i.endsWith("/version"))return new Response(o,{status:200})}))}()),!0)}}function u(e){return new Promise((t=>setTimeout(t,e)))}class c extends Error{constructor(e,t){super(`Received status ${t} from ${e}. Ensure the service worker is registered and active.`),this.url=e,this.status=t,this.type="ServiceWorkerError",Object.setPrototypeOf(this,c.prototype)}}function a(e,t){const r=(new TextEncoder).encode(JSON.stringify(t)),{data:n,meta:o}=e;if(r.length>n.length)throw new Error("Message is too big, increase bufferSize when making channel.");n.set(r,0),Atomics.store(o,0,r.length),Atomics.store(o,1,1),Atomics.notify(o,1)}function f(e,t,n){return r(this,void 0,void 0,(function*(){yield navigator.serviceWorker.ready;const r=e.baseUrl+"/write",s=Date.now();for(;;){const i={message:t,messageId:n},a=yield fetch(r,{method:"POST",body:JSON.stringify(i)});if(200===a.status&&(yield a.json()).version===o)return;if(!(Date.now()-s<e.timeout))throw new c(r,a.status);yield u(100)}}))}function d(e,t,n){return r(this,void 0,void 0,(function*(){"atomics"===e.type?a(e,t):yield f(e,t,n)}))}function l(e={}){return"undefined"!=typeof SharedArrayBuffer?y(e.atomics):"serviceWorker"in navigator?p(e.serviceWorker):null}function y({bufferSize:e}={}){return{type:"atomics",data:new Uint8Array(new SharedArrayBuffer(e||131072)),meta:new Int32Array(new SharedArrayBuffer(2*Int32Array.BYTES_PER_ELEMENT))}}function p(e={}){return{type:"serviceWorker",baseUrl:(e.scope||"/")+n,timeout:e.timeout||5e3}}function m(e,t){return e>0?+e:t}function h(e,t,{checkInterrupt:r,checkTimeout:n,timeout:s}={}){const i=performance.now();n=m(n,r?100:5e3);const u=m(s,Number.POSITIVE_INFINITY);let a;if("atomics"===e.type){const{data:t,meta:r}=e;a=()=>{if("timed-out"===Atomics.wait(r,1,0,n))return null;{const e=Atomics.exchange(r,0,0),n=t.slice(0,e);Atomics.store(r,1,0);const o=(new TextDecoder).decode(n);return JSON.parse(o)}}}else a=()=>{const r=new XMLHttpRequest,s=e.baseUrl+"/read";r.open("POST",s,!1);const u={messageId:t,timeout:n};r.send(JSON.stringify(u));const{status:a}=r;if(408===a)return null;if(200===a){const e=JSON.parse(r.responseText);return e.version!==o?null:e.message}if(performance.now()-i<e.timeout)return null;throw new c(s,a)};for(;;){const e=u-(performance.now()-i);if(e<=0)return null;n=Math.min(n,e);const t=a();if(null!==t)return t;if(null==r?void 0:r())return null}}function v(e,t){if(e=m(e,0))if("undefined"!=typeof SharedArrayBuffer){const t=new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT));t[0]=0,Atomics.wait(t,0,0,e)}else h(t,`sleep ${e} ${g()}`,{timeout:e})}let g;return g="randomUUID"in crypto?function(){return crypto.randomUUID()}:function(){return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,(e=>{const t=Number(e);return(t^crypto.getRandomValues(new Uint8Array(1))[0]&15>>t/4).toString(16)}))},t})()}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var s=t[n]={exports:{}};return e[n](s,s.exports,r),s.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return(()=>{"use strict";r.r(n),r.d(n,{InputWorker:()=>o});var e=r(137),t=function(e,t,r,n){return new(r||(r=Promise))((function(o,s){function i(e){try{c(n.next(e))}catch(e){s(e)}}function u(e){try{c(n.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,u)}c((n=n.apply(e,t||[])).next())}))};class o{constructor(t=""){this.hostName=t,this.syncMessageListener=(0,e.serviceWorkerFetchListener)()}handleInputRequest(e){return t(this,void 0,void 0,(function*(){if(this.syncMessageListener(e))return!0;const t=e.request.url;return!(!this.hostName||!t.includes(this.hostName))&&(e.respondWith(fetch(e.request).then((e=>{const t=new Headers(e.headers);t.set("Cross-Origin-Embedder-Policy","require-corp"),t.set("Cross-Origin-Opener-Policy","same-origin"),t.set("Cross-Origin-Resource-Policy","cross-origin");return new Response(e.body,{status:e.status||200,statusText:e.statusText,headers:t})}))),!0)}))}}})(),n})()));
|
|
File without changes
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dodona/papyros",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"homepage": ".",
|
|
6
6
|
"devDependencies": {
|
|
7
7
|
"@types/escape-html": "^1.0.1",
|
|
8
8
|
"@types/i18n-js": "^3.8.2",
|
|
9
9
|
"@types/jest": "27.4.1",
|
|
10
|
-
"@types/serviceworker": "^0.0.
|
|
10
|
+
"@types/serviceworker": "^0.0.46",
|
|
11
11
|
"@typescript-eslint/eslint-plugin": "^5.21.0",
|
|
12
12
|
"@typescript-eslint/parser": "^5.21.0",
|
|
13
13
|
"autoprefixer": "^10.4.0",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"jest": "27.0.0",
|
|
20
20
|
"postcss": "^8.3.11",
|
|
21
21
|
"postcss-import": "^14.0.2",
|
|
22
|
-
"postcss-loader": "^
|
|
22
|
+
"postcss-loader": "^7.0.0",
|
|
23
23
|
"style-loader": "^3.3.1",
|
|
24
24
|
"tailwindcss": "^3.0.24",
|
|
25
25
|
"terser-webpack-plugin": "^5.3.1",
|