Online Component Editor
Applies to: CoModel cloud modeling & simulation platform (v1.7+)
1. Overview
The Online Component Editor (code components) is a full-page IDE that CoModel provides for custom component development. You write Julia / ModelingToolkit (MTK) component code directly in the browser — no local .jl file needed. The editor reuses the Monaco kernel of the Code (text modeling) module, with Julia syntax highlighting, real-time back-end editor validation, Error Lens inline hints, and a Problems diagnostics panel at the bottom.
With the Online Component Editor you can:
- write
@component functiondefinitions from scratch - see syntax / semantic errors in real time and jump to them in one click
- save finished components to the My MTK Components library for later drag-and-drop modeling
- modify existing components at any time; changes take effect after re-parsing
2. Entering the editor
2.1 Creating a new component
- Click Components in the left navigation bar, then MTK Components, to open the My MTK Components page.
- Click the New Component button at the top right.
- You enter the dedicated full-page route
/mtks/new.

2.2 Editing an existing component
- In the My MTK Components list, find a file whose source is
Online. - Click the Edit icon in the Actions column.
- You enter
/mtks/edit?id={file ID}.
3. Editor layout
The page uses a full-screen IDE layout with four areas from top to bottom:
| Area | Position | Description |
|---|---|---|
| Breadcrumb bar | Top | Shows My Component Libraries / New Component or My Component Libraries / {component name}; click it to return to the list |
| Toolbar | Below the breadcrumb | Library name input, editor toggles, Save / Finish / Cancel / Reset, validation status |
| Monaco editor area | Middle (flex-1) | Julia syntax highlighting, code editing (dark theme) |
| Problems panel | Bottom (collapsible) | Lists syntax / semantic diagnostics; click one to jump to its line |
4. Toolbar
| Control | Shortcut | Purpose |
|---|---|---|
| Library name input | — | Sets the display name of the library; required on save |
| Inline error hints (Error Lens) | — | Toggles inline error text at line ends |
| Word Wrap | — | Toggles word wrap |
| Increase / decrease font size | — | Adjusts the Monaco font size; the current size is shown between the buttons |
| Save | Ctrl+S |
Triggers validation and saves the component when it passes; enabled when there are changes |
| Finish | — | Saves and returns to the My MTK Components list |
| Cancel | — | Discards changes and returns (second confirmation when there are unsaved changes) |
| Reset | — | Restores the editor content to the last saved version or the initial template; enabled when there are changes |
The right side of the toolbar shows the current validation status:
Syntax OK(green)Validating...{n} error(s)(red)- when there are only warnings, the warning count (amber)
If a component name conflict occurs on save, an inline amber conflict banner appears in the toolbar (see 7.1).
5. Initial template
When you create a new component, the editor fills in an @component function template. It already carries an electrical port (p, n) lifted through a OnePort member + extend, so you can save and use it as-is, or build on it:
# define a component with ports
using ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as D
using ModelingToolkitStandardLibrary.Electrical: OnePort
@component function MyComponent(; name, R = 1.0)
@named oneport = OnePort()
@unpack v, i = oneport
pars = @parameters begin
R = R, [description = "Parameter description"]
end
eqs = [
v ~ R * i,
]
# extend lifts the p and n Pins inside OnePort up to component ports
return extend(System(eqs, t, [], pars; name), oneport)
end
For port rules and more patterns (attaching
Pindirectly, multi-member components, etc.), see Julia Component Code Conventions.For the detailed code conventions, see Julia Component Code Conventions.
6. Real-time validation and the Problems panel
About 1.2 seconds after you stop typing, the editor submits the current content to the back-end validation service (a Julia subprocess). The check has three layers:
- Syntax parsing (
[parse]): parses statement by statement, catching missingend, unbalanced parentheses, and similar errors; - MTK semantic compilation (
[mtkcompile]): evaluates each statement in an MTK sandbox, catching semantically invalid structures; - Component instantiation (
[mtkcompile]): once all statements evaluate, every component defined in the file is actually instantiated — a function definition does not execute its body, so undefined variables inside the body, misspelled APIs, references to nonexistent components, and similar errors surface at this step.
Validation results are reflected in:
- Monaco editor: error lines get red squiggles.
- Error Lens: a short error text at the end of the line (can be toggled).
- Problems panel: lists all diagnostics; expands automatically when error-level diagnostics exist.

The Problems panel header shows error / warning counts (or No problems when clean). Each diagnostic has:
| Field | Example | Description |
|---|---|---|
| Level icon | ● / △ | Error / warning |
| Source | [parse] / [mtkcompile] |
Syntax parsing / MTK semantic compilation |
| Message | expected 'end' |
Error description |
| Position | Ln 12, Col 5 |
Line and column |
Click a diagnostic row and the editor jumps to and highlights the corresponding line.
Every validation starts its own Julia subprocess in the back end, which costs seconds. The editor serializes validations automatically: while the previous validation is still running, new input is queued, and only the latest content is re-run once it finishes.
7. Save flow
When you click Save or press Ctrl+S, the system proceeds in this order:
- Name required: if the library name is empty, it prompts "Please enter a library name" and does not submit.
- Forced validation before save: waits for the validation result of the latest content.
- Error blocking: if any
error-level diagnostics exist, it prompts "There are errors, please fix before saving" and does not submit. - Submit:
- new component:
POST /api/v1/component-libraries(source_type=online) - editing an existing component: overwrites the original library file content and re-parses
- new component:
- Back end:
- synchronous syntax validation + definition detection + naming checks
- asynchronous two-phase parsing (AST scan → MTK subprocess port introspection and parameter extraction)
- returns
202 { library_file_id }
- Front-end polling: polls the parse status; on completion it shows "Saved, parsing in background" or "Save failed".
After Save succeeds you stay on the page to continue editing; Finish saves and then automatically returns to the My MTK Components list.
7.1 Resolving name conflicts
If a component name collides with a component in one of your other libraries, the back end returns 409 Conflict and an amber banner appears in the toolbar:
Component name(s) {names} already exist. Confirm overwrite?
- Click Overwrite: the content overwrites the existing library (keeping the original
library_file_idand the references inside models). - Click the "✕" or change the component name: abandon the overwrite and save again.
8. Leave guard
If you have modified code without saving, the following actions trigger a second confirmation ("You have unsaved changes. Leave anyway?"):
- clicking My Component Libraries in the breadcrumb
- clicking the Cancel button
- closing or refreshing the browser tab
Confirming leaves the page and unsaved content is lost; canceling keeps you in the editor to continue working. You can also click Reset to discard changes, or save before leaving.
9. FAQ
Q1: Why isn't the component available right after saving?
The back end needs to parse the component source asynchronously and write it into the component tables (seconds). Back on the My MTK Components list, if the parse status is Parsing, wait a few seconds or refresh the list.
Q2: What does "No component definition found" on save mean?
Your source must contain at least one @component function definition (@mtkmodel is not supported in the current environment). Pure utility functions and test scripts cannot be saved as components.
Q3: How do I confirm the component parsed successfully?
Back on the My MTK Components list, check the parse status badge on the file row:
| Badge | Meaning |
|---|---|
| Parsed | Parsing completed; the component is ready to use |
| Parsing | Being parsed |
| Failed | Parsing error; expand the row to see the error details |
10. Next steps
- To upload component files instead, read Uploading MTK Component Files.
- For the component code conventions, read Julia Component Code Conventions.