Socket
Book a DemoInstallSign in
Socket

@snack-uikit/code-editor

Package Overview
Dependencies
Maintainers
3
Versions
125
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@snack-uikit/code-editor

latest
Source
npmnpm
Version
0.7.11
Version published
Maintainers
3
Created
Source

Code Editor

Installation

npm i @snack-uikit/code-editor

Changelog

CodeEditor

Props

nametypedefault valuedescription
jsonSchema*JsonSchema-Схема для валидации
themeNamestring-Название текущей темы. Значение не важно, важно что смена значения запускает пересчет стилей.
hasBackgroundbooleantrueВключение/отключение псевдобекграунда
hasHeaderboolean-Включение/отключение шапки
onCopyClick() => void-Клик по кнопке копирования
defaultValuestring-Default value of the current model
defaultLanguagestring-Default language of the current model
defaultPathstring-Default path of the current model Will be passed as the third argument to .createModel method monaco.editor.createModel(..., ..., monaco.Uri.parse(defaultPath))
valuestring-Value of the current model
languagestring-Language of the current model
pathstring-Path of the current model Will be passed as the third argument to .createModel method monaco.editor.createModel(..., ..., monaco.Uri.parse(defaultPath))
themestring"light"The theme for the monaco Available options "vs-dark" | "light" Define new themes by monaco.editor.defineTheme
linenumber-The line to jump on it
loadingReactNode"Loading..."The loading screen before the editor will be mounted
optionsIStandaloneEditorConstructionOptions-IStandaloneEditorConstructionOptions
overrideServicesIEditorOverrideServices-IEditorOverrideServices
saveViewStateboolean-Indicator whether to save the models' view states between model changes or not Defaults to true
keepCurrentModelbooleanfalseIndicator whether to dispose the current model when the Editor is unmounted or not
widthstring | number"100%"Width of the editor wrapper
heightstring | number"100%"Height of the editor wrapper
classNamestring-Class name for the editor container
wrapperPropsobject-Props applied to the wrapper element
beforeMountBeforeMount-Signature: function(monaco: Monaco) => void An event is emitted before the editor is mounted It gets the monaco instance as a first argument Defaults to "noop"
onMountOnMount-Signature: function(editor: monaco.editor.IStandaloneCodeEditor, monaco: Monaco) => void An event is emitted when the editor is mounted It gets the editor instance as a first argument and the monaco instance as a second Defaults to "noop"
onChangeOnChange-Signature: function(value: string | undefined, ev: monaco.editor.IModelContentChangedEvent) => void An event is emitted when the content of the current model is changed
onValidateOnValidate-Signature: function(markers: monaco.editor.IMarker[]) => void An event is emitted when the content of the current model is changed and the current model markers are ready Defaults to "noop"

Поддержка YAML

Для обеспечения полноценной работы YAML Monaco Editor необходимо подключить yaml.worker. Это можно сделать следующими способами: с использованием window.MonacoEnvironment или с помощью плагина MonacoWebpackPlugin . Подробнее с monaco-yaml можно ознакомиться тут

Как редактор загружает worker?

Плагин создает новые точки входа каждого build-in воркера и для каждого дабавленного отдельно. Плагин создат глобальную переменную, используя которую редкатор будет загружать нужный воркер на основе текущего language.

Чтобы управлять конфигурацией загрузчика Monaco Editor, добавьте

import * as monaco from 'monaco-editor';
import { loader } from '@snack-uikit/code-editor';
loader.config({ monaco });

Это позволяет динамически настраивать пути и другие параметры при инициализации редактора.

Для загрузки monaco-editor асинхронно можно воспользоваться следующим способом:

// import * as monaco from 'monaco-editor'; // ~3Mb
import { lazy, Suspense } from 'react';
import { loader, CodeEditor } from '@snack-uikit/code-editor';

const Editor = lazy(async () => {
  const monaco = await import('monaco-editor').then(module => module.default);
  loader.config({ monaco });
  return { default: CodeEditor };
});

const MyComponent = () => {
  return <Suspense fallback={<Loader height={height} />}>
   <Editor />
  </Suspense>
}

FAQs

Package last updated on 22 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