Skip to content

Commit 0a038b0

Browse files
committed
Update to working verison of 2.0
1 parent 3e4ddf4 commit 0a038b0

File tree

6 files changed

+65
-92
lines changed

6 files changed

+65
-92
lines changed

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/App.vue

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,38 @@
11
<template>
22
<div id="app">
33
<h1>Vue2Editor 2.0 (In Development)</h1>
4-
<!-- <vue-editor></vue-editor> -->
4+
<button @click="setEditor">Set Editor</button>
55
<div class="flexWrapper">
66
<div class="editorWrapper">
77
<vue-editor v-model="editorContent"></vue-editor>
88
<button @click="saveContent">Save</button>
99
</div>
10-
<div class="preview" v-html="editorContent"></div>
10+
<div class="preview" v-if="showPreview" v-html="editorContent"></div>
1111
</div>
1212

1313
</div>
1414
</template>
1515

1616
<script>
1717
import {VueEditor} from '../src/index.js'
18-
// import Vue2Editor from '../src/Vue2Editor.vue'
18+
1919
export default {
2020
components: {
2121
VueEditor,
2222
// Vue2Editor
2323
},
2424
data() {
2525
return {
26-
editorContent: '<h1>Content</h1>'
26+
editorContent: '<h1>Starting Content</h1>',
27+
showPreview: false
2728
}
2829
},
2930
3031
methods: {
32+
setEditor() {
33+
this.editorContent = 'Set programatically!'
34+
},
35+
3136
saveContent() {
3237
console.log(this.editorContent);
3338
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"description": "HTML editor using Vue.js 2.0 and Quill.js, an open source editor&#34;",
44
"version": "0.0.0",
55
"repository": {},
6-
"main": "dist/vue2-editor.js",
6+
"main": "src/index.js",
77
"files": [
8-
"dist"
8+
"src"
99
],
1010
"scripts": {
1111
"test": "echo lol",

src/VueEditor.vue

Lines changed: 41 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
<template>
22
<div id="quillWrapper">
3-
<div ref="quillContainer" id="quill-container" :value="value"></div>
4-
5-
<div v-if="showPreview" ref="livePreview" class="ql-editor"></div>
6-
3+
<div ref="quillContainer" id="quill-container"></div>
74
</div>
85
</template>
96
<script>
107
import Quill from 'quill'
118
var icons = Quill.import('ui/icons');
129
import 'quill/dist/quill.core.css'
1310
import 'quill/dist/quill.snow.css'
14-
// require('./icons/icons.js')
11+
require('./icons/icons.js')
1512
// icons['bold'] =
1613
// `<svg fill="#2d2d2d" height="36" viewBox="0 0 24 24" width="36" xmlns="http://www.w3.org/2000/svg">
1714
// <path d="M15.6 10.79c.97-.67 1.65-1.77 1.65-2.79 0-2.26-1.75-4-4-4H7v14h7.04c2.09 0 3.71-1.7 3.71-3.79 0-1.52-.86-2.82-2.15-3.42zM10 6.5h3c.83 0 1.5.67 1.5 1.5s-.67 1.5-1.5 1.5h-3v-3zm3.5 9H10v-3h3.5c.83 0 1.5.67 1.5 1.5s-.67 1.5-1.5 1.5z"/>
@@ -39,23 +36,9 @@ var defaultToolbar = [
3936
export default {
4037
name: 'vue-editor',
4138
props: {
42-
editorContent: String,
4339
value: String,
4440
placeholder: String,
45-
buttonText: String,
4641
editorToolbar: Array,
47-
useSaveButton: {
48-
type: Boolean,
49-
default () {
50-
return true
51-
}
52-
},
53-
showPreview: {
54-
type: Boolean,
55-
default () {
56-
return false
57-
}
58-
}
5942
},
6043
6144
data: function() {
@@ -67,48 +50,47 @@ export default {
6750
},
6851
6952
mounted: function() {
70-
const vm = this
71-
72-
vm.quill = new Quill(vm.$refs.quillContainer, {
73-
modules: {
74-
toolbar: this.toolbar
75-
},
76-
placeholder: this.placeholder ? this.placeholder : '',
77-
theme: 'snow'
78-
});
79-
80-
vm.editor = document.querySelector('.ql-editor')
81-
82-
if (vm.value) {
83-
vm.editor.innerHTML = vm.value
84-
}
85-
86-
if (vm.$refs.livePreview !== undefined || false) {
87-
88-
vm.quill.on('text-change', function() {
89-
vm.$refs.livePreview.innerHTML = vm.editor.innerHTML
90-
vm.$emit('input', vm.editor.innerHTML)
91-
});
92-
93-
} else {
94-
95-
vm.quill.on('text-change', function() {
96-
vm.$emit('input', vm.editor.innerHTML)
97-
// vm.$emit('editor-updated', vm.editor.innerHTML)
98-
});
99-
100-
}
53+
this.initializeVue2Editor()
54+
this.handleUpdatedEditor()
10155
},
10256
10357
watch: {
104-
editorContent: function() {
105-
this.editor.innerHTML = this.value
58+
value (val) {
59+
if (val != this.editor.innerHTML && !this.quill.hasFocus()) {
60+
this.editor.innerHTML = val
61+
}
10662
}
10763
},
10864
10965
methods: {
110-
saveContent: function(value) {
111-
this.$emit('save-content', this.editor.innerHTML)
66+
initializeVue2Editor() {
67+
this.setQuillElement()
68+
this.setEditorElement()
69+
this.checkForInitialContent()
70+
},
71+
72+
setQuillElement() {
73+
this.quill = new Quill(this.$refs.quillContainer, {
74+
modules: {
75+
toolbar: this.toolbar
76+
},
77+
placeholder: this.placeholder ? this.placeholder : '',
78+
theme: 'snow'
79+
})
80+
},
81+
82+
setEditorElement() {
83+
this.editor = document.querySelector('.ql-editor')
84+
},
85+
86+
checkForInitialContent() {
87+
this.editor.innerHTML = this.value || ''
88+
},
89+
90+
handleUpdatedEditor() {
91+
this.quill.on('text-change', () => {
92+
this.$emit('input', this.editor.innerHTML)
93+
})
11294
}
11395
}
11496
}
@@ -120,7 +102,7 @@ export default {
120102
height: 400px;
121103
}
122104

123-
/*svg {
105+
.ql-formats svg {
124106
position: absolute;
125107
left: 0;
126108
top: 0;
@@ -130,7 +112,7 @@ export default {
130112
fill: #4d4d4d;
131113
}
132114

133-
button {
115+
.ql-formats button {
134116
position: relative;
135117
transition: all .2s ease;
136118
border-radius: 3px;
@@ -139,18 +121,15 @@ button {
139121
width: 31px !important;
140122
}
141123

142-
button.ql-active {
143-
144-
background: #5b5b5b !important;
124+
.ql-formats button.ql-active {
145125
}
146126

147127
.ql-active svg {
148-
149-
fill: #06c;
128+
fill: #06c;
150129
}
151130

152131
.ql-snow .ql-picker-options .ql-picker-item {
153132
position: relative;
154133
width: 100% !important;
155-
}*/
134+
}
156135
</style>

src/index.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1-
import VueEditor from './VueEditor'
1+
/**
2+
* Vue2-Editor
3+
*/
4+
import VueEditor from './VueEditor.vue'
25

3-
export {
4-
VueEditor
6+
const Vue2Editor = {
7+
VueEditor,
8+
install: function(Vue) {
9+
Vue.component(VueEditor.name, VueEditor)
10+
}
511
}
12+
13+
export default Vue2Editor
14+
export { VueEditor }

webpack.config.dev.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)