ESM-only Askr wrapper for Monaco Editor.
This package keeps the wrapper thin on purpose: it hosts Monaco inside an Askr
component without inventing a second editor API. Raw Monaco options, external
model ownership, and direct editor/namespace escape hatches are the contract.
npm install @askrjs/monaco monaco-editorimport { MonacoEditor } from '@askrjs/monaco';
import * as monaco from 'monaco-editor';const model = monaco.editor.createModel(
'const answer = 42;',
'typescript',
monaco.Uri.parse('file:///src/example.ts')
);
<MonacoEditor
monaco={monaco}
model={model}
options={{ automaticLayout: true, minimap: { enabled: false } }}
onMount={(editor) => {
editor.focus();
}}
/>;- The root exports
MonacoEditor,MonacoEditorProps, andMonacoEditorOptions. - Editor tests use Monaco's native model/edit APIs; deterministic driver code lives in this repository's test suite.
MonacoEditorlazy-loads Monaco by default or accepts an injected namespace.- Wrapper-owned concerns are host lifecycle, model wiring, and typed escape hatches.
- Controlled parent rerenders retain the live editor host, so focus, selection, history, and completion state survive model-content callbacks. Actual component unmount remains the single disposal boundary.
- Wrapper-owned
pathvalues (usage without amodelprop) must be unique. Externally-owned models are exempt from this wrapper check; pass an existing Monaco model throughmodel={monaco.editor.getModel(uri)}when sharing is intentional, and retain responsibility for its identity and disposal. - Monaco's
setThemeAPI is process-global. Thethemeprop configures that shared Monaco namespace, so simultaneous editors cannot display different themes; the most recently applied theme wins.
src/components/monaco-editor- public wrapper surfacetests- unit, jsdom, and browser smoke coveragedocs- repo notes and package overview
Import the component and its wrapper-specific props/options from @askrjs/monaco.
The duplicate @askrjs/monaco/monaco-editor path and test-only
@askrjs/monaco/testing path are removed. The two test-driver exports move into
this repository's private test helpers; use Monaco's native edit and history
APIs in application tests (see testing guidance).
Native aliases MonacoEditorInstance, MonacoTextModel, MonacoUri, and
MonacoNamespace are private: use monaco-editor types
editor.IStandaloneCodeEditor, editor.ITextModel, Uri, and
typeof import('monaco-editor/editor/editor.api'). Callback aliases
MonacoLoader, MonacoBeforeMount, MonacoMountHandler, and MonacoErrorHandler
are private: derive callbacks from MonacoEditorProps['loadMonaco'],
['beforeMount'], ['onMount']/['onUnmount'], and ['onError'].