code-mirror

WebJar for code-mirror

License

License

Categories

Categories

CLI User Interface Mirror Application Layer Libs Introspection
GroupId

GroupId

org.webjars.bowergithub.advanced-rest-client
ArtifactId

ArtifactId

code-mirror
Last Version

Last Version

2.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

code-mirror
WebJar for code-mirror
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/advanced-rest-client/code-mirror

Download code-mirror

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.bowergithub.advanced-rest-client/code-mirror/ -->
<dependency>
    <groupId>org.webjars.bowergithub.advanced-rest-client</groupId>
    <artifactId>code-mirror</artifactId>
    <version>2.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.bowergithub.advanced-rest-client/code-mirror/
implementation 'org.webjars.bowergithub.advanced-rest-client:code-mirror:2.0.1'
// https://jarcasting.com/artifacts/org.webjars.bowergithub.advanced-rest-client/code-mirror/
implementation ("org.webjars.bowergithub.advanced-rest-client:code-mirror:2.0.1")
'org.webjars.bowergithub.advanced-rest-client:code-mirror:jar:2.0.1'
<dependency org="org.webjars.bowergithub.advanced-rest-client" name="code-mirror" rev="2.0.1">
  <artifact name="code-mirror" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.bowergithub.advanced-rest-client', module='code-mirror', version='2.0.1')
)
libraryDependencies += "org.webjars.bowergithub.advanced-rest-client" % "code-mirror" % "2.0.1"
[org.webjars.bowergithub.advanced-rest-client/code-mirror "2.0.1"]

Dependencies

compile (5)

Group / Artifact Type Version
org.webjars.bowergithub.polymerelements : iron-form-element-behavior jar [2.0.0,3)
org.webjars.bowergithub.polymer : polymer jar [2.0.0,3)
org.webjars.bowergithub.polymerelements : paper-styles jar [2.1.0,3)
org.webjars.bowergithub.components : codemirror jar [5.35.0,6)
org.webjars.bowergithub.polymerelements : iron-validatable-behavior jar [2.1.0,3)

Project Modules

There are no modules declared in this project.

Code mirror web component

Tests and publishing

Published on NPM

This is a wrapper for CodeMirror library. It has been adjusted to work inside shadow DOM. The component is used by Advanced REST Client and API Console.

Required imports

CodeMirror library has to be included into the document before inserting this element to the DOM. CodeMirror 6 possibly will be working with ES imports but this is not set in stone at the moment.

Below is the default set of scripts to be added to the document.

<script src="node_modules/codemirror/lib/codemirror.js"></script>
<script src="node_modules/codemirror/addon/mode/loadmode.js"></script>
<script src="node_modules/codemirror/mode/meta.js"></script>
<!--Default set of parsers -->
<script src="node_modules/codemirror/mode/javascript/javascript.js"></script>
<script src="node_modules/codemirror/mode/xml/xml.js"></script>
<script src="node_modules/codemirror/mode/htmlmixed/htmlmixed.js"></script>

If you are using JSON linter

<script src="node_modules/jsonlint/lib/jsonlint.js"></script>
<script src="node_modules/codemirror/addon/lint/lint.js"></script>
<script src="node_modules/codemirror/addon/lint/json-lint.js"></script>
<link rel="stylesheet" href="node_modules/codemirror/addon/lint/lint.css" />

Finally, if your application will use modes that aren't included in the document, you should set import URI. This will be used to resolve modes dependencies.

<script>
CodeMirror.modeURL = 'node_modules/codemirror/mode/%N/%N.js';
</script>

Accessing options

The element exposes setOption() function that should be used to directly set editor option.

cm.setOption('extraKeys', {
 'Ctrl-Space': (cm) => {
   CodeMirror.showHint(cm, CodeMirror.hint['http-headers'], {
     container: containerRef
   });
 }
});

Additionally, the element has the editor property which is a reference to the CodeMirror instance.

Rendering hidden element

If the element is active but not visible then you may need to call refresh() function on a CodeMirror instance after showing the element.

parent.style.display = 'block';
cm.editor.refresh();

Styling

See codemirror-styles.js file for CSS variables definition.

Usage

Installation

npm install --save @advanced-rest-client/code-mirror

In an html file

<html>
  <head>
    <script type="module">
      import '@advanced-rest-client/code-mirror/code-mirror.js';
    </script>
  </head>
  <body>
    <code-mirror mode="javascript">
      function myScript() {
        return 100;
      }
    </code-mirror>
  </body>
</html>

In a LitElement

import { LitElement, html } from 'lit-element';
import '@advanced-rest-client/code-mirror/code-mirror.js';

class SampleElement extends PolymerElement {
  render() {
    return html`
    <code-mirror @value-changed="${this._valueHandler}"></code-mirror>
    `;
  }

  _valueHandler(e) {
    this.value = e.detail.value;
  }
}
customElements.define('sample-element', SampleElement);

Development

git clone https://github.com/advanced-rest-client/code-mirror
cd code-mirror
npm install

Running the demo locally

npm start

Running the tests

npm test
org.webjars.bowergithub.advanced-rest-client

ARC

A set of repositories related to the Advanced REST Client and API console (by Mulesoft)

Versions

Version
2.0.1