Components

Code Editor ​

CodeEditor provides a monospace code surface for HTML or plain text, built on CodeMirror 6 via @verbb/plugin-kit-codemirror-core (shared with the <CodeEditor> web component). Use it when a schema field or settings screen needs syntax-aware editing with line numbers, tab sizing, and validation styling — without pulling in a full IDE.

Basic Usage ​

Keep the editor controlled so value changes stay in sync with the surrounding form.

Longer HTML ​

HTML mode works well for notification templates, partials, and other multi-line markup.

Other Languages ​

Use the language prop for JavaScript, CSS, JSON, or plain text highlighting.

Layout Options ​

Use rows for minimum height, tabSize for tab character width and indent unit, and lineNumbers to toggle the gutter.

Validation and Read-only ​

Use isInvalid for field-level error styling. Use readOnly or disabled when the markup should be visible but not editable.

Implementation notes ​

  • HTML mode enables @codemirror/lang-html, bracket matching, and close-brackets support.
  • Text mode omits HTML language extensions for generic monospace editing.
  • The wrapper exposes data-slot="code-editor" for styling hooks in host apps.
  • Min height is derived from rows and a fixed line height so the control stays stable in modal layouts.
  • Vanilla plugins can import @verbb/plugin-kit-web/components/code-editor.js and listen for pk-change events.
  • Web component attributes: rows, tab-size, line-numbers, language, invalid, readonly, disabled.

API ​

Props ​

NameDescription
customErrorCustom validation message; also settable via setCustomValidity().
Type string | null
Default null
defaultValueType string | null
disabledDisables the control and excludes it from constraint validation.
Type boolean
Default false
invalidType boolean
Default false
isInvalidAlias for invalid.
languageType CodeEditorLanguage
Default html
lineNumbersType boolean
Default true
nameName submitted with form data.
Type string | null
Default null
readonlyType boolean
Default false
readOnlyAlias for readonly.
requiredMarks the control as required for form submission.
Type boolean
Default false
rowsType number
Default 12
tabSizeType number
Default 4

Methods ​

NameDescription
checkValidity()Runs constraint validation without showing the browser UI.
reportValidity()Runs constraint validation and shows the browser UI when invalid.
resetValidity()Clears custom errors and re-syncs validity state.
setCustomValidity(message: string)Sets or clears a custom validation message.

Events ​

NameDescription
@blur—
@change—
@input—
@pk-change—

Custom States ​

NameDescriptionCSS selector
disabledThe control is disabled.:state(disabled)
invalidThe control currently fails constraint validation.:state(invalid)
optionalThe control is not required.:state(optional)
requiredThe control is required.:state(required)
user-invalidInvalid after the user has interacted with the control.:state(user-invalid)
user-validValid after the user has interacted with the control.:state(user-valid)
validThe control currently passes constraint validation.:state(valid)