Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/components/Menu/ActionFormattingHelp.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!--
- @copyright Copyright (c) 2022 Vinicius Reis <[email protected]>
-
- @author Vinicius Reis <[email protected]>
-
- @license GNU AGPL version 3 or any later version
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as
- published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-->
<template>
<NcActionButton close-after-click
data-text-action-entry="formatting-help"
v-on="$listeners">
<template #icon>
<Help />
</template>
{{ t('text', 'Formatting help') }}
</NcActionButton>
</template>

<script>
import { defineComponent } from 'vue'
import { NcActionButton } from '@nextcloud/vue'
import { Help } from '../icons.js'

export default defineComponent({
name: 'ActionFormattingHelp',
components: {
NcActionButton,
Help,
},
})
</script>
23 changes: 9 additions & 14 deletions src/components/Menu/ActionList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
:title="actionEntry.label"
:data-text-action-entry="actionEntry.key"
:data-text-action-active="activeKey"
@update:open="(o) => $emit('update:open', o)">
@update:open="onOpenChange">
<template #icon>
<component :is="icon" :key="iconKey" />
</template>
Expand All @@ -41,38 +41,30 @@
:action-entry="child"
v-on="$listeners"
@trigged="onTrigger" />
<NcActionButton close-after-click
data-text-action-entry="formatting-help"
@click="$emit('call:help')">
<template #icon>
<Help />
</template>
{{ t('text', 'Formatting help') }}
</NcActionButton>
<slot name="lastAction" />
<slot v-bind="{ visible }" name="lastAction" />
</NcActions>
</template>

<script>
import { NcActions, NcActionButton } from '@nextcloud/vue'
import { NcActions } from '@nextcloud/vue'
import { BaseActionEntry } from './BaseActionEntry.js'
import ActionSingle from './ActionSingle.vue'
import { getIsActive } from './utils.js'
import { useOutlineStateMixin } from '../Editor/Wrapper.provider.js'
import useStore from '../../mixins/store.js'
import { useMenuIDMixin } from './MenuBar.provider.js'
import { Help } from '../icons.js'

export default {
name: 'ActionList',
components: {
NcActions,
NcActionButton,
ActionSingle,
Help,
},
extends: BaseActionEntry,
mixins: [useStore, useOutlineStateMixin, useMenuIDMixin],
data: () => ({
visible: false,
}),
computed: {
currentChild() {
const {
Expand Down Expand Up @@ -115,6 +107,9 @@ export default {
},
},
methods: {
onOpenChange(val) {
this.visible = val
},
runAction() {
// nothing todo
},
Expand Down
52 changes: 52 additions & 0 deletions src/components/Menu/CharacterCount.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<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'
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>
40 changes: 10 additions & 30 deletions src/components/Menu/MenuBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,11 @@
v-bind="{ actionEntry }"
:key="`text-action--${actionEntry.key}`" />
<ActionList key="text-action--remain"
:action-entry="hiddenEntries"
@update:open="refreshWordCount"
@call:help="showHelp">
<template #lastAction>
:action-entry="hiddenEntries">
<template #lastAction="{ visible }">
<ActionFormattingHelp @click="showHelp" />
<NcActionSeparator />
<NcActionText data-text-action-entry="character-count">
<template #icon>
<AlphabeticalVariant />
</template>
<template #default>
{{ countString }}
</template>
</NcActionText>
<CharacterCount v-bind="{ visible }" />
</template>
</ActionList>
</div>
Expand All @@ -67,32 +59,33 @@
</template>

<script>
import { NcActionSeparator, NcActionText } from '@nextcloud/vue'
import { NcActionSeparator } from '@nextcloud/vue'
import { subscribe, unsubscribe } from '@nextcloud/event-bus'
import { translatePlural as n } from '@nextcloud/l10n'
import debounce from 'debounce'

import HelpModal from '../HelpModal.vue'
import actionsFullEntries from './entries.js'
import ActionEntry from './ActionEntry.js'
import { MENU_ID } from './MenuBar.provider.js'
import ActionList from './ActionList.vue'
import { AlphabeticalVariant, DotsHorizontal } from '../icons.js'
import { DotsHorizontal } from '../icons.js'
import {
useEditorMixin,
useIsRichEditorMixin,
useIsRichWorkspaceMixin,
} from '../Editor.provider.js'
import ActionFormattingHelp from './ActionFormattingHelp.vue'
import CharacterCount from './CharacterCount.vue'

export default {
name: 'MenuBar',
components: {
ActionEntry,
ActionFormattingHelp,
ActionList,
AlphabeticalVariant,
HelpModal,
NcActionSeparator,
NcActionText,
CharacterCount,
},
mixins: [
useEditorMixin,
Expand Down Expand Up @@ -124,8 +117,6 @@ export default {
isReady: false,
isVisible: this.$editor.isFocused,
windowWidth: 0,
wordCount: 0,
charCount: 0,
}
},
computed: {
Expand Down Expand Up @@ -167,9 +158,6 @@ export default {
}),
}
},
countString() {
return `${n('text', '%n word', '%n words', this.wordCount)}, ${n('text', '%n char', '%n chars', this.charCount)}`
},
},
mounted() {
window.addEventListener('resize', this.getWindowWidth)
Expand Down Expand Up @@ -239,14 +227,6 @@ export default {
hideHelp() {
this.displayHelp = false
},

refreshWordCount(open) {
// characterCount is not reactive so we need this workaround
if (open) {
this.wordCount = this.$editor.storage.characterCount.words()
this.charCount = this.$editor.storage.characterCount.characters()
}
},
},
}
</script>
Expand Down