πŸš€ DAY 5 OF LAUNCH WEEK:Introducing Webhook Events for Alert Changes.Learn more β†’
Socket
Book a DemoInstallSign in
Socket

@webwriter/code

Package Overview
Dependencies
Maintainers
3
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@webwriter/code

Write and run code as a code cell. Supports several languages (HTML, JavaScript/TypeScript, Python, Java, WebAssembly).

latest
npmnpm
Version
3.0.3
Version published
Maintainers
3
Created
Source

Code (@webwriter/code@3.0.2)

License: MIT | Version: 3.0.2

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)

Features

  • 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.

Development

To set up the development environment, clone the repository and execute the following commands:

npm install
npm run dev # runs @webwriter/build dev

Finally, import the code directory into WebWriter to begin.

Snippets

Snippets are examples and templates using the package's widgets.

NameImport Path
HTML@webwriter/code/snippets/HTML.html

CodeHTML (<webwriter-code-html>)

Code widget for HTML with live preview functionality.

Usage

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>

Fields

Name (Attribute Name)TypeDescriptionDefaultReflects
code (code)StringThe source code content displayed in the editor.-βœ“
visible (visible)booleanWhether the code editor is visible to the user.trueβœ“
autoRun (autoRun)booleanWhether to automatically run the code when the component is first loaded.falseβœ“
runnable (runnable)booleanWhether the code execution is allowed and the run button is enabled.trueβœ“
autocomplete (autocomplete)booleanWhether autocompletion is enabled in the code editor.falseβœ“
lockedLines (lockedLines)number[]Array of line numbers that should be locked from editing.[]βœ“
showExecutionTime (showExecutionTime)booleanWhether to display the execution time in the controls.falseβœ“
executionTime (executionTime)numberThe execution time in milliseconds of the last code run.0βœ“
showExecutionCount (showExecutionCount)booleanWhether to display the execution count in the run button.falseβœ“
executionCount (executionCount)numberThe number of times the code has been executed.0βœ“
results (results)anyThe 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.

Editing config

NameValue

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.

CodeJavaScript (<webwriter-code-javascript>)

Code widget for JavaScript with execution capabilities.

Usage

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>

Fields

Name (Attribute Name)TypeDescriptionDefaultReflects
code (code)StringThe source code content displayed in the editor.-βœ“
visible (visible)booleanWhether the code editor is visible to the user.trueβœ“
autoRun (autoRun)booleanWhether to automatically run the code when the component is first loaded.falseβœ“
runnable (runnable)booleanWhether the code execution is allowed and the run button is enabled.trueβœ“
autocomplete (autocomplete)booleanWhether autocompletion is enabled in the code editor.falseβœ“
lockedLines (lockedLines)number[]Array of line numbers that should be locked from editing.[]βœ“
showExecutionTime (showExecutionTime)booleanWhether to display the execution time in the controls.falseβœ“
executionTime (executionTime)numberThe execution time in milliseconds of the last code run.0βœ“
showExecutionCount (showExecutionCount)booleanWhether to display the execution count in the run button.falseβœ“
executionCount (executionCount)numberThe number of times the code has been executed.0βœ“
results (results)anyThe 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.

Editing config

NameValue

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.

CodeJava (<webwriter-code-java>)

Code widget for Java with compilation and execution capabilities using TeaVM (Java 21).

Usage

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>

Fields

Name (Attribute Name)TypeDescriptionDefaultReflects
code (code)StringThe source code content displayed in the editor.-βœ“
visible (visible)booleanWhether the code editor is visible to the user.trueβœ“
autoRun (autoRun)booleanWhether to automatically run the code when the component is first loaded.falseβœ“
runnable (runnable)booleanWhether the code execution is allowed and the run button is enabled.trueβœ“
autocomplete (autocomplete)booleanWhether autocompletion is enabled in the code editor.falseβœ“
lockedLines (lockedLines)number[]Array of line numbers that should be locked from editing.[]βœ“
showExecutionTime (showExecutionTime)booleanWhether to display the execution time in the controls.falseβœ“
executionTime (executionTime)numberThe execution time in milliseconds of the last code run.0βœ“
showExecutionCount (showExecutionCount)booleanWhether to display the execution count in the run button.falseβœ“
executionCount (executionCount)numberThe number of times the code has been executed.0βœ“
results (results)anyThe 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.

