Add BUILD and plugin to codemirror-editor Bug: Issue 4437 Change-Id: I931d2853d92b9dab20edeaf7e1fd43c40c94e339
diff --git a/BUILD b/BUILD new file mode 100644 index 0000000..70a98c1 --- /dev/null +++ b/BUILD
@@ -0,0 +1,8 @@ +load("//tools/bzl:js.bzl", "polygerrit_plugin") + +polygerrit_plugin( + name = "cm", + srcs = glob(["**/*.html", "**/*.js"]), + app = "plugin.html", + deps = ["//lib/js:codemirror-minified"], +)
diff --git a/gr-editor/gr-editor-styles.html b/gr-editor/gr-editor-styles.html new file mode 100644 index 0000000..5da80c7 --- /dev/null +++ b/gr-editor/gr-editor-styles.html
@@ -0,0 +1,42 @@ +<!-- +Copyright (C) 2017 The Android Open Source Project + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +--> + +<dom-module id="gr-editor-styles"> + <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/lib/codemirror.css"> + <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/theme/ambiance.css"> + <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/theme/ambiance-mobile.css"> + <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/theme/material.css"> + <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/theme/blackboard.css"> + <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/theme/cobalt.css"> + <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/theme/eclipse.css"> + <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/theme/elegant.css"> + <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/theme/erlang-dark.css"> + <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/theme/lesser-dark.css"> + <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/theme/midnight.css"> + <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/theme/monokai.css"> + <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/theme/neat.css"> + <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/theme/night.css"> + <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/theme/rubyblue.css"> + <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/theme/solarized.css"> + <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/theme/twilight.css"> + <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/theme/vibrant-ink.css"> + <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/theme/xq-dark.css"> + <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/theme/xq-light.css"> + <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/addon/fold/foldgutter.css"> + <template> + <style></style> + </template> +</dom-module> \ No newline at end of file
diff --git a/gr-editor/gr-editor.html b/gr-editor/gr-editor.html new file mode 100644 index 0000000..e476c51 --- /dev/null +++ b/gr-editor/gr-editor.html
@@ -0,0 +1,62 @@ +<!-- +Copyright (C) 2017 The Android Open Source Project + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +--> + +<link rel="import" href="./gr-editor-styles.html"> + +<dom-module id="gr-editor"> + <template> + <style include="gr-editor-styles"> + .CodeMirror, + #wrapper { + height: 100%; + } + .CodeMirror { + font-family: 'Roboto Mono', Menlo, 'Lucida Console', Monaco, monospace; + } + </style> + <div id="wrapper"></div> + </template> + <script src="../bower_components/codemirror-minified/lib/codemirror.js"></script> + <script src="../bower_components/codemirror-minified/mode/python/python.js" ></script> + <script src="../bower_components/codemirror-minified/mode/ruby/ruby.js" ></script> + <script src="../bower_components/codemirror-minified/mode/php/php.js" ></script> + <script src="../bower_components/codemirror-minified/mode/pascal/pascal.js" ></script> + <script src="../bower_components/codemirror-minified/mode/sql/sql.js" ></script> + <script src="../bower_components/codemirror-minified/mode/clike/clike.js" ></script> + <script src="../bower_components/codemirror-minified/mode/xml/xml.js" ></script> + <script src="../bower_components/codemirror-minified/mode/javascript/javascript.js" ></script> + <script src="../bower_components/codemirror-minified/mode/css/css.js" ></script> + <script src="../bower_components/codemirror-minified/mode/vbscript/vbscript.js" ></script> + <script src="../bower_components/codemirror-minified/mode/htmlmixed/htmlmixed.js" ></script> + <script src="../bower_components/codemirror-minified/mode/apl/apl.js" ></script> + <script src="../bower_components/codemirror-minified/mode/asciiarmor/asciiarmor.js" ></script> + <script src="../bower_components/codemirror-minified/mode/markdown/markdown.js" ></script> + <script src="../bower_components/codemirror-minified/mode/clojure/clojure.js" ></script> + <script src="../bower_components/codemirror-minified/mode/cmake/cmake.js" ></script> + <script src="../bower_components/codemirror-minified/mode/dart/dart.js" ></script> + <script src="../bower_components/codemirror-minified/mode/fortran/fortran.js" ></script> + <script src="../bower_components/codemirror-minified/mode/haskell/haskell.js" ></script> + <script src="../bower_components/codemirror-minified/mode/sass/sass.js" ></script> + <script src="../bower_components/codemirror-minified/mode/shell/shell.js" ></script> + <script src="../bower_components/codemirror-minified/mode/xml/xml.js" ></script> + <script src="../bower_components/codemirror-minified/mode/yaml/yaml.js" ></script> + <script src="../bower_components/codemirror-minified/addon/fold/foldcode.js" ></script> + <script src="../bower_components/codemirror-minified/addon/fold/foldgutter.js" ></script> + <script src="../bower_components/codemirror-minified/addon/fold/brace-fold.js" ></script> + <script src="../bower_components/codemirror-minified/addon/fold/xml-fold.js" ></script> + <script src="../bower_components/codemirror-minified/addon/fold/markdown-fold.js" ></script> + <script src="./gr-editor.js"></script> +</dom-module> \ No newline at end of file
diff --git a/gr-editor/gr-editor.js b/gr-editor/gr-editor.js new file mode 100644 index 0000000..cf76865 --- /dev/null +++ b/gr-editor/gr-editor.js
@@ -0,0 +1,47 @@ +// Copyright (C) 2017 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +(function() { + 'use strict'; + + Polymer({ + is: 'gr-editor', + /** + * Fired when the content of the editor changes. + * + * @event content-change + */ + + properties: { + fileContent: String, + mirror: Object, + prefs: Object, + }, + + attached() { + this.scopeSubtree(this.$.wrapper, true); + this.mirror = CodeMirror(this.$.wrapper, Object.assign({} , { + value: this.fileContent, + }, this.prefs)); + this.async(() => { this.mirror.refresh(); }, 1); + this.addEventListeners(); + }, + + addEventListeners() { + this.mirror.on('change', e => { + this.dispatchEvent(new CustomEvent('content-change', + {detail: {value: e.getValue()}, bubbles: true})); + }); + }, + }); +})(); \ No newline at end of file
diff --git a/plugin.html b/plugin.html new file mode 100644 index 0000000..f3ddeda --- /dev/null +++ b/plugin.html
@@ -0,0 +1,25 @@ +<!-- +Copyright (C) 2017 The Android Open Source Project + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +--> +<link rel="import" href="./gr-editor/gr-editor.html"> + +<dom-module id="editor-plugin"> + <script> + Gerrit.install(plugin => { + plugin.registerCustomComponent( + 'editor', 'gr-editor', {replace: true}); + }); + </script> +</dom-module> \ No newline at end of file