mirror of
https://github.com/directus/directus.git
synced 2026-01-26 10:58:14 -05:00
change function parameters and clean code
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div class="v-dialog" ref="dialog">
|
||||
<div class="v-dialog">
|
||||
<slot name="activator" v-bind="{ on: () => (_active = true) }" />
|
||||
|
||||
<portal to="dialog-outlet">
|
||||
@@ -33,16 +33,12 @@ export default defineComponent({
|
||||
},
|
||||
setup(props, { emit }) {
|
||||
const dialog = ref<HTMLElement | null>(null);
|
||||
useShortcut(
|
||||
() => {
|
||||
if (_active.value) {
|
||||
emitToggle();
|
||||
return true;
|
||||
}
|
||||
},
|
||||
ref(document.body),
|
||||
'escape'
|
||||
);
|
||||
useShortcut('escape', () => {
|
||||
if (_active.value) {
|
||||
emitToggle();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
const localActive = ref(false);
|
||||
|
||||
|
||||
@@ -295,11 +295,11 @@ export default defineComponent({
|
||||
});
|
||||
|
||||
useShortcut(
|
||||
'meta+a',
|
||||
() => {
|
||||
onToggleSelectAll(!allItemsSelected.value);
|
||||
},
|
||||
table,
|
||||
'meta+a'
|
||||
table
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { onMounted, onUnmounted, Ref } from '@vue/composition-api';
|
||||
import { onMounted, onUnmounted, Ref, ref } from '@vue/composition-api';
|
||||
import Vue from 'vue';
|
||||
|
||||
type ShortcutHandler = (event: KeyboardEvent) => void | any | boolean;
|
||||
@@ -51,9 +51,9 @@ function callHandlers(event: KeyboardEvent) {
|
||||
}
|
||||
|
||||
export default function useShortcut(
|
||||
shortcuts: string | string[],
|
||||
handler: ShortcutHandler,
|
||||
reference: Ref<HTMLElement | null> | Ref<Vue | null>,
|
||||
...shortcuts: string[]
|
||||
reference: Ref<HTMLElement | null> | Ref<Vue | null> = ref(document.body)
|
||||
) {
|
||||
const callback: ShortcutHandler = (event) => {
|
||||
if (reference.value === null) return;
|
||||
@@ -70,7 +70,7 @@ export default function useShortcut(
|
||||
return false;
|
||||
};
|
||||
onMounted(() => {
|
||||
shortcuts.forEach((shortcut) => {
|
||||
[shortcuts].flat().forEach((shortcut) => {
|
||||
if (handlers.hasOwnProperty(shortcut)) {
|
||||
handlers[shortcut].unshift(callback);
|
||||
} else {
|
||||
@@ -79,7 +79,7 @@ export default function useShortcut(
|
||||
});
|
||||
});
|
||||
onUnmounted(() => {
|
||||
shortcuts.forEach((shortcut) => {
|
||||
[shortcuts].flat().forEach((shortcut) => {
|
||||
if (handlers.hasOwnProperty(shortcut)) {
|
||||
handlers[shortcut] = handlers[shortcut].filter((f) => f !== callback);
|
||||
if (handlers[shortcut].length === 0) {
|
||||
|
||||
@@ -286,8 +286,8 @@ export default defineComponent({
|
||||
return i18n.t('archive');
|
||||
});
|
||||
|
||||
useShortcut(saveAndStay, form, 'meta+s');
|
||||
useShortcut(saveAndAddNew, form, 'meta+shift+s');
|
||||
useShortcut('meta+s', saveAndStay, form);
|
||||
useShortcut('meta+shift+s', saveAndAddNew, form);
|
||||
|
||||
const navigationGuard: NavigationGuard = (to, from, next) => {
|
||||
const hasEdits = Object.keys(edits.value).length > 0;
|
||||
|
||||
@@ -293,7 +293,7 @@ export default defineComponent({
|
||||
|
||||
const { moveToDialogActive, moveToFolder, moving, selectedFolder } = useMovetoFolder();
|
||||
|
||||
useShortcut(saveAndStay, form, 'meta+s');
|
||||
useShortcut('meta+s', saveAndStay, form);
|
||||
|
||||
return {
|
||||
item,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<v-modal
|
||||
:active="active"
|
||||
:active="true"
|
||||
@toggle="cancelField"
|
||||
:title="
|
||||
field === '+'
|
||||
@@ -120,7 +120,6 @@ export default defineComponent({
|
||||
},
|
||||
},
|
||||
setup(props) {
|
||||
const active = ref(true);
|
||||
const collectionsStore = useCollectionsStore();
|
||||
const fieldsStore = useFieldsStore();
|
||||
const relationsStore = useRelationsStore();
|
||||
@@ -163,7 +162,6 @@ export default defineComponent({
|
||||
localType,
|
||||
existingField,
|
||||
collectionInfo,
|
||||
active,
|
||||
};
|
||||
|
||||
function useTabs() {
|
||||
|
||||
@@ -293,8 +293,8 @@ export default defineComponent({
|
||||
return i18n.t('archive');
|
||||
});
|
||||
|
||||
useShortcut(saveAndStay, form, 'meta+s');
|
||||
useShortcut(saveAndAddNew, form, 'meta+shift+s');
|
||||
useShortcut('meta+s', saveAndStay, form);
|
||||
useShortcut('meta+shift+s', saveAndAddNew, form);
|
||||
|
||||
return {
|
||||
title,
|
||||
|
||||
@@ -47,7 +47,7 @@ export default defineComponent({
|
||||
},
|
||||
setup(props) {
|
||||
const textarea = ref<HTMLElement | null>(null);
|
||||
useShortcut(postComment, textarea, 'meta+enter');
|
||||
useShortcut('meta+enter', postComment, textarea);
|
||||
const newCommentContent = ref<string | null>(null);
|
||||
const saving = ref(false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user