1.0.0-rc.9 • Published 2 years ago

@lsky/react-monaco-editor v1.0.0-rc.9

Weekly downloads
1
License
MIT
Repository
github
Last release
2 years ago

Monaco Editor for React


Installing

$ yarn add @lsky/react-monaco-editor

Example

Editor

import React from 'react';
import examples from '@src/examples'
// component
import MonacoEditor from '@lsky/react-monaco-editor'


class Index extends React.Component {
  render() {
    return (
      <div style={{ padding: '20px' }}>
        <h2>Monaco Editor base example</h2>
        <MonacoEditor
          width={800}
          height={500}
          language="javascript"
          value={examples['javascript']}
          onChange={(value) => {
            console.log('editor value: ', value)
          }}
          editorDidMount={(editor, monaco) => {
            console.log("editor instance: ", editor)
            console.log("monaco: ", monaco)
          }}
        />
      </div>
    )
  }
}


export default Index

Diff

import React from 'react'
import { DiffEditor } from '@lsky/react-monaco-editor'
import { diffExamples } from '@src/example'


class Index extends React.PureComponent {
  render() {
    return (
      <DiffEditor
        width={600}
        height={400}
        original={diffExamples.original}
        modified={diffExamples.modified}
        language="markdown"
      />
    )
  }
}


export default Index

monaco Instance

import { monaco } from '@lsky/react-monaco-editor'

monaco.init()
  .then(monacoInstance => {
    // then
  })

Development

To build the example locally, run:

git clone https://github.com/lsky-walt/react-monaco-editor.git

cd react-monaco-editor

yarn install

yarn start

Monaco Editor

Props

NameTypeDefaultDescription
valuestringnulleditor value
widthnumbernulleditor width
heightnumbernulleditor height
languagestringnulleditor language
themestringvsvs, vs-dark, active4d, clouds, chrome, monokai, solarized-dark, solarized-light, MonacoTheme
optionsobjectnullIEditorOptions
loadingReact.ReactNodenullloading ??
linenumbernullline number
modelOptionsArraynullmonaco.editor.createModel(value, language, ...modelOptions)
borderedbooleantrueneed bordered ?
styleobjectnulleditor outer container style
onChangefunc(value) => voidtriggered when the editor value changes
monacoWillMountfunc(monaco) => voidtriggered when the monaco will mounted
editorDidMountfunc(editor, monaco) => voidtriggered when the editor did mounted
cdnConfig{ monaco: string, monacoLoader: string }{ monaco: "https://unpkg.com/monaco-editor@0.24.0/min/vs", monacoLoader: "https://unpkg.com/monaco-editor@0.24.0/min/vs/loader.js" }custom cdn

Diff Editor

Props

NameTypeDefaultDescription
originalstringnulldiff editor original value
modifiedstringnulldiff editor modified value
widthnumbernulldiff editor width
heightnumbernulldiff editor height
languagestringnulldiff editor language
originalLanguagestringnulldiff editor original language
modifiedLanguagestringnulldiff editor modified language
themestringvsvs, vs-dark, active4d, clouds, chrome, monokai, solarized-dark, solarized-light, MonacoTheme
optionsobjectnullIDiffEditorOptions
styleobjectnulldiff editor outer container style
monacoWillMountfunc(monaco) => voidtriggered when the monaco will mounted
editorDidMountfunc(original: MonacoEditor.editor.ITextModel, modified: MonacoEditor.editor.ITextModel, editor: MonacoEditor.editor) => voidtriggered when the diff editor did mounted
onChange(value: string) => voidnullmodified model content change
cdnConfig{ monaco: string, monacoLoader: string }{ monaco: "https://unpkg.com/monaco-editor@0.24.0/min/vs", monacoLoader: "https://unpkg.com/monaco-editor@0.24.0/min/vs/loader.js" }custom cdn
1.0.0-rc.9

2 years ago

1.0.0-rc.8

3 years ago

1.0.0-rc.7

3 years ago

1.0.0-rc.6

3 years ago

1.0.0-rc.5

3 years ago

1.0.0-rc.4

3 years ago

1.0.0-rc.3

3 years ago

1.0.0-rc.2

3 years ago

1.0.0-rc.1

3 years ago

0.0.9

3 years ago

0.0.7

4 years ago

0.0.5

4 years ago

0.0.6

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago