Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
eterna2 committed Nov 7, 2017
0 parents commit 31268a8
Show file tree
Hide file tree
Showing 85 changed files with 41,324 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"extends": ["eslint:recommended", "google", "prettier"],
"parserOptions": {
"ecmaVersion": 6
},
"env": {
"browser": true,
"es6": true
},
"plugins": ["html", "prettier"],
"rules": {
"prettier/prettier": [
"error",
{
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": false,
"jsxBracketSameLine": false
}
],
"brace-style": "off",
"new-cap": ["error", {"capIsNewExceptions": ["Polymer", "PolymerVis"]}],
"no-var": "off",
"require-jsdoc": "off",
"comma-dangle": ["error", "never"],
"arrow-parens": ["error", "as-needed"],
"no-console": ["error", {"allow": ["warn", "error"]}]
},
"globals": {
"Polymer": true,
"PolymerVis": true,
"monaco": true,
"require": true
}
}
62 changes: 62 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
jspm_packages/
/node_modules/*
/node_modules/monaco-editor/min/vs
!/node_modules/monaco-editor/min/vs/*

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

build/
10 changes: 10 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": false,
"jsxBracketSameLine": false
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 PolymerVis

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
176 changes: 176 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
monaco-editor
[![GitHub release](https://img.shields.io/github/release/PolymerVis/monaco-editor.svg)](https://github.com/PolymerVis/monaco-editor/releases)
[![Published on webcomponents.org](https://img.shields.io/badge/webcomponents.org-published-blue.svg)](https://www.webcomponents.org/element/PolymerVis/monaco-editor)
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
==========

<!---
```
<custom-element-demo>
<template is="dom-bind">
<link rel="import" href="monaco-schemas.html">
<link rel="import" href="monaco-editor.html">
<next-code-block></next-code-block>
</template>
</custom-element-demo>
```
-->
```html
<monaco-schemas
keys="vega-lite"
schemas="{{schemas}}"></monaco-schemas>

<monaco-editor
style="width:520px;"
value="[[value]]"
language="json"
schemas="[[schemas]]">
<div slot="monaco-value">{
"$schema": "https://vega.github.io/schema/vega-lite/v2.json",
"description": "A simple bar chart with embedded data.",
"data": {
"values": [
{"a": "A","b": 28}, {"a": "B","b": 55}, {"a": "C","b": 43},
{"a": "D","b": 91}, {"a": "E","b": 81}, {"a": "F","b": 53},
{"a": "G","b": 19}, {"a": "H","b": 87}, {"a": "I","b": 52}
]
},
"mark": "bar",
"encoding": {
"x": {"field": "a", "type": "ordinal"},
"y": {"field": "b", "type": "quantitative"}
}
}</div>
</monaco-editor>
```

## Installation
```
bower install --save PolymerVis/monaco-editor
```

## Documentation and demos
More examples and documentation can be found at `monaco-editor` [webcomponents page](https://www.webcomponents.org/element/PolymerVis/monaco-editor).

The demos can be found at the [`monaco-editor` Github page](https://PolymerVis.github.io/monaco-editor/build/demo).

## Special notes on styling and demo
The layout of the hints are out for the demo because of the way the original monaco editor is styled and the way webcomponents.org renders the demo. It is very difficult for me to isolate the conflicts.

You can still view the demo at the [`monaco-editor` Github page](https://PolymerVis.github.io/monaco-editor/build/demo).

## Very important note on external dependencies when building/bundling your app
`monaco-editor` loads most of the required modules dynamically, hence `polymer-build` will not be able to properly detect these external modules. You will need to manually add `bower_components/monaco-editor/node_modules/monaco-editor/min/vs/**/*` into the `extraDependencies` to ensure these modules are exported together.

## Disclaimers
PolymerVis is a personal project and is NOT in any way affliated with Microsoft, Polymer or Google.

# `monaco-editor`
`monaco-editor` is a Polymer 2.0 element for [Monaco Editor](https://microsoft.github.io/monaco-editor/), a browser-based code editor which also powers Visual Studio Code.

## Quick start
```html
<!-- enable code folding, minimap, and dark theme -->
<monaco-editor
folding
minimap
theme="vs-dark"
language="javascript"></monaco-editor>
```
Please look at the documentation for all the available options.

## Pre-populated with codes
1. Populate with the `value` property.
```js
var codes = `// this is a comment line
var helloworld = "hello world";
`;
```
```html
<!-- 2-way binding is available for `value` -->
<monaco-editor
language="javascript"
value="{{codes}}"></monaco-editor>
```

2. Populate with a `monaco-value` `slot` element.
*Note that the `text` in the `slot` element is only loaded once during initialization. Subsequent changes to the slot will not change the `value`.*
```html
<!-- text is only loaded once, and not updated upon subsequent changes -->
<monaco-editor
language="javascript"
value="{{codes}}">
<div slot="monaco-value">// comment line
var helloworld = "hello world";</div>
</monaco-editor>
```

# `monaco-schemas`
`monaco-schemas` is a Polymer 2.0 element to where you can retrieve a list of JSON schemas through a space-separated key string. These schemas can then be passed into `monaco-editor`.

`monaco-schemas` currently only has the schemas for [Vega v3.0](https://vega.github.io/vega/) and [Vega-Lite v2.0](https://vega.github.io/vega-lite/). However, you can easily add additional schemas into `monaco-schemas`.

```html
<!-- extract `schemas` by definiting a space-separated string, `keys`. -->
<monaco-schemas keys="vega-lite" schemas="{{schemas}}"></monaco-schemas>

<!--
pass the `schemas` array to `json-schemas` and set `json-validate` flag
to enable hints, suggestions, and validation of the inputs.
-->
<monaco-editor json-validate language="json"
json-schemas="[[schemas]]"></monaco-editor>
```

You can define your own schemas by providing the `uri` to the schema. `monaco-schemas` will automatically retrieve the schema from the `uri` if the `schema` field is empty.

```js
var data = {
"vega-lite-uri": {
"uri": "https://vega.github.io/schema/vega-lite/v2.json",
"schema": null,
"fileMatch": ["*"]
}
}
```
```html
<!-- retrieve an array of schemas "vega-lite" and "vega-lite-uri". -->
<monaco-schemas keys="vega-lite vega-lite-uri"
schemas="{{schemas}}"
data="[[data]]"></monaco-schemas>
```

You can also define a custom schema directly.

```json
var data_w_cat = {
"cat": {
"schema": {
"title": "Cat",
"type": "object",
"properties": {
"name": {
"description": "Name of the cat",
"type": "string"
},
"breed": {
"description": "Breed of the cat",
"type": "string"
},
"age": {
"description": "Age of the cat",
"type": "string",
"enum": ["kitten", "young adult", "adult", "old cat"]
}
}
},
"fileMatch": ["*"]
}
};
```
```html
<!-- retrieve custom schema "cat". -->
<monaco-schemas keys="cat"
schemas="{{schemas}}"
data="[[data_w_cat]]"></monaco-schemas>
```
17 changes: 17 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "monaco-editor",
"description": "A Polymer 2.0 element for Monaco Editor, an browser-based code editor.",
"main": "monaco-elements.html",
"dependencies": {
"polymer": "Polymer/polymer#^2.0.0"
},
"devDependencies": {
"iron-demo-helpers": "PolymerElements/iron-demo-helpers#^2.0.0",
"web-component-tester": "Polymer/web-component-tester#^6.0.0",
"webcomponentsjs": "webcomponents/webcomponentsjs#^1.0.0",
"vega-element": "PolymerVis/vega-element#^2.0.3"
},
"resolutions": {
"polymer": "^2.0.0"
}
}
Loading

0 comments on commit 31268a8

Please sign in to comment.