-
Notifications
You must be signed in to change notification settings - Fork 57
/
NormalButton.vue
119 lines (107 loc) · 3.92 KB
/
NormalButton.vue
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
<template>
<base-button
:isActive="buttonIsActive"
:isDisabled="mode != 'editor'"
:clickMethod="toggleButton"
:title="__(button)"
:icon="icon"
:innerHtml="innerHtml"
>
</base-button>
</template>
<script>
import BaseButton from './BaseButton.vue';
export default {
props: ['button', 'editor', 'mode'],
components: {
BaseButton,
},
computed: {
buttonIsActive() {
if (!this.editor) {
return false;
}
return this.editor.isActive(this.button);
},
icon() {
if (this.button == 'bold') {
return ['fas', 'bold'];
} else if (this.button == 'italic') {
return ['fas', 'italic'];
} else if (this.button == 'highlight') {
return ['fas', 'highlighter'];
} else if (this.button == 'strike') {
return ['fas', 'strikethrough'];
} else if (this.button == 'underline') {
return ['fas', 'underline'];
} else if (this.button == 'blockquote') {
return ['fas', 'quote-right'];
} else if (this.button == 'bulletList') {
return ['fas', 'list-ul'];
} else if (this.button == 'orderedList') {
return ['fas', 'list-ol'];
} else if (this.button == 'horizontalRule') {
return ['fas', 'horizontal-rule'];
} else if (this.button == 'table') {
return ['fas', 'table'];
} else if (this.button == 'subscript') {
return ['fas', 'subscript'];
} else if (this.button == 'superscript') {
return ['fas', 'superscript'];
} else if (this.button == 'paragraph') {
return ['fas', 'paragraph'];
}
return null;
},
innerHtml() {
if (this.button == 'code') {
return '<span> <> </span>';
} else if (this.button == 'codeBlock') {
return '<span> </> </span>';
} else if (this.button == 'hardBreak') {
return '<span> BR </span>';
}
return null;
}
},
methods: {
toggleButton() {
var command = this.editor.chain().focus();
if (this.button == 'bold') {
command.toggleBold();
} else if (this.button == 'code') {
command.toggleCode();
} else if (this.button == 'italic') {
command.toggleItalic();
} else if (this.button == 'highlight') {
command.toggleHighlight();
} else if (this.button == 'strike') {
command.toggleStrike();
} else if (this.button == 'underline') {
command.toggleUnderline();
} else if (this.button == 'subscript') {
command.toggleSubscript();
} else if (this.button == 'superscript') {
command.toggleSuperscript();
} else if (this.button == 'blockquote') {
command.toggleBlockquote();
} else if (this.button == 'bulletList') {
command.toggleBulletList();
} else if (this.button == 'orderedList') {
command.toggleOrderedList();
} else if (this.button == 'codeBlock') {
command.toggleCodeBlock();
} else if (this.button == 'horizontalRule') {
command.setHorizontalRule();
} else if (this.button == 'table') {
command.insertTable({ rows: 3, cols: 3, withHeaderRow: true });
} else if (this.button == 'hardBreak') {
command.setHardBreak();
} else if (this.button == 'paragraph') {
command.setParagraph();
}
command.run();
}
},
}
</script>