@dodona/papyros 0.1.61 → 0.1.91-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.
package/dist/Papyros.d.ts CHANGED
@@ -1,69 +1,142 @@
1
1
  import "./Papyros.css";
2
- import { Remote } from "comlink";
3
- import { Backend } from "./Backend";
4
- import { CodeEditor } from "./CodeEditor";
5
- import { InputManager, InputMode } from "./InputManager";
6
- import { PapyrosEvent } from "./PapyrosEvent";
2
+ import { InputMode } from "./InputManager";
7
3
  import { ProgrammingLanguage } from "./ProgrammingLanguage";
8
- import { RenderOptions } from "./util/Util";
9
- import { StatusPanel } from "./StatusPanel";
4
+ import { RenderOptions, ButtonOptions } from "./util/Util";
5
+ import { RunState, CodeRunner } from "./CodeRunner";
10
6
  import { OutputManager } from "./OutputManager";
11
- declare enum PapyrosState {
12
- Loading = "loading",
13
- Running = "running",
14
- AwaitingInput = "awaiting_input",
15
- Stopping = "stopping",
16
- Ready = "ready"
17
- }
18
- declare class PapyrosStateManager {
19
- state: PapyrosState;
20
- statusPanel: StatusPanel;
21
- get runButton(): HTMLButtonElement;
22
- get stopButton(): HTMLButtonElement;
23
- constructor(statusPanel: StatusPanel);
24
- setState(state: PapyrosState, message?: string): void;
25
- render(options: RenderOptions): HTMLElement;
26
- }
27
- interface PapyrosCodeState {
28
- programmingLanguage: ProgrammingLanguage;
29
- editor: CodeEditor;
30
- backend: Remote<Backend>;
31
- runId: number;
32
- }
7
+ /**
8
+ * Configuration options for this instance of Papyros
9
+ */
33
10
  interface PapyrosConfig {
11
+ /**
12
+ * Whether Papyros is run in standAlone mode or embedded in an application
13
+ */
34
14
  standAlone: boolean;
15
+ /**
16
+ * The programming language to use
17
+ */
35
18
  programmingLanguage: ProgrammingLanguage;
19
+ /**
20
+ * The language to use
21
+ */
36
22
  locale: string;
23
+ /**
24
+ * The InputMode to use
25
+ */
37
26
  inputMode: InputMode;
38
27
  }
28
+ /**
29
+ * Options for rendering Papyros
30
+ */
39
31
  interface PapyrosRenderOptions {
40
- papyros?: RenderOptions;
41
- code?: RenderOptions;
42
- panel?: RenderOptions;
43
- input?: RenderOptions;
44
- output?: RenderOptions;
32
+ /**
33
+ * Options to render Papyros itself, only used in standAlone mode
34
+ */
35
+ standAloneOptions?: RenderOptions;
36
+ /**
37
+ * RenderOptions for the code editor
38
+ */
39
+ codeEditorOptions?: RenderOptions;
40
+ /**
41
+ * RenderOptions for the status panel in the editor
42
+ */
43
+ statusPanelOptions?: RenderOptions;
44
+ /**
45
+ * RenderOptions for the input field
46
+ */
47
+ inputOptions?: RenderOptions;
48
+ /**
49
+ * RenderOptions for the output field
50
+ */
51
+ outputOptions?: RenderOptions;
45
52
  }
53
+ /**
54
+ * Class that manages multiple components to form a coding scratchpad
55
+ */
46
56
  export declare class Papyros {
47
- stateManager: PapyrosStateManager;
48
- codeState: PapyrosCodeState;
49
- inputManager: InputManager;
57
+ /**
58
+ * Config used to initialize Papyros
59
+ */
60
+ config: PapyrosConfig;
61
+ /**
62
+ * Component to run code entered by the user
63
+ */
64
+ codeRunner: CodeRunner;
65
+ /**
66
+ * Component to handle output generated by the user's code
67
+ */
50
68
  outputManager: OutputManager;
51
- constructor(programmingLanguage: ProgrammingLanguage, inputMode: InputMode);
52
- get state(): PapyrosState;
69
+ /**
70
+ * Whether this instance has been launched
71
+ */
72
+ private launched;
73
+ /**
74
+ * Construct a new Papyros instance
75
+ * @param {PapyrosConfig} config Properties to configure this instance
76
+ */
77
+ constructor(config: PapyrosConfig);
78
+ /**
79
+ * @return {RunState} The current state of the user's code
80
+ */
81
+ getState(): RunState;
82
+ /**
83
+ * Launch this instance of Papyros, making it ready to run code
84
+ * @return {Promise<Papyros>} Promise of launching, chainable
85
+ */
53
86
  launch(): Promise<Papyros>;
87
+ /**
88
+ * Set the used programming language to the given one to allow editing and running code
89
+ * @param {ProgrammingLanguage} programmingLanguage The language to use
90
+ */
54
91
  setProgrammingLanguage(programmingLanguage: ProgrammingLanguage): Promise<void>;
92
+ /**
93
+ * @param {string} code The code to use in the editor
94
+ */
55
95
  setCode(code: string): void;
96
+ /**
97
+ * @return {string} The currently written code
98
+ */
56
99
  getCode(): string;
57
- startBackend(): Promise<void>;
58
- static fromElement(config: PapyrosConfig, renderOptions: PapyrosRenderOptions): Papyros;
59
- configureInput(allowReload: boolean, serviceWorkerRoot?: string, serviceWorkerName?: string): Promise<boolean>;
60
- onError(e: PapyrosEvent): void;
61
- onInput(e: PapyrosEvent): Promise<void>;
62
- onMessage(e: PapyrosEvent): void;
63
- runCode(): Promise<void>;
64
- stop(): Promise<void>;
65
- render(standAlone: boolean, programmingLanguage: ProgrammingLanguage, locale: string, renderOptions: PapyrosRenderOptions): void;
100
+ /**
101
+ * Helper method to perform the service worker related checks and initialisation
102
+ * @param {string} serviceWorkerRoot URL for the directory where the service worker lives
103
+ * @param {string} serviceWorkerName The name of the file containing the script
104
+ * @return {Promise<boolean>} Whether registration was successful
105
+ */
106
+ private registerServiceWorker;
107
+ /**
108
+ * Configure how user input is handled within Papyros
109
+ * By default, we will try to use SharedArrayBuffers
110
+ * If this option is not available, the optional arguments become relevant
111
+ * They are needed to register a service worker to handle communication between threads
112
+ * @param {string} serviceWorkerRoot URL for the directory where the service worker lives
113
+ * @param {string} serviceWorkerName The name of the file containing the script
114
+ * @param {boolean} allowReload Whether we are allowed to force a reload of the page
115
+ * This allows using SharedArrayBuffers without configuring the HTTP headers yourself
116
+ * @return {Promise<boolean>} Promise of configuring input
117
+ */
118
+ configureInput(serviceWorkerRoot?: string, serviceWorkerName?: string, allowReload?: boolean): Promise<boolean>;
119
+ /**
120
+ * Render Papyros with the given options
121
+ * @param {PapyrosRenderOptions} renderOptions Options to use
122
+ */
123
+ render(renderOptions: PapyrosRenderOptions): void;
124
+ /**
125
+ * Add a button to the status panel within Papyros
126
+ * @param {ButtonOptions} options Options to render the button with
127
+ * @param {function} onClick Listener for click events on the button
128
+ */
129
+ addButton(options: ButtonOptions, onClick: () => void): void;
130
+ /**
131
+ * @param {ProgrammingLanguage} language The language to check
132
+ * @return {boolean} Whether Papyros supports this language by default
133
+ */
66
134
  static supportsProgrammingLanguage(language: string): boolean;
135
+ /**
136
+ * Convert a string to a ProgrammingLanguage
137
+ * @param {string} language The language to convert
138
+ * @return {ProgrammingLanguage | undefined} The ProgrammingLanguage, or undefined if not supported
139
+ */
67
140
  static toProgrammingLanguage(language: string): ProgrammingLanguage | undefined;
68
141
  }
69
142
  export {};
@@ -1,3 +1,6 @@
1
+ /**
2
+ * String enum representing programming languages supported by Papyros
3
+ */
1
4
  export declare enum ProgrammingLanguage {
2
5
  Python = "Python",
3
6
  JavaScript = "JavaScript"
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Interface for components that maintain state based on runs of code
3
+ */
4
+ export interface RunListener {
5
+ /**
6
+ * Inform this listener that a new run started
7
+ */
8
+ onRunStart(): void;
9
+ /**
10
+ * Inform this listener that the run ended
11
+ */
12
+ onRunEnd(): void;
13
+ }
@@ -8,4 +8,5 @@ export declare const PYTHON_EXAMPLES: {
8
8
  Unicode: string;
9
9
  Files: string;
10
10
  Matplotlib: string;
11
+ Sleep: string;
11
12
  };