npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

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

v2.1.0

Published

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

Readme

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 '@gant-lowcode/lowcode-plugin-base-monaco-editor/lib/style'; for styling.

API

| prop | description | type annotation | | --- | --- | --- | | value | value, controlled | string | | defaultValue | defaultValue for creating model, uncontrolled | string | | language | language of the editor | string | | theme | theme of the editor, "light" | "vs-dark" | string | | options | Monaco editor options | Record<string, any> | | requireConfig | config passing to require, can be used to upgrade monaco-editor | Record<string, any> | | path | path of the current model, useful when creating a multi-model editor | string | | saveViewState | whether to save the models' view states between model changes or not | boolean | | className | className of wrapper | string | | width | width of wrapper | number | string | | height | height of wrapper | number | string | | enableOutline | whether to enable outline of wrapper or not | boolean | | style | style of wrapper | CSSProperties | | editorWillMount | callback after monaco's loaded and before editor's loaded | (monaco: IMonacoInstance) => void | | editorDidMount | callback 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 '@gant-lowcode/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 '@gant-lowcode/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.