Skip to content

Commit c6cb853

Browse files
committed
chore: testing SSR
1 parent 53c27ec commit c6cb853

File tree

2 files changed

+38
-52
lines changed

2 files changed

+38
-52
lines changed

src/components/VueEditor.vue

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,35 @@
22
<div class="quillWrapper">
33
<slot name="toolbar"></slot>
44
<div :id="id" ref="quillContainer"></div>
5-
<input
5+
<!-- <input
66
v-if="useCustomImageHandler"
77
id="file-upload"
88
ref="fileInput"
99
type="file"
1010
accept="image/*"
1111
style="display:none;"
1212
@change="emitImageInfo($event)"
13-
/>
13+
/> -->
1414
</div>
1515
</template>
1616

1717
<script>
18+
// import Quill from 'quill'
1819
import Vue from "vue";
1920
import defaultToolbar from "@/helpers/default-toolbar";
2021
import oldApi from "@/helpers/old-api";
2122
import mergeDeep from "@/helpers/merge-deep";
22-
// import MarkdownShortcuts from "@/helpers/markdown-shortcuts";
23+
// import MarkdownShortcuts from '@/helpers/markdown-shortcuts'
2324
2425
let Quill;
2526
let MarkdownShortcuts;
27+
// if (!Vue.prototype.$isServer) Quill = require('quill')
2628
if (!Vue.prototype.$isServer) {
27-
console.log("NOT SERVER");
28-
2929
Quill = require("quill");
3030
MarkdownShortcuts = require("@/helpers/markdown-shortcuts");
3131
}
3232
3333
export default {
34-
name: "VueEditor",
3534
mixins: [oldApi],
3635
props: {
3736
id: {
@@ -74,6 +73,7 @@ export default {
7473
7574
watch: {
7675
value(val) {
76+
// eslint-disable-next-line eqeqeq
7777
if (val != this.quill.root.innerHTML && !this.quill.hasFocus()) {
7878
this.quill.root.innerHTML = val;
7979
}
@@ -84,11 +84,12 @@ export default {
8484
},
8585
8686
mounted() {
87-
this.$parent.$once("hook:mounted", () => {
88-
console.log("in mounted hook");
87+
// this.$parent.$once('hook:mounted', () => {
88+
// // eslint-disable-next-line no-console
89+
// console.log('in mounted hook')
8990
90-
this.$parent.$forceUpdate();
91-
});
91+
// this.$parent.$forceUpdate()
92+
// })
9293
this.registerCustomModules(Quill);
9394
this.registerPrototypes();
9495
this.initializeEditor();
@@ -109,7 +110,7 @@ export default {
109110
},
110111
111112
setupQuillEditor() {
112-
let editorConfig = {
113+
const editorConfig = {
113114
debug: false,
114115
modules: this.setModules(),
115116
theme: "snow",
@@ -122,12 +123,12 @@ export default {
122123
},
123124
124125
setModules() {
125-
let modules = {
126+
const modules = {
126127
toolbar: this.editorToolbar.length ? this.editorToolbar : defaultToolbar
127128
};
128129
if (this.useMarkdownShortcuts) {
129130
Quill.register("modules/markdownShortcuts", MarkdownShortcuts, true);
130-
modules["markdownShortcuts"] = {};
131+
modules.markdownShortcuts = {};
131132
}
132133
return modules;
133134
},
@@ -154,7 +155,7 @@ export default {
154155
return this.container.querySelector(".ql-editor").innerHTML;
155156
};
156157
Quill.prototype.getWordCount = function() {
157-
return this.container.querySelector(".ql-editor").innerText.length;
158+
return this.container.querySelector(".ql-editor").textContent.length;
158159
};
159160
},
160161
@@ -182,7 +183,7 @@ export default {
182183
},
183184
184185
handleTextChange(delta, oldContents) {
185-
let editorContent =
186+
const editorContent =
186187
this.quill.getHTML() === "<p><br></p>" ? "" : this.quill.getHTML();
187188
this.$emit("input", editorContent);
188189
@@ -204,11 +205,12 @@ export default {
204205
});
205206
},
206207
checkForCustomImageHandler() {
208+
// eslint-disable-next-line no-unused-expressions
207209
this.useCustomImageHandler === true ? this.setupCustomImageHandler() : "";
208210
},
209211
210212
setupCustomImageHandler() {
211-
let toolbar = this.quill.getModule("toolbar");
213+
const toolbar = this.quill.getModule("toolbar");
212214
toolbar.addHandler("image", this.customImageHandler);
213215
},
214216
@@ -218,13 +220,13 @@ export default {
218220
219221
emitImageInfo($event) {
220222
const resetUploader = function() {
221-
var uploader = document.getElementById("file-upload");
223+
const uploader = document.getElementById("file-upload");
222224
uploader.value = "";
223225
};
224-
let file = $event.target.files[0];
225-
let Editor = this.quill;
226-
let range = Editor.getSelection();
227-
let cursorLocation = range.index;
226+
const file = $event.target.files[0];
227+
const Editor = this.quill;
228+
const range = Editor.getSelection();
229+
const cursorLocation = range.index;
228230
this.$emit("image-added", file, Editor, cursorLocation, resetUploader);
229231
this.$emit("imageAdded", file, Editor, cursorLocation, resetUploader);
230232
}
@@ -233,4 +235,3 @@ export default {
233235
</script>
234236

235237
<style src="quill/dist/quill.snow.css"></style>
236-
<style src="../assets/vue2-editor.scss" lang="scss"></style>

src/index.js

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,20 @@
1-
import Quill from "quill";
2-
import VueEditor from "@/components/VueEditor.vue";
1+
/* eslint-disable no-console */
2+
import VueEditor from "./VueEditor";
33

4-
const version = "__VERSION__";
4+
const Plugin = {
5+
install(Vue, options = {}) {
6+
Vue.component("VueEditor", VueEditor);
57

6-
// Declare install function executed by Vue.use()
7-
export function install(Vue) {
8-
if (install.installed) return;
9-
install.installed = true;
8+
// Vue.prototype.$modal = {
9+
// show(name) {
10+
// location.hash = name
11+
// },
1012

11-
Vue.component("VueEditor", VueEditor);
12-
}
13-
14-
const VPlugin = {
15-
install,
16-
version,
17-
Quill,
18-
VueEditor
13+
// hide(name) {
14+
// location.hash = '#'
15+
// }
16+
// }
17+
}
1918
};
2019

21-
// Auto-install when vue is found (eg. in browser via <script> tag)
22-
let GlobalVue = null;
23-
if (typeof window !== "undefined") {
24-
GlobalVue = window.Vue;
25-
} else if (typeof global !== "undefined") {
26-
GlobalVue = global.Vue;
27-
}
28-
if (GlobalVue) {
29-
GlobalVue.use(VPlugin);
30-
}
31-
32-
export default VPlugin;
33-
export { VueEditor, Quill };
34-
35-
/*************************************************/
20+
export default Plugin;

0 commit comments

Comments
 (0)