-
Notifications
You must be signed in to change notification settings - Fork 121
Expand file tree
/
Copy pathCharacterCount.vue
More file actions
57 lines (54 loc) · 1.29 KB
/
CharacterCount.vue
File metadata and controls
57 lines (54 loc) · 1.29 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
<!--
- SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<NcActionText data-text-action-entry="character-count">
<template #icon>
<AlphabeticalVariant />
</template>
<template #default>
{{ countString }}
</template>
</NcActionText>
</template>
<script>
import { defineComponent } from 'vue'
import { translatePlural as n } from '@nextcloud/l10n'
import NcActionText from '@nextcloud/vue/components/NcActionText'
import { AlphabeticalVariant } from '../icons.js'
import { useEditorMixin } from '../Editor.provider.js'
export default defineComponent({
name: 'CharacterCount',
components: {
AlphabeticalVariant,
NcActionText,
},
mixins: [useEditorMixin],
props: {
visible: Boolean,
},
data: () => ({
wordCount: 0,
charCount: 0,
}),
computed: {
countString() {
return `${n('text', '%n word', '%n words', this.wordCount)}, ${n('text', '%n char', '%n chars', this.charCount)}`
},
},
watch: {
visible: 'refresh',
},
created() {
this.refresh()
},
methods: {
refresh() {
// characterCount is not reactive so we need this workaround
this.wordCount = this.$editor.storage.characterCount.words()
this.charCount = this.$editor.storage.characterCount.characters()
},
},
})
</script>