├── .editorconfig
├── .gitattributes
├── .gitignore
├── LICENSE
├── README.md
├── circle.yml
├── example
└── index.js
├── package.json
├── src
├── CodeMirror.js
└── index.js
└── yarn.lock
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | indent_style = space
5 | indent_size = 2
6 | end_of_line = lf
7 | charset = utf-8
8 | trim_trailing_whitespace = true
9 | insert_final_newline = true
10 |
11 | [*.md]
12 | trim_trailing_whitespace = false
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | dist/
3 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) egoist <0x142857@gmail.com> (https://egoist.moe)
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # vue-cm
2 |
3 | [](https://npmjs.com/package/vue-cm) [](https://npmjs.com/package/vue-cm) [](https://circleci.com/gh/egoist/vue-cm/tree/master) [](https://github.com/egoist/donate)
4 |
5 | *[CodeMirror](https://codemirror.net/) is a versatile text editor implemented in JavaScript for the browser.*
6 |
7 | **NOTE:** I'm aware of the existence of [vue-codemirror](https://github.com/surmon-china/vue-codemirror), but I built this one for good reasons:
8 |
9 | - Smaller.
10 | - No unnecessary abstractions, which means simpler API.
11 | - Prebuilt bundle, you can use it with or without a bundler.
12 | - More modern-ish.
13 | - Simply better.
14 |
15 | ## Install
16 |
17 | ```bash
18 | yarn add codemirror vue-cm
19 | ```
20 |
21 | CDN: [UNPKG](https://unpkg.com/vue-cm/dist/) | [jsDelivr](https://cdn.jsdelivr.net/npm/vue-cm/dist/)
22 |
23 | > **NOTE**: You need to include CodeMirror as well if you're using the CDN version, basically we access it via `window.CodeMirror` in the CDN version.
24 |
25 | ## Usage
26 |
27 | ```vue
28 |
29 |
107 | Authored and maintained by egoist with help from contributors ([list](https://github.com/egoist/vue-cm/contributors)).
108 |
109 | > [egoist.moe](https://egoist.moe) · GitHub [@egoist](https://github.com/egoist) · Twitter [@_egoistlily](https://twitter.com/_egoistlily)
110 |
--------------------------------------------------------------------------------
/circle.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | jobs:
3 | build:
4 | working_directory: ~/repo
5 | docker:
6 | - image: circleci/node:latest
7 | branches:
8 | ignore:
9 | - gh-pages # list of branches to ignore
10 | - /release\/.*/ # or ignore regexes
11 | steps:
12 | - checkout
13 | - restore_cache:
14 | key: dependency-cache-{{ checksum "yarn.lock" }}
15 | - run:
16 | name: install dependences
17 | command: yarn
18 | - save_cache:
19 | key: dependency-cache-{{ checksum "yarn.lock" }}
20 | paths:
21 | - ./node_modules
22 | - run:
23 | name: test
24 | command: yarn test
25 |
--------------------------------------------------------------------------------
/example/index.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue'
2 | import CodeMirror from '../src'
3 | import 'codemirror/mode/javascript/javascript'
4 | import 'codemirror/mode/gfm/gfm'
5 |
6 | import 'codemirror/lib/codemirror.css'
7 |
8 | const code = `
9 | function foo() {
10 | return 'foo'
11 | }
12 | `.trim()
13 |
14 | const markdownCode = `
15 | # hello
16 |
17 | **this is bold**
18 |
19 | \`\`\`js
20 | function foo() {
21 | return 'foo'
22 | }
23 | \`\`\`
24 | `.trim()
25 |
26 | new Vue({
27 | el: '#app',
28 |
29 | data: {
30 | code,
31 | options: {
32 | mode: 'javascript'
33 | }
34 | },
35 |
36 | mounted() {
37 | console.log(this.$refs.editor)
38 | },
39 |
40 | methods: {
41 | updateEditor() {
42 | this.code = markdownCode
43 | this.options.mode = 'gfm'
44 | this.$refs.editor.focus()
45 | }
46 | },
47 |
48 | render() {
49 | return (
50 |