Socket
Book a DemoInstallSign in
Socket

@alilc/lowcode-plugin-base-monaco-editor

Package Overview
Dependencies
Maintainers
20
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@alilc/lowcode-plugin-base-monaco-editor

代码编辑组件,monaco-editor 的低代码适配封装

1.1.2
latest
Source
npmnpm
Version published
Maintainers
20
Created
Source

monaco-editor for lowcode environments

This is monaco-editor's react port for lowcode environments.

It removes those obstacles when using monaco-editor directly:

  • using webpack font loader
  • using wepback-monaco-editor
  • make web worker appear in the same host as origin site
  • make font accessable and in the same repository
  • if using amd loader, make sure it dosen't collide with webpack loader
  • do above things again if it appears in dependencies in the package.json

And it supports some of the monaco-editor typescript definitions without referring to monaco-editor directly.

BTW. Style is seperate from index.js. Use import '@alilc/lowcode-plugin-base-monaco-editor/lib/style'; for styling.

API

propdescriptiontype annotation
valuevalue, controlledstring
defaultValuedefaultValue for creating model, uncontrolledstring
languagelanguage of the editorstring
themetheme of the editor, `"light""vs-dark"`
optionsMonaco editor optionsRecord<string, any>
requireConfigconfig passing to require, can be used to upgrade monaco-editorRecord<string, any>
pathpath of the current model, useful when creating a multi-model editorstring
saveViewStatewhether to save the models' view states between model changes or notboolean
classNameclassName of wrapperstring
widthwidth of wrapper`number
heightheight of wrapper`number
enableOutlinewhether to enable outline of wrapper or notboolean
stylestyle of wrapperCSSProperties
editorWillMountcallback after monaco's loaded and before editor's loaded(monaco: IMonacoInstance) => void
editorDidMountcallback after monaco's loaded and after editor's loaded(monaco: IMonacoInstance, editor: IEditorInstance) => void

Usage

Simple usage with fullscreen toggle

<SingleMonacoEditorComponent
  value={val}
  language="json"
  onChange={(next) => {
    setValue(next);
  }}
  supportFullScreen={true}
/>

Diff Editor

<LowcodePluginBaseMonacoEditor.MonacoDiffEditor
  original={JSON.stringify({a: 1}, null, 2)}
  value={JSON.stringify({b: 2}, null, 2)}
  height={100}
  language="json"
/>

Multi Model Saving Scrolling States

import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import SingleMonacoEditorComponent from '@alilc/lowcode-plugin-base-monaco-editor';

function App() {
  const [files, setFiles] = React.useState({
    'a.json': {
      name: 'a.json',
      language: 'json',
      value: '{ "a": 1 }',
    },
    'b.js': {
      name: 'b.js',
      language: 'javascript',
      value: 'var a = 1',
    },
    'c.sql': {
      name: 'c.sql',
      language: 'sql',
      value: 'SELECT * from table where id = 1',
    },
  })
  const [fileName, setFileName] = React.useState("a.json");
  const file = files[fileName];

  return (
    <div>
      {Object.keys(files).map(key => (
        <button
          key={key}
          disabled={key === fileName}
          onClick={() => {
            setFileName(key)
          }}
        >
          {key}
        </button>
      ))}
      <SingleMonacoEditorComponent
        height={40}
        path={file.name}
        language={file.language}
        defaultValue={file.value}
        saveViewState={true}
        onChange={(next) => {
          setFiles(v => ({
            ...v,
            [file.name]: {
              ...v[file.name],
              value: next,
            },
          }))
        }}
      />
    </div>
  );
}

ReactDOM.render(<App />, mountNode);

Using controller

import { controller } from '@alilc/lowcode-plugin-base-monaco-editor';

// configure Monaco to be singleton
controller.updateMeta({ singleton: true });

// Get all metadata
controller.getMeta();

// register a custom method
controller.registerMethod('methodName', (a, b, c) => { });

// call custom methods
const ret = controller.call('methodName', a, b, c);

Citation

This is forked from monaco-react. Thanks for suren-atoyan's effort for making monaco editor appoachable.

Keywords

ice

FAQs

Package last updated on 14 Apr 2023

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

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.