1.1.2 • Published 1 year ago

@alilc/lowcode-plugin-base-monaco-editor v1.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

monaco-editor for lowcode environments

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

It removes those obstacles when using monaco-editor directly:

  1. using webpack font loader
  2. using wepback-monaco-editor
  3. make web worker appear in the same host as origin site
  4. make font accessable and in the same repository
  5. if using amd loader, make sure it dosen't collide with webpack loader
  6. 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"string
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 wrappernumber | string
heightheight of wrappernumber | string
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.

@jiankeyihao/lowcode-engine-extgcw-lowcode-app-material@infinitebrahmanuniverse/nolb-_alil@everything-registry/sub-chunk-55loco-lowcode-engine-extleeyw-lowcode-engine-extlcp-code-generatorlowcode-engine-ext-wflowcode-engine-ext-ccs2lowcode-engine-ext-ccslowcode-plugin-code-editor-ccslowcode-plugin-code-editor-customerlowcode-plugin-code-generator-ccslowcode-plugin-code-generator-hbclowcode-plugin-datasource-pane-ccslowcode-plugin-datasource-pane-ccs2lowcode-setter-extlowcode-solution-gate-lowcode-output-plugin-1@lammu/lowcode-plugin-remote-handle@leanwo/lowcode-plugin-code-editor-vueepro-plugin-code-generatorealge-lowcode-operationharm-lowcode-engine-extgenerator-test-dxx@metago/lowcode-plugin-api-pane@luotongxin/lowcode-app-material@iss-library-web-designer-plugins/code-generator@knxcloud/lowcode-plugin-vue-code-editor@pxridah/hylowcode-chart-setter@pxridah/hylowcode-setter@pxridah/lowcode-datasource-pane@pxridah/lowcode-react-rendernocode-generate-plugin@zhubangyun/lowcode-engine-ext@zhubangyun/lowcode-plugin-code-editor@zhubangyun/lowcode-plugin-datasource-pane@zalastax/nolb-_alil@yuntijs/ui@cdlab996/lowcode-engine-ext-vue@cdlab996/lowcode-plugin-vue-code-editor2.7cem-lowcode-engine-extcem-lowcode-plugin-datasource-pane@an_mengdi/lowcode-app-materialvue-code-generator-plugin-testrc-lowcode-pluginrc-cus-form@alilc/lowcode-plugin-schema@alilc/lowcode-plugin-code-editor@alilc/lowcode-plugin-code-generator@alilc/lowcode-plugin-datasource-pane@alilc/lowcode-engine-ext@ali-dayu/qi-fusionantd-pro-components-lowcode-materials@bitwebsvc/lowcode-plugin-workflow-pane@bitwebsvc/plugin-usermanage-pane@bitwebsvc/lowcode-engine-ext@bitwebsvc/lowcode-plugin-code-editor@bitwebsvc/lowcode-plugin-datasource-panezby-acodezft-lowcode-engine-ext1zhizhou-lowcode@dogtiti/lowcode-engine-extzz-lowcode-plugin-code-generatorzw-lowcode-plugin-datasource-panezw-lowcodenpm-plugin-code-editorzw-lowcode-plugin-code-editorzw-lowcode-plugin-code-generator@follisher/plugin-ext@follisher/setter-ext@ftlean/lowcode-engine-ext@dslc/lowcode-engine-extshopee-lowcode-settershopee-lowcode-setter-test-code
1.1.2

1 year ago

1.1.1

2 years ago

1.1.0-beta.2

2 years ago

1.1.0

2 years ago

1.1.0-beta.1

2 years ago

1.1.0-beta.0

2 years ago

1.1.0-beta.3

2 years ago

1.0.0

2 years ago

1.0.0-beta.0

2 years ago