CodeEditor

A Panel subclass which encapsulates a Monaco editor to provide rich editing of text.

This requires the Monaco editor to be installed as a Node module, and simply requires a path to a local node_modules directory.

Editing text is as simple as setting the text and language properties.

const
    editorPanel = new CodeEditor({
        codePath : 'node_modules/monaco-editor',
        width    : 1000,
        height   : 600,
        title    : 'This is just a Panel',
        text     : 'This is the text to edit',
        language : 'markdown',
        appendTo : document.body
    }),
    // Direct access to the Monaco Editor API
    monaco = await editorPanel.editorReady;

The CodeEditor loads the required modules dynamically from the codePath and fulfills the editorReady Promise, yielding the Monaco editor when it is ready for interaction.

Status bar

The bottom toolbar of this Panel is used as a status bar. You may reconfigure it or its items in the usual way. There are three items provided by default.

These may all be accessed using this Panel's widgetMap.

These may all be styled using the selector [ref="widgetName"] where "widgetName" is one of the names listed below:

  • readOnly A read-only indicator which by default uses the Font-Awesome fa-lock glyph to indicate that the editor is read-only.
  • status A widget which may be used to display textual status messages.
  • cursorPos A widget which displays the current cursor position.

Code editor
//<code-header>
fiddle.title = 'Code editor';
//</code-header>
const panel = new CodeEditor({
    codePath : window.bryntum.editorPath,
    appendTo : targetElement,
    height   : '30em',
    width    : '55em',
    header   : 'Editing this example\'s code. No, it does not reload on change'
});

fetch('../docs/data/Core/examples/widget/CodeEditor.js').then(response => {
    response.text().then(t => panel.text = t);
});

Configs

114

Common

listenersEvents

Other

codePath: String

The path from which to load the Monaco editor.

For example:

{
  codePath : 'node_modules/monaco-editor'
}

An editor configuration object to be passed to https://microsoft.github.io/monaco-editor/docs.html#functions/editor.create.html

The language being edited may be set and read using this property.

The read-only state of the editor may be set and read. This state is by default reflected by an icon in the bottom toolbar.

The status message displayed un the bottom toolbar may be set and read using this property.

The text being edited may be set and read using this property.

theme: vs | vs-dark | hc-black | hc-lightAlso a property

The Monaco theme to use. If not specified, it defaults to 'vs';

columnWidget
defaultFocusContainer
drawerPanel
labelPositionContainer
renditionContainer
rtlRTL
spanWidget

Accessibility

ariaLabelWidget
keyMapKeyMap

Content

bbarPanel
defaultsContainer
footerPanel
headerPanel
itemsContainer
lazyItemsContainer
namedItemsContainer
stripsPanel
tbarPanel
textContentContainer
toolsPanel

CSS

bodyClsPanel
borderContainer
clsWidget
colorWidget
htmlClsWidget
itemClsContainer
styleWidget
uiPanel

DOM

adoptWidget
appendToWidget
contentWidget
datasetWidget
htmlWidget
idWidget
tagWidget

Float & align

alignWidget
anchorWidget
centeredWidget
draggableWidget
floatingWidget
xWidget
yWidget

Layout

alignSelfWidget
dockWidget
flexWidget
heightWidget
hiddenWidget
hideWhenEmptyContainer
layoutContainer
layoutStyleContainer
marginWidget
maxHeightWidget
maxWidthWidget
minHeightWidget
minWidthWidget
textAlignWidget
weightWidget
widthWidget

misc

tabBarItemsContainer

Misc

dataFieldWidget
disabledWidget
iconPanel
localeClassLocalizable
localizableLocalizable
maskedWidget
ownerWidget
refWidget
rippleWidget
tabWidget
titlePanel
tooltipWidget

Record

recordContainer

Scrolling

State

stateIdState

Properties

101

Class hierarchy

isCodeEditor: Boolean= truereadonly
Identifies an object as an instance of CodeEditor class, or subclass thereof.
isCodeEditor: Boolean= truereadonlystatic
Identifies an object as an instance of CodeEditor class, or subclass thereof.
isContainerContainer
isDelayableDelayable
isEventsEvents
isKeyMapKeyMap
isLocalizableLocalizable
isPanelPanel
isStateState
isToolableToolable
isWidgetWidget

Other

codeModel: Objectreadonly

An instance of https://microsoft.github.io/monaco-editor/docs.html#interfaces/editor.ITextModel.html which is handling the editing of the current text.

This is created every time text is set.

editor: ObjectreadonlyAlso a config

The Monaco editor instance. Use this property to manipulate the editor according to https://microsoft.github.io/monaco-editor/typedoc/index.html

Note that this will only exist when the editor has been loaded from the codePath.

This will be indicated by the editorReady property which yields the monaco editor as its value.

editorReady: Promisereadonly

A promise which resolves when the Monaco editor is loaded from the codePath and ready for use which yields the Monaco editor instance.

The language being edited may be set and read using this property.

The read-only state of the editor may be set and read. This state is by default reflected by an icon in the bottom toolbar.

The status message displayed un the bottom toolbar may be set and read using this property.

The text being edited may be set and read using this property.

theme: vs | vs-dark | hc-black | hc-lightAlso a config

The Monaco theme to use. If not specified, it defaults to 'vs';

$namestaticWidget
columnWidget
firstItemContainer
hasChangesContainer
isValidContainer
itemsContainer
labelPositionContainer
lastItemContainer
renditionContainer
rtlRTL
spanWidget
toolsPanel
typestaticWidget
valuesContainer

Accessibility

keyMapKeyMap

Content

bbarPanel
tbarPanel

CSS

clsWidget

DOM

appendToWidget
contentWidget
datasetWidget
elementWidget
htmlWidget
idWidget
styleWidget

Float & align

xWidget
yWidget

Layout

alignSelfWidget
flexWidget
heightWidget
layoutContainer
layoutStyleContainer
marginWidget
maxHeightWidget
maxWidthWidget
minHeightWidget
minWidthWidget
widthWidget

Lifecycle

configBase

Misc

cellInfoWidget
disabledWidget
localeHelperLocalizable
localeManagerLocalizable
refWidget
tabWidget
titlePanel
tooltipWidget

Record

recordContainer

State

stateState

Visibility

hiddenWidget
isVisibleWidget

Widget hierarchy

ownerWidget
parentWidget
widgetMapContainer

Functions

75

Other

Constructor for Code Editor.

ParameterTypeDescription
config

Focuses the Monaco editor

Loads text into the editor.

ParameterTypeDescription
textString

The text to edit.

languageString

The language to edit the text with.

Returns: Object -

The https://microsoft.github.io/monaco-editor/docs.html#interfaces/editor.ITextModel.html which is handling editing the text.

addContainer
composeWidget
createOnFrameDelayable
disableWidget
enableWidget
getAtContainer
getWidgetByIdContainer
insertContainer
LstaticLocalizable
maskWidget
onEvents
recomposeWidget
relayAllEvents
removeContainer
removeAllContainer
resetValuesContainer
setValuesContainer
triggerEvents
unEvents
unmaskWidget

Configuration

applyDefaultsstaticBase

Events

Float & align

alignToWidget
setXYWidget
showByWidget
toFrontWidget

Lifecycle

createstaticWidget
destroystaticBase
initClassstaticWidget

Misc

attachTooltipstaticWidget
fromElementstaticWidget
fromSelectorstaticWidget
getByIdstaticWidget
isOfTypeNamestaticBase
mixinstaticBase
optionalLstaticLocalizable

State

Visibility

hideWidget
showWidget

Widget hierarchy

closestWidget
containsWidget
ownsWidget
queryWidget
queryAllWidget
upWidget

Events

21

Event handlers

21

Typedefs

7

CSS variables

52

Inherited