Editing config

NameValue

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.

CodeTypeScript (<webwriter-code-typescript>)

Code widget for TypeScript with compilation and execution capabilities.

Usage

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>

Fields

Name (Attribute Name)TypeDescriptionDefaultReflects
code (code)StringThe source code content displayed in the editor.-βœ“
visible (visible)booleanWhether the code editor is visible to the user.trueβœ“
autoRun (autoRun)booleanWhether to automatically run the code when the component is first loaded.falseβœ“
runnable (runnable)booleanWhether the code execution is allowed and the run button is enabled.trueβœ“
autocomplete (autocomplete)booleanWhether autocompletion is enabled in the code editor.falseβœ“
lockedLines (lockedLines)number[]Array of line numbers that should be locked from editing.[]βœ“
showExecutionTime (showExecutionTime)booleanWhether to display the execution time in the controls.falseβœ“
executionTime (executionTime)numberThe execution time in milliseconds of the last code run.0βœ“
showExecutionCount (showExecutionCount)booleanWhether to display the execution count in the run button.falseβœ“
executionCount (executionCount)numberThe number of times the code has been executed.0βœ“
results (results)anyThe 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.

Editing config

NameValue

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.

CodePython (<webwriter-code-python>)

Code widget for Python with execution capabilities using Pyodide.

Usage

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>

Fields

Name (Attribute Name)TypeDescriptionDefaultReflects
code (code)StringThe source code content displayed in the editor.-βœ“
visible (visible)booleanWhether the code editor is visible to the user.trueβœ“
autoRun (autoRun)booleanWhether to automatically run the code when the component is first loaded.falseβœ“
runnable (runnable)booleanWhether the code execution is allowed and the run button is enabled.trueβœ“
autocomplete (autocomplete)booleanWhether autocompletion is enabled in the code editor.falseβœ“
lockedLines (lockedLines)number[]Array of line numbers that should be locked from editing.[]βœ“
showExecutionTime (showExecutionTime)booleanWhether to display the execution time in the controls.falseβœ“
executionTime (executionTime)numberThe execution time in milliseconds of the last code run.0βœ“
showExecutionCount (showExecutionCount)booleanWhether to display the execution count in the run button.falseβœ“
executionCount (executionCount)numberThe number of times the code has been executed.0βœ“
results (results)anyThe 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.

Editing config

NameValue

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.

CodeWebAssembly (<webwriter-code-webassembly>)

Code widget for WebAssembly with compilation and execution capabilities.

Usage

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>

Fields

Name (Attribute Name)TypeDescriptionDefaultReflects
code (code)StringThe source code content displayed in the editor.-βœ“
visible (visible)booleanWhether the code editor is visible to the user.trueβœ“
autoRun (autoRun)booleanWhether to automatically run the code when the component is first loaded.falseβœ“
runnable (runnable)booleanWhether the code execution is allowed and the run button is enabled.trueβœ“
autocomplete (autocomplete)booleanWhether autocompletion is enabled in the code editor.falseβœ“
lockedLines (lockedLines)number[]Array of line numbers that should be locked from editing.[]βœ“
showExecutionTime (showExecutionTime)booleanWhether to display the execution time in the controls.falseβœ“
executionTime (executionTime)numberThe execution time in milliseconds of the last code run.0βœ“
showExecutionCount (showExecutionCount)booleanWhether to display the execution count in the run button.falseβœ“
executionCount (executionCount)numberThe number of times the code has been executed.0βœ“
results (results)anyThe 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.

Editing config

NameValue

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

Keywords

webwriter-widget

FAQs

Package last updated on 27 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts