-
Notifications
You must be signed in to change notification settings - Fork 122
Expand file tree
/
Copy pathActionList.vue
More file actions
130 lines (123 loc) · 3.25 KB
/
ActionList.vue
File metadata and controls
130 lines (123 loc) · 3.25 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
123
124
125
126
127
128
129
130
<!--
- @copyright Copyright (c) 2022 Vinicius Reis <vinicius@nextcloud.com>
-
- @author Vinicius Reis <vinicius@nextcloud.com>
-
- @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>
<NcActions v-tooltip="tooltip"
class="entry-list-action entry-action"
role="menu"
v-bind="state"
:container="menuIDSelector"
:aria-label="actionEntry.label"
:aria-pressed="state.active"
:type="state.active ? 'primary': 'tertiary'"
:aria-activedescendant="currentChild ? `${$menuID}-child-${currentChild.key}` : null"
:force-menu="true"
:name="actionEntry.label"
:data-text-action-entry="actionEntry.key"
:data-text-action-active="activeKey"
@update:open="onOpenChange">
<template #icon>
<component :is="icon" :key="iconKey" />
</template>
<ActionSingle v-for="child in children"
:id="`${$menuID}-child-${child.key}`"
:key="`child-${child.key}`"
:active="currentChild?.key === child.key"
is-item
:action-entry="child"
v-on="$listeners"
@trigged="onTrigger" />
<slot v-bind="{ visible }" name="lastAction" />
</NcActions>
</template>
<script>
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'
export default {
name: 'ActionList',
components: {
NcActions,
ActionSingle,
},
extends: BaseActionEntry,
mixins: [useStore, useOutlineStateMixin, useMenuIDMixin],
data: () => ({
visible: false,
}),
computed: {
currentChild() {
const {
state,
$editor,
actionEntry: { children },
} = this
if (!state.active) {
return null
}
return children.find(child => {
return getIsActive(child, $editor)
})
},
icon() {
if (this.currentChild) {
return this.currentChild.icon
}
return this.actionEntry.icon
},
iconKey() {
return `${this.actionEntry.key}/${this.activeKey}`
},
activeKey() {
return this.currentChild?.key
},
children() {
return this.actionEntry.children.filter(({ visible }) => {
if (visible === undefined) {
return true
}
return typeof visible === 'function'
? visible(this)
: visible
})
},
},
methods: {
onOpenChange(val) {
this.visible = val
},
runAction() {
// nothing todo
},
onTrigger(entry) {
if (entry?.click) {
return
}
this.$editor.chain().focus().run()
this.$emit('trigged', entry)
},
},
}
</script>