-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSquibViewVue.js
More file actions
122 lines (116 loc) · 3.04 KB
/
SquibViewVue.js
File metadata and controls
122 lines (116 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import SquibView from './squibview.esm.min.js';
export default {
name: 'SquibViewVue',
props: {
initialContent: {
type: String,
default: ''
},
inputContentType: {
type: String,
default: 'md'
},
showControls: {
type: Boolean,
default: true
},
initialView: {
type: String,
default: 'split'
},
titleShow: {
type: Boolean,
default: false
},
titleContent: {
type: String,
default: ''
},
className: {
type: String,
default: ''
}
},
data() {
return {
editor: null
};
},
mounted() {
this.initializeEditor();
},
methods: {
initializeEditor() {
this.editor = new SquibView(this.$refs.container, {
initialContent: this.initialContent,
inputContentType: this.inputContentType,
showControls: this.showControls,
initialView: this.initialView,
titleShow: this.titleShow,
titleContent: this.titleContent
});
// Override methods to emit events
const originalSetContent = this.editor.setContent.bind(this.editor);
this.editor.setContent = (content, type, saveRevision) => {
originalSetContent(content, type, saveRevision);
this.$emit('content-change', content, type);
};
const originalSetView = this.editor.setView.bind(this.editor);
this.editor.setView = (view) => {
originalSetView(view);
this.$emit('view-change', view);
};
// Listen for editor events and re-emit them
this.editor.events.on('content:rendered', (contentType) => {
this.$emit('content-rendered', contentType);
});
this.editor.events.on('revision:undo', (content, contentType) => {
this.$emit('revision-undo', content, contentType);
});
this.editor.events.on('revision:redo', (content, contentType) => {
this.$emit('revision-redo', content, contentType);
});
}
},
watch: {
initialContent(newContent) {
if (this.editor && newContent !== this.editor.getContent()) {
this.editor.setContent(newContent, this.inputContentType || this.editor.inputContentType, false);
}
},
inputContentType(newType) {
if (this.editor && newType !== this.editor.inputContentType) {
this.editor.setContent(this.editor.getContent(), newType, false);
}
},
showControls(show) {
if (this.editor) {
this.editor.controlsShow(show);
}
},
titleShow(show) {
if (this.editor) {
this.editor.titleShow(show);
}
},
titleContent(content) {
if (this.editor) {
this.editor.titleSetContent(content);
}
},
initialView(view) {
if (this.editor) {
this.editor.setView(view);
}
}
},
beforeUnmount() {
// Cleanup if necessary
if (this.editor && this.editor.events) {
this.editor.events.off('*');
}
},
template: `
<div ref="container" :class="['squibview-vue-container', className]"></div>
`
};