3.12.1 • Published 5 years ago

@contiamo/code-editor v3.12.1

Weekly downloads
25
License
ISC
Repository
-
Last release
5 years ago

Contiamo Code editor

A Monaco editor with PSL and SQL languages ready to use!

Local development

  1. npm i
  2. npm start
  3. Start hacking 🤟

How to update lexer and parser?

If you want/need to update grammar files (*.g4), you need to regenerate the lexer/parser from antlr.

To do this you need:

Note: Generated files are versionned, so you don't need java or antlr if you don't need to update grammars 😉

Integration

Webpack configuration

To integrate this in your application, first you need style-loader and css-loader for webpack.

$ npm i -D style-loader css-loader
// webpack.config.js
+ module: {
+     rules: [
+       {
+         test: /\.css$/,
+         use: ["style-loader", "css-loader"],
+       },
+     ],
+   },

You will also need to copy the service worker file to your public directory.

$ npm i -D copy-webpack-plugin
// webpack.config.js
+ const CopyWebpackPlugin = require("copy-webpack-plugin");
...
+ plugins: [
+    new CopyWebpackPlugin([{ from: "node_modules/@contiamo/code-editor/dist/editor.worker.*.js", flatten: true }]),
+  ],

React Wrapper

import React from "react";
import bootstrapMonaco, { Config, Editor } from "@contiamo/code-editor";

export interface MyEditorProps {
  value: string;
  language: Config["language"];
  disabled: boolean;
  onChange: (value: string) => void;
}
export class MyEditor extends React.Component<MyEditorProps> {
  private editor: Editor | undefined;
  private containerNode: HTMLElement | undefined;

  componentDidMount() {
    if (!this.containerNode) {
      return;
    }

    this.editor = bootstrapMonaco(this.containerNode, {
      language: this.props.language,
      value: this.props.value,
      disabled: this.props.disabled,
    });

    // handle onChange
    this.editor.subscribe((value: string) => {
      if (this.props.onChange && !this.props.disabled) {
        this.props.onChange(value);
      }
    });
  }

  componentWillUnmount() {
    if (this.editor) {
      this.editor.unmount();
    }
  }

  render() {
    return <div innerRef={node => (this.containerNode = node)} />;
  }
}
3.12.1

5 years ago

3.12.0

5 years ago

3.11.0

5 years ago

3.10.0

5 years ago

3.9.0

5 years ago

3.8.0

5 years ago

3.7.2

5 years ago

3.7.1

5 years ago

3.7.0-3

5 years ago

3.7.0-1

5 years ago

3.7.0

5 years ago

3.6.0

5 years ago

3.5.0

5 years ago

3.4.0

5 years ago

3.3.0

5 years ago

3.2.3

5 years ago

3.2.2

5 years ago

3.2.1

5 years ago

3.2.0

5 years ago

3.1.0

5 years ago

3.0.0

5 years ago

2.0.0

5 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago