Skip to content

Commit 9c3bfbb

Browse files
committed
adjusted options merging
1 parent 4f3def2 commit 9c3bfbb

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

dev/views/Basic.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@
2222

2323
<script>
2424
import { VueEditor, Quill } from "../../src/index.js";
25-
// import { VueEditor, Quill } from "../../dist/vue2-editor.js";
2625
2726
export default {
2827
components: { VueEditor },
29-
28+
3029
data: () => ({
3130
editorOption: {
3231
bounds: "#editor-boundary",

src/VueEditor.vue

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77

88
<script>
99
import _Quill from "quill";
10-
const Quill = window.Quill || _Quill;
1110
import defaultOptions from "./helpers/default-options";
12-
import { objectAssignPolyfillHandler } from "./helpers/polyfills.js";
11+
import { objectAssignPolyfillHandler } from "./helpers/polyfills";
12+
import { configSettingsMerger } from "./helpers/config-settings-merger";
13+
import merge from "lodash.merge";
14+
15+
const Quill = window.Quill || _Quill;
1316
1417
export default {
1518
name: "VueEditor",
@@ -25,11 +28,6 @@ export default {
2528
type: Object,
2629
required: false,
2730
default: () => ({})
28-
},
29-
globalOptions: {
30-
type: Object,
31-
required: false,
32-
default: () => ({})
3331
}
3432
},
3533
@@ -40,20 +38,16 @@ export default {
4038
}),
4139
4240
mounted() {
41+
console.log(this.config);
42+
configSettingsMerger(this.defaultOptions, this.options);
4343
this.registerPrototypes();
4444
this.initialize();
4545
},
4646
4747
methods: {
4848
initialize() {
4949
if (this.$el) {
50-
this.config = Object.assign(
51-
{},
52-
this.defaultOptions,
53-
this.globalOptions,
54-
this.options
55-
);
56-
50+
this.config = Object.assign({}, this.options);
5751
this.quill = new Quill(this.$refs.editor, this.config);
5852
this.handleInitialContent();
5953
this.registerEditorEventListeners();
@@ -71,7 +65,7 @@ export default {
7165
},
7266
7367
registerEditorEventListeners() {
74-
this.quill.on('text-change', this.handleTextChange)
68+
this.quill.on("text-change", this.handleTextChange);
7569
this.quill.on("selection-change", this.handleSelectionChange);
7670
this.listenForEditorEvent("text-change");
7771
this.listenForEditorEvent("selection-change");
@@ -85,7 +79,7 @@ export default {
8579
},
8680
8781
handleInitialContent() {
88-
if (this.value) this.quill.root.innerHTML = this.value; // Set initial editor content
82+
if (this.value) this.quill.root.innerHTML = this.value; // Set initial editor content
8983
},
9084
9185
handleSelectionChange(range, oldRange) {
@@ -94,7 +88,8 @@ export default {
9488
},
9589
9690
handleTextChange() {
97-
let editorContent = this.quill.getHTML() === "<p><br></p>" ? "" : this.quill.getHTML();
91+
let editorContent =
92+
this.quill.getHTML() === "<p><br></p>" ? "" : this.quill.getHTML();
9893
this.$emit("input", editorContent);
9994
}
10095
},

src/helpers/config-settings-merger.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import merge from "lodash.merge";
2+
3+
export function configSettingsMerger(defaultOptions, customizedOptions) {
4+
if (
5+
Object.keys(customizedOptions).length > 0 &&
6+
customizedOptions.constructor === Object
7+
) {
8+
if (
9+
customizedOptions.modules &&
10+
typeof customizedOptions.modules.toolbar !== "undefined"
11+
) {
12+
// We don't want to merge default toolbar with provided toolbar.
13+
delete defaultOptions.modules.toolbar;
14+
}
15+
merge(customizedOptions, defaultOptions);
16+
}
17+
}

0 commit comments

Comments
 (0)