Skip to content

Commit f0bc7a6

Browse files
committed
Update documents
1 parent b50e001 commit f0bc7a6

File tree

2 files changed

+98
-108
lines changed

2 files changed

+98
-108
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#### Reproduction Link
1313
- A minimal JSBin, JSFiddle, Codepen, or a GitHub repository that can reproduce the bug.
14-
- You could start with this template: https://jsfiddle.net/u1f16q85/
14+
- You could start with this template: https://jsfiddle.net/surmon/cp01hvq2/
1515

1616
#### Steps to reproduce
1717

README.md

Lines changed: 97 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -4,126 +4,113 @@
44
[![GitHub forks](https://img.shields.io/github/forks/surmon-china/vue-codemirror.svg?style=flat-square)](https://github.com/surmon-china/vue-codemirror/network)
55
[![GitHub last commit](https://img.shields.io/github/last-commit/google/skia.svg?style=flat-square)](https://github.com/surmon-china/vue-codemirror)
66
[![license](https://img.shields.io/github/license/mashape/apistatus.svg?style=flat-square)](https://github.com/surmon-china/vue-codemirror)
7-
[![Twitter](https://img.shields.io/twitter/url/https/github.com/surmon-china/vue-codemirror.svg?style=flat-square)](https://twitter.com/intent/tweet?url=https://github.com/surmon-china/vue-codemirror)
87

98
[![NPM](https://nodei.co/npm/vue-codemirror.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/vue-codemirror/)
109
[![NPM](https://nodei.co/npm-dl/vue-codemirror.png?months=9&height=3)](https://nodei.co/npm/vue-codemirror/)
1110

1211

13-
# Vue-Codemirror
14-
[Codemirror](http://codemirror.net/) component for Vue.
12+
## vue-codemirror
13+
[CodeMirror](http://codemirror.net/) component for Vue.
1514

16-
基于 [Codemirror](http://codemirror.net/),适用于 Vue 的 Web 代码编辑器。
15+
基于 [CodeMirror](http://codemirror.net/),适用于 Vue 的 Web 代码编辑器。
1716

18-
# Example
17+
### Example
1918

20-
[Demo Page](https://surmon-china.github.io/vue-codemirror)
19+
- [Demo Page](https://surmon-china.github.io/vue-codemirror)
20+
- [CDN Example](https://jsfiddle.net/surmon/cp01hvq2/)
21+
- [Nuxt.js/SSR example code](https://github.com/surmon-china/surmon-china.github.io/tree/source/projects/vue-codemirror/nuxt)
2122

22-
[CDN Example](https://jsfiddle.net/u1f16q85/)
23+
### Events
2324

24-
[Nuxt.js/SSR example code](https://github.com/surmon-china/vue-codemirror/blob/master/examples/nuxt-ssr-example)
25+
To make it easier to handle events, the component converts some codemirror built-in native events into a single vue component event, where you can listen for events from both the component itself and from codemirror. If you need to listen for more and more complex events, you can pass in the event names (Array) you need for the global `Vue.use(, { events: [] })` and the component parameters `:events`, respectively, or by the `this.codemirror.on(event, hanger)` method of the codemirror instance. Here's a list of events:
2526

26-
# Events
27+
**codemirror event list:**
28+
- `scroll`
29+
- `changes`
30+
- `beforeChange`
31+
- `cursorActivity`
32+
- `keyHandled`
33+
- `inputRead`
34+
- `electricInput`
35+
- `beforeSelectionChange`
36+
- `viewportChange`
37+
- `swapDoc`
38+
- `gutterClick`
39+
- `gutterContextMenu`
40+
- `focus`
41+
- `blur`
42+
- `refresh`
43+
- `optionChange`
44+
- `scrollCursorIntoView`
45+
- `update`
46+
47+
**component event list:**
48+
- `ready`
49+
- `input`
50+
51+
52+
### Install
53+
54+
**NPM**
2755

28-
To make it easier to handle events, the component converts some codemirror built-in native events into a single vue component event, where you can listen for events from both the component itself and from codemirror. If you need to listen for more and more complex events, you can pass in the event names (Array) you need for the global `Vue.use(, { events: [] })` and the component parameters `:events`, respectively, or by the `this.codemirror.on(event, hanger)` method of the codemirror instance. Here's a list of events:
56+
``` bash
57+
npm install vue-codemirror --save
58+
59+
# or
60+
yarn add vue-codemirror
61+
```
2962

30-
**codemirror events list:**
31-
- scroll
32-
- changes
33-
- beforeChange
34-
- cursorActivity
35-
- keyHandled
36-
- inputRead
37-
- electricInput
38-
- beforeSelectionChange
39-
- viewportChange
40-
- swapDoc
41-
- gutterClick
42-
- gutterContextMenu
43-
- focus
44-
- blur
45-
- refresh
46-
- optionChange
47-
- scrollCursorIntoView
48-
- update
49-
50-
**component events list:**
51-
- ready
52-
- input
53-
54-
55-
# Install
56-
57-
#### CDN
63+
**CDN**
5864

5965
``` html
6066
<link rel="stylesheet" href="path/to/codemirror/lib/codemirror.css">
6167
<script type="text/javascript" src="path/to/codemirror.js"></script>
6268
<script type="text/javascript" src="path/to/vue.min.js"></script>
6369
<script type="text/javascript" src="path/to/dist/vue-codemirror.js"></script>
64-
<script type="text/javascript" src="path/to/codemirror/some-resources.js"></script>
70+
<script type="text/javascript" src="path/to/codemirror/{some-resources}"></script>
6571
<script type="text/javascript">
6672
Vue.use(window.VueCodemirror)
6773
</script>
6874
```
6975

70-
#### NPM
71-
72-
``` bash
73-
npm install vue-codemirror --save
74-
```
75-
7676
### Mount
7777

78-
#### mount with global
78+
**mount with global**
7979

8080
``` javascript
81-
// require lib
8281
import Vue from 'vue'
8382
import VueCodemirror from 'vue-codemirror'
8483

85-
// require styles
84+
// import base styles
8685
import 'codemirror/lib/codemirror.css'
8786

88-
// require more codemirror resource...
87+
// import more codemirror resource...
8988

90-
// you can set default global options and events when use
91-
Vue.use(VueCodemirror, /* {
89+
// you can set default global options and events when Vue.use
90+
Vue.use(VueCodemirror, /* {
9291
options: { theme: 'base16-dark', ... },
9392
events: ['scroll', ...]
9493
} */)
9594
```
9695

97-
#### mount with component
96+
**mount with component**
9897

9998
```javascript
100-
// require component
10199
import { codemirror } from 'vue-codemirror'
102100

103-
// require styles
101+
// import base styles
104102
import 'codemirror/lib/codemirror.css'
105103

106-
// require more codemirror resource...
104+
// import more codemirror resource...
107105

108-
// component
109106
export default {
110107
components: {
111108
codemirror
112109
}
113110
}
114111
```
115112

116-
#### mount with ssr
117-
118-
```javascript
119-
// If used in nuxt.js/ssr, you should keep it only in browser build environment
120-
if (process.browser) {
121-
const VueCodemirror = require('vue-codemirror')
122-
Vue.use(VueCodemirror)
123-
}
124-
```
125-
126-
#### defined codemirror mode
113+
**defined codemirror mode**
127114

128115
```javascript
129116
import CodeMirror from 'codemirror'
@@ -141,55 +128,60 @@ CodeMirror.defineMode('mymode', () => {
141128
}
142129
}
143130
})
131+
132+
// Vue app...
144133
```
145134

146135
### Component
147136

148137
```vue
149138
<template>
150-
<!-- bidirectional data binding(双向数据绑定) -->
151-
<codemirror v-model="code" :options="cmOptions"></codemirror>
152-
153-
<!-- or to manually control the datasynchronization(或者手动控制数据流,需要像这样手动监听changed事件) -->
154-
<codemirror ref="myCm"
155-
:value="code"
156-
:options="cmOptions"
157-
@ready="onCmReady"
158-
@focus="onCmFocus"
159-
@input="onCmCodeChange">
160-
</codemirror>
161-
162-
<!-- if Nust.js/SSR(如果在 Nuxt.js 环境下,需要外面包裹一层 no-ssr) -->
163-
<no-ssr placeholder="Codemirror Loading...">
164-
<codemirror ref="myCm"
165-
:value="code"
166-
:options="cmOptions"
167-
@ready="onCmReady"
168-
@focus="onCmFocus"
169-
@input="onCmCodeChange">
170-
</codemirror>
171-
</no-ssr>
139+
<!-- Two-way Data-Binding -->
140+
<codemirror v-model="code" :options="cmOptions" />
141+
142+
<!-- Or manually control the data synchronization -->
143+
<codemirror
144+
ref="cmEditor"
145+
:value="code"
146+
:options="cmOptions"
147+
@ready="onCmReady"
148+
@focus="onCmFocus"
149+
@input="onCmCodeChange"
150+
/>
151+
152+
<!-- Nuxt.js -->
153+
<client-only placeholder="Codemirror Loading...">
154+
<codemirror
155+
ref="cmEditor"
156+
:value="code"
157+
:options="cmOptions"
158+
@ready="onCmReady"
159+
@focus="onCmFocus"
160+
@input="onCmCodeChange"
161+
/>
162+
</client-only>
172163
</template>
173164
174165
<script>
175-
// language js
166+
// import language js
176167
import 'codemirror/mode/javascript/javascript.js'
177-
// theme css
168+
169+
// import theme css
178170
import 'codemirror/theme/base16-dark.css'
179-
// more codemirror resources
180-
// import 'codemirror/some-resource...'
171+
172+
// import more 'codemirror/some-resource...'
173+
181174
export default {
182175
data () {
183176
return {
184177
code: 'const a = 10',
185178
cmOptions: {
186-
// codemirror options
187179
tabSize: 4,
188180
mode: 'text/javascript',
189181
theme: 'base16-dark',
190182
lineNumbers: true,
191183
line: true,
192-
// more codemirror options, 更多 codemirror 的高级配置...
184+
// more codemirror options...
193185
}
194186
}
195187
},
@@ -198,7 +190,7 @@ export default {
198190
console.log('the editor is readied!', cm)
199191
},
200192
onCmFocus(cm) {
201-
console.log('the editor is focus!', cm)
193+
console.log('the editor is focused!', cm)
202194
},
203195
onCmCodeChange(newCode) {
204196
console.log('this is new code', newCode)
@@ -207,11 +199,11 @@ export default {
207199
},
208200
computed: {
209201
codemirror() {
210-
return this.$refs.myCm.codemirror
202+
return this.$refs.cmEditor.codemirror
211203
}
212204
},
213205
mounted() {
214-
console.log('this is current codemirror object', this.codemirror)
206+
console.log('the current codemirror instance object:', this.codemirror)
215207
// you can use this.codemirror to do something...
216208
}
217209
}
@@ -224,21 +216,25 @@ export default {
224216

225217
```vue
226218
<template>
227-
<codemirror :merge="true" :options="cmOption" @scroll="onCmScroll"></codemirror>
219+
<codemirror :merge="true" :options="cmOption" @scroll="onCmScroll" />
228220
</template>
229221
230222
<script>
231223
// merge js
232224
import 'codemirror/addon/merge/merge.js'
225+
233226
// merge css
234227
import 'codemirror/addon/merge/merge.css'
228+
235229
// google DiffMatchPatch
236230
import DiffMatchPatch from 'diff-match-patch'
231+
237232
// DiffMatchPatch config with global
238233
window.diff_match_patch = DiffMatchPatch
239234
window.DIFF_DELETE = -1
240235
window.DIFF_INSERT = 1
241236
window.DIFF_EQUAL = 0
237+
242238
export default {
243239
data() {
244240
return {
@@ -263,11 +259,9 @@ export default {
263259
</script>
264260
```
265261

266-
267262
### Codemirror language mode types
268-
编辑器的模式(mode属性)分为 字符串、对象两种方式,Codemirror 官方文档有说明
269263

270-
`mode: 'string' || object`
264+
Codemirror language mode have [string | object](https://codemirror.net/doc/manual.html#option_mode) types.
271265

272266
``` javascript
273267
// MIME types
@@ -295,14 +289,10 @@ mode: {
295289
}
296290
```
297291

298-
# CodeMirror
292+
### CodeMirror
299293

300294
- [CodeMirror language modes](http://codemirror.net/mode/) (MIME types defined)
301295
- [CodeMirror Autoresize](https://codemirror.net/demo/resize.html)
302296
- [CodeMirror themes](http://codemirror.net/demo/theme.html)
303297
- [CodeMirror events](https://codemirror.net/doc/manual.html#events)
304298
- [CodeMirror APIs](http://codemirror.net/doc/manual.html#config)
305-
306-
307-
# Author
308-
[Surmon](https://surmon.me)

0 commit comments

Comments
 (0)