Skip to content

Commit

Permalink
fix: disable callouts button when all callout variants are disabled
Browse files Browse the repository at this point in the history
Signed-off-by: Luka Trovic <luka@nextcloud.com>
  • Loading branch information
luka-nextcloud committed Apr 22, 2024
1 parent fbaf71a commit 26cdebe
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/components/Menu/ActionList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
:force-menu="true"
:data-text-action-entry="actionEntry.key"
:data-text-action-active="activeKey"
:disabled="isDisabled"
@update:open="onOpenChange">
<template #icon>
<component :is="icon" :key="iconKey" />
Expand All @@ -53,10 +54,11 @@
import { NcActions, NcActionSeparator } from '@nextcloud/vue'
import { BaseActionEntry } from './BaseActionEntry.js'
import ActionListItem from './ActionListItem.vue'
import { getIsActive } from './utils.js'
import { getActionState, getIsActive } from './utils.js'
import { useOutlineStateMixin } from '../Editor/Wrapper.provider.js'
import useStore from '../../mixins/store.js'
import { useMenuIDMixin } from './MenuBar.provider.js'
import debounce from 'debounce'
export default {
name: 'ActionList',
Expand All @@ -69,6 +71,7 @@ export default {
mixins: [useStore, useOutlineStateMixin, useMenuIDMixin],
data: () => ({
visible: false,
disabledChildren: [],
}),
computed: {
currentChild() {
Expand Down Expand Up @@ -121,6 +124,18 @@ export default {
return this.actionEntry.label
},
isDisabled() {
return this.disabledChildren.length === this.children.filter((child) => !child.isSeparator).length
},
},
mounted() {
this.$_updateState = debounce(this.checkStateOfChildren.bind(this), 50)
this.$editor.on('update', this.$_updateState)
this.$editor.on('selectionUpdate', this.$_updateState)
},
beforeDestroy() {
this.$editor.off('update', this.$_updateState)
this.$editor.off('selectionUpdate', this.$_updateState)
},
methods: {
onOpenChange(val) {
Expand All @@ -136,6 +151,15 @@ export default {
this.$editor.chain().focus().run()
this.$emit('trigged', entry)
},
checkStateOfChildren() {
this.disabledChildren = this.children.filter((child) => {
if (child.isSeparator) {
return false
}
const { disabled } = getActionState(child, this.$editor)
return disabled
})
},
},
}
</script>

0 comments on commit 26cdebe

Please sign in to comment.