2020-10-17 13:12:00 +02:00
|
|
|
<template>
|
2021-10-03 08:39:39 +02:00
|
|
|
<div class="rrevdjwt" :class="{ center: align === 'center' }"
|
2020-10-17 13:12:00 +02:00
|
|
|
ref="items"
|
|
|
|
@contextmenu.self="e => e.preventDefault()"
|
|
|
|
v-hotkey="keymap"
|
|
|
|
>
|
|
|
|
<template v-for="(item, i) in _items">
|
|
|
|
<div v-if="item === null" class="divider"></div>
|
|
|
|
<span v-else-if="item.type === 'label'" class="label item">
|
|
|
|
<span>{{ item.text }}</span>
|
|
|
|
</span>
|
|
|
|
<span v-else-if="item.type === 'pending'" :tabindex="i" class="pending item">
|
|
|
|
<span><MkEllipsis/></span>
|
|
|
|
</span>
|
2020-10-24 18:21:41 +02:00
|
|
|
<MkA v-else-if="item.type === 'link'" :to="item.to" @click.passive="close()" :tabindex="i" class="_button item">
|
2021-04-20 16:22:59 +02:00
|
|
|
<i v-if="item.icon" class="fa-fw" :class="item.icon"></i>
|
2020-10-17 13:12:00 +02:00
|
|
|
<MkAvatar v-if="item.avatar" :user="item.avatar" class="avatar"/>
|
|
|
|
<span>{{ item.text }}</span>
|
2021-04-20 16:22:59 +02:00
|
|
|
<span v-if="item.indicate" class="indicator"><i class="fas fa-circle"></i></span>
|
2020-10-24 18:21:41 +02:00
|
|
|
</MkA>
|
2020-10-17 13:12:00 +02:00
|
|
|
<a v-else-if="item.type === 'a'" :href="item.href" :target="item.target" :download="item.download" @click="close()" :tabindex="i" class="_button item">
|
2021-04-20 16:22:59 +02:00
|
|
|
<i v-if="item.icon" class="fa-fw" :class="item.icon"></i>
|
2020-10-17 13:12:00 +02:00
|
|
|
<span>{{ item.text }}</span>
|
2021-04-20 16:22:59 +02:00
|
|
|
<span v-if="item.indicate" class="indicator"><i class="fas fa-circle"></i></span>
|
2020-10-17 13:12:00 +02:00
|
|
|
</a>
|
2020-11-07 02:54:52 +01:00
|
|
|
<button v-else-if="item.type === 'user'" @click="clicked(item.action, $event)" :tabindex="i" class="_button item">
|
2020-10-17 13:12:00 +02:00
|
|
|
<MkAvatar :user="item.user" class="avatar"/><MkUserName :user="item.user"/>
|
2021-04-20 16:22:59 +02:00
|
|
|
<span v-if="item.indicate" class="indicator"><i class="fas fa-circle"></i></span>
|
2020-10-17 13:12:00 +02:00
|
|
|
</button>
|
2021-10-09 06:12:41 +02:00
|
|
|
<button v-else @click="clicked(item.action, $event)" :tabindex="i" class="_button item" :class="{ danger: item.danger, active: item.active }" :disabled="item.active">
|
2021-04-20 16:22:59 +02:00
|
|
|
<i v-if="item.icon" class="fa-fw" :class="item.icon"></i>
|
2020-10-17 13:12:00 +02:00
|
|
|
<MkAvatar v-if="item.avatar" :user="item.avatar" class="avatar"/>
|
|
|
|
<span>{{ item.text }}</span>
|
2021-04-20 16:22:59 +02:00
|
|
|
<span v-if="item.indicate" class="indicator"><i class="fas fa-circle"></i></span>
|
2020-10-17 13:12:00 +02:00
|
|
|
</button>
|
|
|
|
</template>
|
|
|
|
<span v-if="_items.length === 0" class="none item">
|
2020-12-26 02:47:36 +01:00
|
|
|
<span>{{ $ts.none }}</span>
|
2020-10-17 13:12:00 +02:00
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2021-09-21 14:04:59 +02:00
|
|
|
import { defineComponent, ref, unref } from 'vue';
|
2021-03-23 09:30:14 +01:00
|
|
|
import { focusPrev, focusNext } from '@client/scripts/focus';
|
|
|
|
import contains from '@client/scripts/contains';
|
2020-10-17 13:12:00 +02:00
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
props: {
|
|
|
|
items: {
|
|
|
|
type: Array,
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
viaKeyboard: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
align: {
|
|
|
|
type: String,
|
|
|
|
requried: false
|
2021-08-09 11:01:12 +02:00
|
|
|
},
|
2020-10-17 13:12:00 +02:00
|
|
|
},
|
|
|
|
emits: ['close'],
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
_items: [],
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
keymap(): any {
|
|
|
|
return {
|
|
|
|
'up|k|shift+tab': this.focusUp,
|
|
|
|
'down|j|tab': this.focusDown,
|
|
|
|
'esc': this.close,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
2021-09-21 14:04:59 +02:00
|
|
|
watch: {
|
|
|
|
items: {
|
|
|
|
handler() {
|
|
|
|
const items = ref(unref(this.items).filter(item => item !== undefined));
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2021-09-21 14:04:59 +02:00
|
|
|
for (let i = 0; i < items.value.length; i++) {
|
|
|
|
const item = items.value[i];
|
|
|
|
|
|
|
|
if (item && item.then) { // if item is Promise
|
|
|
|
items.value[i] = { type: 'pending' };
|
|
|
|
item.then(actualItem => {
|
|
|
|
items.value[i] = actualItem;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2021-09-21 14:04:59 +02:00
|
|
|
this._items = items;
|
|
|
|
},
|
|
|
|
immediate: true
|
|
|
|
}
|
2020-10-17 13:12:00 +02:00
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
if (this.viaKeyboard) {
|
|
|
|
this.$nextTick(() => {
|
|
|
|
focusNext(this.$refs.items.children[0], true, false);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.contextmenuEvent) {
|
|
|
|
this.$el.style.top = this.contextmenuEvent.pageY + 'px';
|
|
|
|
this.$el.style.left = this.contextmenuEvent.pageX + 'px';
|
|
|
|
|
|
|
|
for (const el of Array.from(document.querySelectorAll('body *'))) {
|
|
|
|
el.addEventListener('mousedown', this.onMousedown);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
beforeUnmount() {
|
|
|
|
for (const el of Array.from(document.querySelectorAll('body *'))) {
|
|
|
|
el.removeEventListener('mousedown', this.onMousedown);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2020-11-07 02:54:52 +01:00
|
|
|
clicked(fn, ev) {
|
|
|
|
fn(ev);
|
2020-10-17 13:12:00 +02:00
|
|
|
this.close();
|
|
|
|
},
|
|
|
|
close() {
|
|
|
|
this.$emit('close');
|
|
|
|
},
|
|
|
|
focusUp() {
|
|
|
|
focusPrev(document.activeElement);
|
|
|
|
},
|
|
|
|
focusDown() {
|
|
|
|
focusNext(document.activeElement);
|
|
|
|
},
|
|
|
|
onMousedown(e) {
|
|
|
|
if (!contains(this.$el, e.target) && (this.$el != e.target)) this.close();
|
|
|
|
},
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.rrevdjwt {
|
|
|
|
padding: 8px 0;
|
2021-10-03 08:39:39 +02:00
|
|
|
min-width: 200px;
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2021-10-03 08:39:39 +02:00
|
|
|
&.center {
|
2020-10-17 13:12:00 +02:00
|
|
|
> .item {
|
2021-10-03 08:39:39 +02:00
|
|
|
text-align: center;
|
2020-10-17 13:12:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .item {
|
|
|
|
display: block;
|
|
|
|
position: relative;
|
2021-10-15 16:35:28 +02:00
|
|
|
padding: 8px 18px;
|
2020-10-17 13:12:00 +02:00
|
|
|
width: 100%;
|
|
|
|
box-sizing: border-box;
|
|
|
|
white-space: nowrap;
|
|
|
|
font-size: 0.9em;
|
|
|
|
line-height: 20px;
|
2021-10-03 08:39:39 +02:00
|
|
|
text-align: left;
|
2021-03-02 14:57:16 +01:00
|
|
|
overflow: hidden;
|
2020-10-17 13:12:00 +02:00
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
2021-10-03 08:39:39 +02:00
|
|
|
&:before {
|
|
|
|
content: "";
|
|
|
|
display: block;
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
right: 0;
|
|
|
|
margin: auto;
|
2021-10-15 16:33:27 +02:00
|
|
|
width: calc(100% - 16px);
|
2021-10-03 08:39:39 +02:00
|
|
|
height: 100%;
|
2021-10-15 16:33:27 +02:00
|
|
|
border-radius: 6px;
|
2021-10-03 08:39:39 +02:00
|
|
|
}
|
|
|
|
|
2021-10-09 06:12:41 +02:00
|
|
|
> * {
|
|
|
|
position: relative;
|
|
|
|
}
|
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
&.danger {
|
|
|
|
color: #ff2a2a;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
color: #fff;
|
2021-10-03 08:39:39 +02:00
|
|
|
|
|
|
|
&:before {
|
|
|
|
background: #ff4242;
|
|
|
|
}
|
2020-10-17 13:12:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
&:active {
|
|
|
|
color: #fff;
|
2021-10-03 08:39:39 +02:00
|
|
|
|
|
|
|
&:before {
|
|
|
|
background: #d42e2e;
|
|
|
|
}
|
2020-10-17 13:12:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-09 06:12:41 +02:00
|
|
|
&.active {
|
|
|
|
color: var(--fgOnAccent);
|
|
|
|
opacity: 1;
|
|
|
|
|
|
|
|
&:before {
|
|
|
|
background: var(--accent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&:not(:disabled):hover {
|
2021-10-03 08:39:39 +02:00
|
|
|
color: var(--accent);
|
2020-10-17 13:12:00 +02:00
|
|
|
text-decoration: none;
|
2021-10-03 08:39:39 +02:00
|
|
|
|
|
|
|
&:before {
|
|
|
|
background: var(--accentedBg);
|
|
|
|
}
|
2020-10-17 13:12:00 +02:00
|
|
|
}
|
|
|
|
|
2021-10-02 19:46:58 +02:00
|
|
|
&:not(:active):focus-visible {
|
2020-10-17 13:12:00 +02:00
|
|
|
box-shadow: 0 0 0 2px var(--focus) inset;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.label {
|
|
|
|
pointer-events: none;
|
|
|
|
font-size: 0.7em;
|
|
|
|
padding-bottom: 4px;
|
|
|
|
|
|
|
|
> span {
|
|
|
|
opacity: 0.7;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&.pending {
|
|
|
|
pointer-events: none;
|
|
|
|
opacity: 0.7;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.none {
|
|
|
|
pointer-events: none;
|
|
|
|
opacity: 0.7;
|
|
|
|
}
|
|
|
|
|
2021-04-20 16:22:59 +02:00
|
|
|
> i {
|
2021-10-15 16:35:28 +02:00
|
|
|
margin-right: 5px;
|
2020-10-17 13:12:00 +02:00
|
|
|
width: 20px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .avatar {
|
2021-10-15 16:35:28 +02:00
|
|
|
margin-right: 5px;
|
2020-10-17 13:12:00 +02:00
|
|
|
width: 20px;
|
|
|
|
height: 20px;
|
|
|
|
}
|
|
|
|
|
2021-04-20 16:22:59 +02:00
|
|
|
> .indicator {
|
2020-10-17 13:12:00 +02:00
|
|
|
position: absolute;
|
|
|
|
top: 5px;
|
|
|
|
left: 13px;
|
|
|
|
color: var(--indicator);
|
|
|
|
font-size: 12px;
|
|
|
|
animation: blink 1s infinite;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .divider {
|
|
|
|
margin: 8px 0;
|
|
|
|
height: 1px;
|
|
|
|
background: var(--divider);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|