License: MIT | Version: 3.0.3
The Code Widget enables interactive code exercises directly in the browser. Users can effortlessly write, execute, and explore code in multiple programming languages, including:
- JavaScript or TypeScript
- HTML
- Python (powered by Pyodide)
- Java (powered by TeaVM)
- WebAssembly Text Format (WAT)
- Intuitive Editor: Based on CodeMirror, offering syntax highlighting and optional autocompletion for a smoother coding experience.
- Line Locking: Allows instructors to lock specific lines, creating read-only templates to guide students effectively.
- Rich Output Display: Outputs appear neatly below each code cell, with JavaScript execution featuring a fully interactive console inspector.
- 100% Client-Side Execution: Everything executes locally within the browser, ensuring complete offline capability and no reliance on servers.
To set up the development environment, clone the repository and execute the following commands:
npm install
npm run dev # runs @webwriter/build devFinally, import the code directory into WebWriter to begin.
Snippets are examples and templates using the package's widgets.
| Name | Import Path |
|---|---|
| HTML | @webwriter/code/snippets/HTML.html |
Code widget for HTML with live preview functionality.
Use with a CDN (e.g. jsdelivr):
<link href="https://cdn.jsdelivr.net/npm/@webwriter/code/widgets/webwriter-code-html.css" rel="stylesheet">
<script type="module" src="https://cdn.jsdelivr.net/npm/@webwriter/code/widgets/webwriter-code-html.js"></script>
<webwriter-code-html></webwriter-code-html>Or use with a bundler (e.g. Vite):
npm install @webwriter/code
<link href="@webwriter/code/widgets/webwriter-code-html.css" rel="stylesheet">
<script type="module" src="@webwriter/code/widgets/webwriter-code-html.js"></script>
<webwriter-code-html></webwriter-code-html>| Name (Attribute Name) | Type | Description | Default | Reflects |
|---|---|---|---|---|
code (code) |
String |
The source code content displayed in the editor. | - | ✓ |
visible (visible) |
boolean |
Whether the code editor is visible to the user. | true |
✓ |
autoRun (autoRun) |
boolean |
Whether to automatically run the code when the component is first loaded. | false |
✓ |
runnable (runnable) |
boolean |
Whether the code execution is allowed and the run button is enabled. | true |
✓ |
autocomplete (autocomplete) |
boolean |
Whether autocompletion is enabled in the code editor. | false |
✓ |
lockedLines (lockedLines) |
number[] |
Array of line numbers that should be locked from editing. | [] |
✓ |
showExecutionTime (showExecutionTime) |
boolean |
Whether to display the execution time in the controls. | false |
✓ |
executionTime (executionTime) |
number |
The execution time in milliseconds of the last code run. | 0 |
✓ |
showExecutionCount (showExecutionCount) |
boolean |
Whether to display the execution count in the run button. | false |
✓ |
executionCount (executionCount) |
number |
The number of times the code has been executed. | 0 |
✓ |
results (results) |
any |
The results from the last code execution. | [] |
✓ |
diagnostics (diagnostics) |
Diagnostic[] |
Compilation or runtime errors from the last code execution. | [] |
✓ |
Fields including properties and attributes define the current state of the widget and offer customization options.
| Name | Value |
|---|
The editing config defines how explorable authoring tools such as WebWriter treat the widget.
No public methods, slots, events, custom CSS properties, or CSS parts.
Code widget for JavaScript with execution capabilities.
Use with a CDN (e.g. jsdelivr):
<link href="https://cdn.jsdelivr.net/npm/@webwriter/code/widgets/webwriter-code-javascript.css" rel="stylesheet">
<script type="module" src="https://cdn.jsdelivr.net/npm/@webwriter/code/widgets/webwriter-code-javascript.js"></script>
<webwriter-code-javascript></webwriter-code-javascript>Or use with a bundler (e.g. Vite):
npm install @webwriter/code
<link href="@webwriter/code/widgets/webwriter-code-javascript.css" rel="stylesheet">
<script type="module" src="@webwriter/code/widgets/webwriter-code-javascript.js"></script>
<webwriter-code-javascript></webwriter-code-javascript>| Name (Attribute Name) | Type | Description | Default | Reflects |
|---|---|---|---|---|
code (code) |
String |
The source code content displayed in the editor. | - | ✓ |
visible (visible) |
boolean |
Whether the code editor is visible to the user. | true |
✓ |
autoRun (autoRun) |
boolean |
Whether to automatically run the code when the component is first loaded. | false |
✓ |
runnable (runnable) |
boolean |
Whether the code execution is allowed and the run button is enabled. | true |
✓ |
autocomplete (autocomplete) |
boolean |
Whether autocompletion is enabled in the code editor. | false |
✓ |
lockedLines (lockedLines) |
number[] |
Array of line numbers that should be locked from editing. | [] |
✓ |
showExecutionTime (showExecutionTime) |
boolean |
Whether to display the execution time in the controls. | false |
✓ |
executionTime (executionTime) |
number |
The execution time in milliseconds of the last code run. | 0 |
✓ |
showExecutionCount (showExecutionCount) |
boolean |
Whether to display the execution count in the run button. | false |
✓ |
executionCount (executionCount) |
number |
The number of times the code has been executed. | 0 |
✓ |
results (results) |
any |
The results from the last code execution. | [] |
✓ |
diagnostics (diagnostics) |
Diagnostic[] |
Compilation or runtime errors from the last code execution. | [] |
✓ |
Fields including properties and attributes define the current state of the widget and offer customization options.
| Name | Value |
|---|
The editing config defines how explorable authoring tools such as WebWriter treat the widget.
No public methods, slots, events, custom CSS properties, or CSS parts.
Code widget for Java with compilation and execution capabilities using TeaVM (Java 21).
Use with a CDN (e.g. jsdelivr):
<link href="https://cdn.jsdelivr.net/npm/@webwriter/code/widgets/webwriter-code-java.css" rel="stylesheet">
<script type="module" src="https://cdn.jsdelivr.net/npm/@webwriter/code/widgets/webwriter-code-java.js"></script>
<webwriter-code-java></webwriter-code-java>Or use with a bundler (e.g. Vite):
npm install @webwriter/code
<link href="@webwriter/code/widgets/webwriter-code-java.css" rel="stylesheet">
<script type="module" src="@webwriter/code/widgets/webwriter-code-java.js"></script>
<webwriter-code-java></webwriter-code-java>| Name (Attribute Name) | Type | Description | Default | Reflects |
|---|---|---|---|---|
code (code) |
String |
The source code content displayed in the editor. | - | ✓ |
visible (visible) |
boolean |
Whether the code editor is visible to the user. | true |
✓ |
autoRun (autoRun) |
boolean |
Whether to automatically run the code when the component is first loaded. | false |
✓ |
runnable (runnable) |
boolean |
Whether the code execution is allowed and the run button is enabled. | true |
✓ |
autocomplete (autocomplete) |
boolean |
Whether autocompletion is enabled in the code editor. | false |
✓ |
lockedLines (lockedLines) |
number[] |
Array of line numbers that should be locked from editing. | [] |
✓ |
showExecutionTime (showExecutionTime) |
boolean |
Whether to display the execution time in the controls. | false |
✓ |
executionTime (executionTime) |
number |
The execution time in milliseconds of the last code run. | 0 |
✓ |
showExecutionCount (showExecutionCount) |
boolean |
Whether to display the execution count in the run button. | false |
✓ |
executionCount (executionCount) |
number |
The number of times the code has been executed. | 0 |
✓ |
results (results) |
any |
The results from the last code execution. | [] |
✓ |
diagnostics (diagnostics) |
Diagnostic[] |
Compilation or runtime errors from the last code execution. | [] |
✓ |
Fields including properties and attributes define the current state of the widget and offer customization options.
| Name | Value |
|---|
The editing config defines how explorable authoring tools such as WebWriter treat the widget.
No public methods, slots, events, custom CSS properties, or CSS parts.
Code widget for TypeScript with compilation and execution capabilities.
Use with a CDN (e.g. jsdelivr):
<link href="https://cdn.jsdelivr.net/npm/@webwriter/code/widgets/webwriter-code-typescript.css" rel="stylesheet">
<script type="module" src="https://cdn.jsdelivr.net/npm/@webwriter/code/widgets/webwriter-code-typescript.js"></script>
<webwriter-code-typescript></webwriter-code-typescript>Or use with a bundler (e.g. Vite):
npm install @webwriter/code
<link href="@webwriter/code/widgets/webwriter-code-typescript.css" rel="stylesheet">
<script type="module" src="@webwriter/code/widgets/webwriter-code-typescript.js"></script>
<webwriter-code-typescript></webwriter-code-typescript>| Name (Attribute Name) | Type | Description | Default | Reflects |
|---|---|---|---|---|
code (code) |
String |
The source code content displayed in the editor. | - | ✓ |
visible (visible) |
boolean |
Whether the code editor is visible to the user. | true |
✓ |
autoRun (autoRun) |
boolean |
Whether to automatically run the code when the component is first loaded. | false |
✓ |
runnable (runnable) |
boolean |
Whether the code execution is allowed and the run button is enabled. | true |
✓ |
autocomplete (autocomplete) |
boolean |
Whether autocompletion is enabled in the code editor. | false |
✓ |
lockedLines (lockedLines) |
number[] |
Array of line numbers that should be locked from editing. | [] |
✓ |
showExecutionTime (showExecutionTime) |
boolean |
Whether to display the execution time in the controls. | false |
✓ |
executionTime (executionTime) |
number |
The execution time in milliseconds of the last code run. | 0 |
✓ |
showExecutionCount (showExecutionCount) |
boolean |
Whether to display the execution count in the run button. | false |
✓ |
executionCount (executionCount) |
number |
The number of times the code has been executed. | 0 |
✓ |
results (results) |
any |
The results from the last code execution. | [] |
✓ |
diagnostics (diagnostics) |
Diagnostic[] |
Compilation or runtime errors from the last code execution. | [] |
✓ |
Fields including properties and attributes define the current state of the widget and offer customization options.
| Name | Value |
|---|
The editing config defines how explorable authoring tools such as WebWriter treat the widget.
No public methods, slots, events, custom CSS properties, or CSS parts.
Code widget for Python with execution capabilities using Pyodide.
Use with a CDN (e.g. jsdelivr):
<link href="https://cdn.jsdelivr.net/npm/@webwriter/code/widgets/webwriter-code-python.css" rel="stylesheet">
<script type="module" src="https://cdn.jsdelivr.net/npm/@webwriter/code/widgets/webwriter-code-python.js"></script>
<webwriter-code-python></webwriter-code-python>Or use with a bundler (e.g. Vite):
npm install @webwriter/code
<link href="@webwriter/code/widgets/webwriter-code-python.css" rel="stylesheet">
<script type="module" src="@webwriter/code/widgets/webwriter-code-python.js"></script>
<webwriter-code-python></webwriter-code-python>| Name (Attribute Name) | Type | Description | Default | Reflects |
|---|---|---|---|---|
code (code) |
String |
The source code content displayed in the editor. | - | ✓ |
visible (visible) |
boolean |
Whether the code editor is visible to the user. | true |
✓ |
autoRun (autoRun) |
boolean |
Whether to automatically run the code when the component is first loaded. | false |
✓ |
runnable (runnable) |
boolean |
Whether the code execution is allowed and the run button is enabled. | true |
✓ |
autocomplete (autocomplete) |
boolean |
Whether autocompletion is enabled in the code editor. | false |
✓ |
lockedLines (lockedLines) |
number[] |
Array of line numbers that should be locked from editing. | [] |
✓ |
showExecutionTime (showExecutionTime) |
boolean |
Whether to display the execution time in the controls. | false |
✓ |
executionTime (executionTime) |
number |
The execution time in milliseconds of the last code run. | 0 |
✓ |
showExecutionCount (showExecutionCount) |
boolean |
Whether to display the execution count in the run button. | false |
✓ |
executionCount (executionCount) |
number |
The number of times the code has been executed. | 0 |
✓ |
results (results) |
any |
The results from the last code execution. | [] |
✓ |
diagnostics (diagnostics) |
Diagnostic[] |
Compilation or runtime errors from the last code execution. | [] |
✓ |
Fields including properties and attributes define the current state of the widget and offer customization options.
| Name | Value |
|---|
The editing config defines how explorable authoring tools such as WebWriter treat the widget.
No public methods, slots, events, custom CSS properties, or CSS parts.
Code widget for WebAssembly with compilation and execution capabilities.
Use with a CDN (e.g. jsdelivr):
<link href="https://cdn.jsdelivr.net/npm/@webwriter/code/widgets/webwriter-code-webassembly.css" rel="stylesheet">
<script type="module" src="https://cdn.jsdelivr.net/npm/@webwriter/code/widgets/webwriter-code-webassembly.js"></script>
<webwriter-code-webassembly></webwriter-code-webassembly>Or use with a bundler (e.g. Vite):
npm install @webwriter/code
<link href="@webwriter/code/widgets/webwriter-code-webassembly.css" rel="stylesheet">
<script type="module" src="@webwriter/code/widgets/webwriter-code-webassembly.js"></script>
<webwriter-code-webassembly></webwriter-code-webassembly>| Name (Attribute Name) | Type | Description | Default | Reflects |
|---|---|---|---|---|
code (code) |
String |
The source code content displayed in the editor. | - | ✓ |
visible (visible) |
boolean |
Whether the code editor is visible to the user. | true |
✓ |
autoRun (autoRun) |
boolean |
Whether to automatically run the code when the component is first loaded. | false |
✓ |
runnable (runnable) |
boolean |
Whether the code execution is allowed and the run button is enabled. | true |
✓ |
autocomplete (autocomplete) |
boolean |
Whether autocompletion is enabled in the code editor. | false |
✓ |
lockedLines (lockedLines) |
number[] |
Array of line numbers that should be locked from editing. | [] |
✓ |
showExecutionTime (showExecutionTime) |
boolean |
Whether to display the execution time in the controls. | false |
✓ |
executionTime (executionTime) |
number |
The execution time in milliseconds of the last code run. | 0 |
✓ |
showExecutionCount (showExecutionCount) |
boolean |
Whether to display the execution count in the run button. | false |
✓ |
executionCount (executionCount) |
number |
The number of times the code has been executed. | 0 |
✓ |
results (results) |
any |
The results from the last code execution. | [] |
✓ |
diagnostics (diagnostics) |
Diagnostic[] |
Compilation or runtime errors from the last code execution. | [] |
✓ |
Fields including properties and attributes define the current state of the widget and offer customization options.
| Name | Value |
|---|
The editing config defines how explorable authoring tools such as WebWriter treat the widget.
No public methods, slots, events, custom CSS properties, or CSS parts.
Generated with @webwriter/build@1.8.1