@maas/vue-equipment 0.22.4 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/nuxt/module.json +1 -1
- package/dist/plugins/MagicCommand/demo/DefaultView.vue +8 -3
- package/dist/plugins/MagicCommand/demo/DefaultView.vue.d.ts +1 -0
- package/dist/plugins/MagicCommand/demo/ProjectView.vue +11 -1
- package/dist/plugins/MagicCommand/demo/ProjectView.vue.d.ts +13 -1
- package/dist/plugins/MagicCommand/index.mjs +6 -2
- package/dist/plugins/MagicCommand/src/components/MagicCommandDrawer.vue +48 -0
- package/dist/plugins/MagicCommand/src/components/MagicCommandDrawer.vue.d.ts +24 -0
- package/dist/plugins/MagicCommand/src/components/MagicCommandItem.vue +0 -1
- package/dist/plugins/MagicCommand/src/components/MagicCommandModal.vue +48 -0
- package/dist/plugins/MagicCommand/src/components/MagicCommandModal.vue.d.ts +24 -0
- package/dist/plugins/MagicCommand/src/components/MagicCommandProvider.vue +69 -0
- package/dist/plugins/MagicCommand/src/components/{MagicCommand.vue.d.ts → MagicCommandProvider.vue.d.ts} +0 -3
- package/dist/plugins/MagicCommand/src/composables/private/useCommandStore.mjs +19 -13
- package/dist/plugins/MagicCommand/src/types/index.d.ts +6 -13
- package/dist/plugins/MagicCommand/src/utils/defaultOptions.mjs +0 -13
- package/dist/plugins/MagicDrawer/index.d.ts +2 -2
- package/dist/plugins/MagicDrawer/src/types/index.d.ts +2 -5
- package/dist/plugins/MagicModal/index.d.ts +2 -2
- package/dist/plugins/MagicModal/src/types/index.d.ts +2 -2
- package/package.json +1 -1
- package/dist/plugins/MagicCommand/src/components/MagicCommand.vue +0 -179
- package/dist/plugins/MagicCommand/src/composables/private/useCommandCallback.d.ts +0 -22
- package/dist/plugins/MagicCommand/src/composables/private/useCommandCallback.mjs +0 -61
package/dist/nuxt/module.json
CHANGED
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
<magic-command-view
|
|
3
3
|
id="default-view"
|
|
4
4
|
:default="true"
|
|
5
|
-
class="
|
|
5
|
+
:class="{
|
|
6
|
+
'w-[40rem] max-h-[30rem] rounded-xl overflow-hidden': isModal,
|
|
7
|
+
'w-full h-full': !isModal,
|
|
8
|
+
}"
|
|
9
|
+
class="bg-neutral-800 border border-solid border-neutral-600 flex flex-col"
|
|
6
10
|
>
|
|
7
11
|
<magic-command-head class="px-2 pt-2">
|
|
8
12
|
<div class="w-full border border-neutral-600 p-3 border-b-solid">
|
|
@@ -11,7 +15,7 @@
|
|
|
11
15
|
</magic-command-head>
|
|
12
16
|
<magic-command-body class="h-full py-2">
|
|
13
17
|
<magic-command-group>
|
|
14
|
-
<
|
|
18
|
+
<span class="p-4 text-xs text-neutral-600">Suggestions</span>
|
|
15
19
|
<magic-command-item
|
|
16
20
|
v-slot="{ isActive }"
|
|
17
21
|
:default="true"
|
|
@@ -26,7 +30,7 @@
|
|
|
26
30
|
</magic-command-item>
|
|
27
31
|
</magic-command-group>
|
|
28
32
|
<magic-command-group>
|
|
29
|
-
<
|
|
33
|
+
<span class="p-4 text-xs text-neutral-600">Filter</span>
|
|
30
34
|
<magic-command-item
|
|
31
35
|
v-slot="{ isActive }"
|
|
32
36
|
v-if="dynamic"
|
|
@@ -54,6 +58,7 @@ import DemoItem from './DemoItem.vue'
|
|
|
54
58
|
|
|
55
59
|
interface Props {
|
|
56
60
|
hasDynamicItem?: boolean
|
|
61
|
+
isModal?: boolean
|
|
57
62
|
}
|
|
58
63
|
|
|
59
64
|
defineProps<Props>()
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
interface Props {
|
|
2
2
|
hasDynamicItem?: boolean;
|
|
3
|
+
isModal?: boolean;
|
|
3
4
|
}
|
|
4
5
|
declare const _default: import("vue").DefineComponent<__VLS_TypePropsToRuntimeProps<Props>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<Props>>>, {}, {}>;
|
|
5
6
|
export default _default;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<magic-command-view
|
|
3
3
|
id="project-view"
|
|
4
|
-
class="
|
|
4
|
+
:class="{
|
|
5
|
+
'w-[40rem] max-h-[30rem] rounded-xl': isModal,
|
|
6
|
+
'w-full h-full': !isModal,
|
|
7
|
+
}"
|
|
8
|
+
class="bg-neutral-800 border border-solid border-neutral-600 overflow-hidden flex flex-col"
|
|
5
9
|
>
|
|
6
10
|
<magic-command-head class="p-2">
|
|
7
11
|
<div class="w-full border border-neutral-600 p-3 border-b-solid">
|
|
@@ -42,6 +46,12 @@ import { useCommandApi, CommandInstanceId } from '@maas/vue-equipment/plugins'
|
|
|
42
46
|
|
|
43
47
|
import DemoItem from './DemoItem.vue'
|
|
44
48
|
|
|
49
|
+
interface Props {
|
|
50
|
+
isModal?: boolean
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
defineProps<Props>()
|
|
54
|
+
|
|
45
55
|
const commandId = inject(CommandInstanceId, '')
|
|
46
56
|
|
|
47
57
|
const commandApi = useCommandApi(commandId)
|
|
@@ -1,2 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
interface Props {
|
|
2
|
+
isModal?: boolean;
|
|
3
|
+
}
|
|
4
|
+
declare const _default: import("vue").DefineComponent<__VLS_TypePropsToRuntimeProps<Props>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<Props>>>, {}, {}>;
|
|
2
5
|
export default _default;
|
|
6
|
+
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
7
|
+
type __VLS_TypePropsToRuntimeProps<T> = {
|
|
8
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
9
|
+
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
10
|
+
} : {
|
|
11
|
+
type: import('vue').PropType<T[K]>;
|
|
12
|
+
required: true;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
@@ -1,21 +1,25 @@
|
|
|
1
|
-
import MagicCommand from "./src/components/MagicCommand.vue";
|
|
2
1
|
import MagicCommandBody from "./src/components/MagicCommandBody.vue";
|
|
2
|
+
import MagicCommandDrawer from "./src/components/MagicCommandDrawer.vue";
|
|
3
3
|
import MagicCommandFooter from "./src/components/MagicCommandFooter.vue";
|
|
4
4
|
import MagicCommandGroup from "./src/components/MagicCommandGroup.vue";
|
|
5
5
|
import MagicCommandHead from "./src/components/MagicCommandHead.vue";
|
|
6
6
|
import MagicCommandItem from "./src/components/MagicCommandItem.vue";
|
|
7
|
+
import MagicCommandModal from "./src/components/MagicCommandModal.vue";
|
|
8
|
+
import MagicCommandProvider from "./src/components/MagicCommandProvider.vue";
|
|
7
9
|
import MagicCommandView from "./src/components/MagicCommandView.vue";
|
|
8
10
|
import { useCommandApi } from "./src/composables/useCommandApi.mjs";
|
|
9
11
|
import { useCommandEmitter } from "./src/composables/useCommandEmitter.mjs";
|
|
10
12
|
import { CommandInstanceId, CommandOptionsKey } from "./src/symbols/index.mjs";
|
|
11
13
|
const MagicCommandPlugin = {
|
|
12
14
|
install: (app) => {
|
|
13
|
-
app.component("MagicCommand", MagicCommand);
|
|
14
15
|
app.component("MagicCommandBody", MagicCommandBody);
|
|
16
|
+
app.component("MagicCommandDrawer", MagicCommandDrawer);
|
|
15
17
|
app.component("MagicCommandFooter", MagicCommandFooter);
|
|
16
18
|
app.component("MagicCommandGroup", MagicCommandGroup);
|
|
17
19
|
app.component("MagicCommandHead", MagicCommandHead);
|
|
18
20
|
app.component("MagicCommandItem", MagicCommandItem);
|
|
21
|
+
app.component("MagicCommandModal", MagicCommandModal);
|
|
22
|
+
app.component("MagicCommandProvider", MagicCommandProvider);
|
|
19
23
|
app.component("MagicCommandView", MagicCommandView);
|
|
20
24
|
}
|
|
21
25
|
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<magic-drawer
|
|
3
|
+
:id="commandId"
|
|
4
|
+
class="magic-command-drawer"
|
|
5
|
+
:class="props.class"
|
|
6
|
+
:options="options"
|
|
7
|
+
>
|
|
8
|
+
<slot />
|
|
9
|
+
</magic-drawer>
|
|
10
|
+
</template>
|
|
11
|
+
|
|
12
|
+
<script setup lang="ts">
|
|
13
|
+
import { inject, watch, onBeforeUnmount, type MaybeRef } from 'vue'
|
|
14
|
+
import { useDrawerApi, useDrawerEmitter } from '../../../MagicDrawer'
|
|
15
|
+
import { useCommandApi } from './../composables/useCommandApi'
|
|
16
|
+
import { CommandInstanceId } from './../symbols'
|
|
17
|
+
|
|
18
|
+
import type { CommandDrawerOptions } from '../types'
|
|
19
|
+
|
|
20
|
+
interface MagicCommandProps {
|
|
21
|
+
class?: MaybeRef<string>
|
|
22
|
+
options?: CommandDrawerOptions
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const props = defineProps<MagicCommandProps>()
|
|
26
|
+
|
|
27
|
+
const commandId = inject(CommandInstanceId, '')
|
|
28
|
+
|
|
29
|
+
function afterLeaveCallback() {
|
|
30
|
+
close()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const { close, isActive } = useCommandApi(commandId)
|
|
34
|
+
|
|
35
|
+
watch(isActive, (value) => {
|
|
36
|
+
if (value) {
|
|
37
|
+
useDrawerApi(commandId).open()
|
|
38
|
+
} else {
|
|
39
|
+
useDrawerApi(commandId).close()
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
useDrawerEmitter().on('afterLeave', afterLeaveCallback)
|
|
44
|
+
|
|
45
|
+
onBeforeUnmount(() => {
|
|
46
|
+
useDrawerEmitter().off('afterLeave', afterLeaveCallback)
|
|
47
|
+
})
|
|
48
|
+
</script>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type MaybeRef } from 'vue';
|
|
2
|
+
import type { CommandDrawerOptions } from '../types';
|
|
3
|
+
interface MagicCommandProps {
|
|
4
|
+
class?: MaybeRef<string>;
|
|
5
|
+
options?: CommandDrawerOptions;
|
|
6
|
+
}
|
|
7
|
+
declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__VLS_TypePropsToRuntimeProps<MagicCommandProps>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<MagicCommandProps>>>, {}, {}>, {
|
|
8
|
+
default?(_: {}): any;
|
|
9
|
+
}>;
|
|
10
|
+
export default _default;
|
|
11
|
+
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
12
|
+
type __VLS_TypePropsToRuntimeProps<T> = {
|
|
13
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
14
|
+
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
15
|
+
} : {
|
|
16
|
+
type: import('vue').PropType<T[K]>;
|
|
17
|
+
required: true;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
21
|
+
new (): {
|
|
22
|
+
$slots: S;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<magic-modal
|
|
3
|
+
:id="commandId"
|
|
4
|
+
class="magic-command-modal"
|
|
5
|
+
:class="props.class"
|
|
6
|
+
:options="options"
|
|
7
|
+
>
|
|
8
|
+
<slot />
|
|
9
|
+
</magic-modal>
|
|
10
|
+
</template>
|
|
11
|
+
|
|
12
|
+
<script setup lang="ts">
|
|
13
|
+
import { inject, watch, onBeforeUnmount, type MaybeRef } from 'vue'
|
|
14
|
+
import { useModalApi, useModalEmitter } from '../../../MagicModal'
|
|
15
|
+
import { useCommandApi } from './../composables/useCommandApi'
|
|
16
|
+
import { CommandInstanceId } from './../symbols'
|
|
17
|
+
|
|
18
|
+
import type { CommandModalOptions } from '../types'
|
|
19
|
+
|
|
20
|
+
interface MagicCommandProps {
|
|
21
|
+
class?: MaybeRef<string>
|
|
22
|
+
options?: CommandModalOptions
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const props = defineProps<MagicCommandProps>()
|
|
26
|
+
|
|
27
|
+
const commandId = inject(CommandInstanceId, '')
|
|
28
|
+
|
|
29
|
+
function afterLeaveCallback() {
|
|
30
|
+
close()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const { close, isActive } = useCommandApi(commandId)
|
|
34
|
+
|
|
35
|
+
watch(isActive, (value) => {
|
|
36
|
+
if (value) {
|
|
37
|
+
useModalApi(commandId).open()
|
|
38
|
+
} else {
|
|
39
|
+
useModalApi(commandId).close()
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
useModalEmitter().on('afterLeave', afterLeaveCallback)
|
|
44
|
+
|
|
45
|
+
onBeforeUnmount(() => {
|
|
46
|
+
useModalEmitter().off('afterLeave', afterLeaveCallback)
|
|
47
|
+
})
|
|
48
|
+
</script>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type MaybeRef } from 'vue';
|
|
2
|
+
import type { CommandModalOptions } from '../types';
|
|
3
|
+
interface MagicCommandProps {
|
|
4
|
+
class?: MaybeRef<string>;
|
|
5
|
+
options?: CommandModalOptions;
|
|
6
|
+
}
|
|
7
|
+
declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__VLS_TypePropsToRuntimeProps<MagicCommandProps>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<MagicCommandProps>>>, {}, {}>, {
|
|
8
|
+
default?(_: {}): any;
|
|
9
|
+
}>;
|
|
10
|
+
export default _default;
|
|
11
|
+
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
12
|
+
type __VLS_TypePropsToRuntimeProps<T> = {
|
|
13
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
14
|
+
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
15
|
+
} : {
|
|
16
|
+
type: import('vue').PropType<T[K]>;
|
|
17
|
+
required: true;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
21
|
+
new (): {
|
|
22
|
+
$slots: S;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="magic-command-provider">
|
|
3
|
+
<slot />
|
|
4
|
+
</div>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script setup lang="ts">
|
|
8
|
+
import { watch, provide, onBeforeUnmount, type MaybeRef } from 'vue'
|
|
9
|
+
import { createDefu } from 'defu'
|
|
10
|
+
import { useMagicKeys } from '@vueuse/core'
|
|
11
|
+
import { defaultOptions } from './../utils/defaultOptions'
|
|
12
|
+
import { useCommandApi } from './../composables/useCommandApi'
|
|
13
|
+
import { CommandInstanceId, CommandOptionsKey } from './../symbols'
|
|
14
|
+
|
|
15
|
+
import type { CommandOptions } from './../types/index'
|
|
16
|
+
|
|
17
|
+
import '@maas/vue-equipment/utils/css/animations/fade-in.css'
|
|
18
|
+
import '@maas/vue-equipment/utils/css/animations/fade-out.css'
|
|
19
|
+
|
|
20
|
+
// Prevent keys arrays from being merged with default
|
|
21
|
+
const customDefu = createDefu((obj, key, value) => {
|
|
22
|
+
if (key === 'open' || key === 'close' || key === 'next' || key === 'prev') {
|
|
23
|
+
obj[key] = value
|
|
24
|
+
return true
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
interface MagicCommandProps {
|
|
29
|
+
id: MaybeRef<string>
|
|
30
|
+
options?: CommandOptions
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const props = withDefaults(defineProps<MagicCommandProps>(), {
|
|
34
|
+
options: () => defaultOptions,
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
const keys = useMagicKeys()
|
|
38
|
+
const commandApi = useCommandApi(props.id)
|
|
39
|
+
const mappedOptions = customDefu(props.options, defaultOptions)
|
|
40
|
+
|
|
41
|
+
const { open, close } = commandApi
|
|
42
|
+
|
|
43
|
+
if (mappedOptions.keys?.open) {
|
|
44
|
+
for (const key of mappedOptions.keys.open) {
|
|
45
|
+
watch(keys[key], (value) => {
|
|
46
|
+
if (value) {
|
|
47
|
+
open()
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (mappedOptions.keys?.close) {
|
|
54
|
+
for (const key of mappedOptions.keys.close) {
|
|
55
|
+
watch(keys[key], (value) => {
|
|
56
|
+
if (value) {
|
|
57
|
+
close()
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
onBeforeUnmount(() => {
|
|
64
|
+
close()
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
provide(CommandInstanceId, props.id)
|
|
68
|
+
provide(CommandOptionsKey, mappedOptions)
|
|
69
|
+
</script>
|
|
@@ -4,8 +4,6 @@ import '@maas/vue-equipment/utils/css/animations/fade-in.css';
|
|
|
4
4
|
import '@maas/vue-equipment/utils/css/animations/fade-out.css';
|
|
5
5
|
interface MagicCommandProps {
|
|
6
6
|
id: MaybeRef<string>;
|
|
7
|
-
class?: MaybeRef<string>;
|
|
8
|
-
props?: Record<string, unknown>;
|
|
9
7
|
options?: CommandOptions;
|
|
10
8
|
}
|
|
11
9
|
declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<MagicCommandProps>, {
|
|
@@ -15,7 +13,6 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
|
|
|
15
13
|
}>>>, {
|
|
16
14
|
options: CommandOptions;
|
|
17
15
|
}, {}>, {
|
|
18
|
-
backdrop?(_: {}): any;
|
|
19
16
|
default?(_: {}): any;
|
|
20
17
|
}>;
|
|
21
18
|
export default _default;
|
|
@@ -17,34 +17,40 @@ export function useCommandStore() {
|
|
|
17
17
|
}
|
|
18
18
|
function sortItems(id, parent) {
|
|
19
19
|
const instance = findInstance(id);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
item
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
if (instance) {
|
|
21
|
+
const itemElements = parent.querySelectorAll("[data-item-id]");
|
|
22
|
+
itemElements.forEach((el, index) => {
|
|
23
|
+
const itemId = el.dataset.itemId;
|
|
24
|
+
const item = instance.items?.find((item2) => item2.id === itemId);
|
|
25
|
+
if (item) {
|
|
26
|
+
item.index = index;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
instance.items?.sort((a, b) => a.index - b.index);
|
|
30
|
+
}
|
|
29
31
|
}
|
|
30
32
|
function addItem(id, item) {
|
|
31
33
|
const instance = findInstance(id);
|
|
32
|
-
instance
|
|
34
|
+
if (instance) {
|
|
35
|
+
instance.items?.push({ index: -1, id: item });
|
|
36
|
+
}
|
|
33
37
|
}
|
|
34
38
|
function removeItem(id, item) {
|
|
35
39
|
const instance = findInstance(id);
|
|
36
40
|
if (instance) {
|
|
37
|
-
instance.items = instance.items
|
|
41
|
+
instance.items = instance.items?.filter((x) => x.id !== item);
|
|
38
42
|
}
|
|
39
43
|
}
|
|
40
44
|
function addView(id, view) {
|
|
41
45
|
const instance = findInstance(id);
|
|
42
|
-
instance
|
|
46
|
+
if (instance) {
|
|
47
|
+
instance.views?.push(view);
|
|
48
|
+
}
|
|
43
49
|
}
|
|
44
50
|
function removeView(id, view) {
|
|
45
51
|
const instance = findInstance(id);
|
|
46
52
|
if (instance) {
|
|
47
|
-
instance.views = instance.views
|
|
53
|
+
instance.views = instance.views?.filter((x) => x !== view);
|
|
48
54
|
}
|
|
49
55
|
}
|
|
50
56
|
return {
|
|
@@ -1,17 +1,6 @@
|
|
|
1
|
+
import type { ModalOptions } from '../../../MagicModal.js';
|
|
2
|
+
import type { DrawerOptions } from '../../../MagicDrawer.js';
|
|
1
3
|
export type CommandOptions = {
|
|
2
|
-
backdrop?: boolean;
|
|
3
|
-
focusTrap?: boolean;
|
|
4
|
-
scrollLock?: boolean;
|
|
5
|
-
scrollLockPadding?: boolean;
|
|
6
|
-
teleport?: {
|
|
7
|
-
target?: string;
|
|
8
|
-
disabled?: boolean;
|
|
9
|
-
};
|
|
10
|
-
transitions?: {
|
|
11
|
-
content?: string;
|
|
12
|
-
backdrop?: string;
|
|
13
|
-
};
|
|
14
|
-
tag?: 'dialog' | 'div';
|
|
15
4
|
keys?: {
|
|
16
5
|
open?: string[] | false;
|
|
17
6
|
close?: string[] | false;
|
|
@@ -28,3 +17,7 @@ export type CommandEvents = {
|
|
|
28
17
|
leave: string;
|
|
29
18
|
afterLeave: string;
|
|
30
19
|
};
|
|
20
|
+
export interface CommandModalOptions extends ModalOptions {
|
|
21
|
+
}
|
|
22
|
+
export interface CommandDrawerOptions extends DrawerOptions {
|
|
23
|
+
}
|
|
@@ -1,17 +1,4 @@
|
|
|
1
1
|
const defaultOptions = {
|
|
2
|
-
backdrop: true,
|
|
3
|
-
focusTrap: true,
|
|
4
|
-
scrollLock: true,
|
|
5
|
-
scrollLockPadding: true,
|
|
6
|
-
teleport: {
|
|
7
|
-
target: "body",
|
|
8
|
-
disabled: false
|
|
9
|
-
},
|
|
10
|
-
transitions: {
|
|
11
|
-
content: "magic-command--content",
|
|
12
|
-
backdrop: "magic-command--backdrop"
|
|
13
|
-
},
|
|
14
|
-
tag: "dialog",
|
|
15
2
|
keys: {
|
|
16
3
|
open: ["Cmd+k"],
|
|
17
4
|
close: ["Escape"],
|
|
@@ -2,7 +2,7 @@ import MagicDrawer from './src/components/MagicDrawer.vue.js';
|
|
|
2
2
|
import { useDrawerApi } from './src/composables/useDrawerApi.js';
|
|
3
3
|
import { useDrawerEmitter } from './src/composables/useDrawerEmitter.js';
|
|
4
4
|
import type { Plugin } from 'vue';
|
|
5
|
-
import type { DrawerEvents } from './src/types/index.js';
|
|
5
|
+
import type { DrawerEvents, DrawerOptions } from './src/types/index.js';
|
|
6
6
|
declare const MagicDrawerPlugin: Plugin;
|
|
7
7
|
export { MagicDrawerPlugin, MagicDrawer, useDrawerApi, useDrawerEmitter };
|
|
8
|
-
export type { DrawerEvents };
|
|
8
|
+
export type { DrawerEvents, DrawerOptions };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type SnapPoint = number | `${string}px`;
|
|
2
|
-
export
|
|
2
|
+
export interface DrawerOptions {
|
|
3
3
|
position?: 'top' | 'right' | 'bottom' | 'left';
|
|
4
4
|
backdrop?: boolean;
|
|
5
5
|
focusTrap?: boolean;
|
|
@@ -31,7 +31,7 @@ export type DrawerOptions = {
|
|
|
31
31
|
initial?: SnapPoint;
|
|
32
32
|
};
|
|
33
33
|
canClose?: boolean;
|
|
34
|
-
}
|
|
34
|
+
}
|
|
35
35
|
export type DrawerEvents = {
|
|
36
36
|
beforeEnter: string;
|
|
37
37
|
enter: string;
|
|
@@ -67,6 +67,3 @@ export type DrawerEvents = {
|
|
|
67
67
|
y: number;
|
|
68
68
|
};
|
|
69
69
|
};
|
|
70
|
-
export interface CustomMouseEvent extends MouseEvent {
|
|
71
|
-
custom?: string;
|
|
72
|
-
}
|
|
@@ -2,7 +2,7 @@ import MagicModal from './src/components/MagicModal.vue.js';
|
|
|
2
2
|
import { useModalApi } from './src/composables/useModalApi.js';
|
|
3
3
|
import { useModalEmitter } from './src/composables/useModalEmitter.js';
|
|
4
4
|
import type { Plugin } from 'vue';
|
|
5
|
-
import type { ModalEvents } from './src/types/index.js';
|
|
5
|
+
import type { ModalEvents, ModalOptions } from './src/types/index.js';
|
|
6
6
|
declare const MagicModalPlugin: Plugin;
|
|
7
7
|
export { MagicModalPlugin, MagicModal, useModalEmitter, useModalApi };
|
|
8
|
-
export type { ModalEvents };
|
|
8
|
+
export type { ModalEvents, ModalOptions };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export interface ModalOptions {
|
|
2
2
|
backdrop?: boolean;
|
|
3
3
|
focusTrap?: boolean;
|
|
4
4
|
scrollLock?: boolean;
|
|
@@ -13,7 +13,7 @@ export type ModalOptions = {
|
|
|
13
13
|
};
|
|
14
14
|
tag?: 'dialog' | 'div';
|
|
15
15
|
keys?: string[] | false;
|
|
16
|
-
}
|
|
16
|
+
}
|
|
17
17
|
export type ModalEvents = {
|
|
18
18
|
beforeEnter: string;
|
|
19
19
|
enter: string;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maas/vue-equipment",
|
|
3
3
|
"description": "A magic collection of Vue composables, plugins, components and directives",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.23.0",
|
|
5
5
|
"author": "Robin Scholz <https://github.com/robinscholz>, Christoph Jeworutzki <https://github.com/ChristophJeworutzki>",
|
|
6
6
|
"devDependencies": {
|
|
7
7
|
"@antfu/ni": "^0.21.12",
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<teleport
|
|
3
|
-
v-if="wrapperActive"
|
|
4
|
-
:to="mappedOptions.teleport?.target"
|
|
5
|
-
:disabled="mappedOptions.teleport?.disabled"
|
|
6
|
-
>
|
|
7
|
-
<component
|
|
8
|
-
:is="mappedOptions.tag"
|
|
9
|
-
ref="commandRef"
|
|
10
|
-
class="magic-command"
|
|
11
|
-
:id="toValue(id)"
|
|
12
|
-
:class="toValue(props.class)"
|
|
13
|
-
aria-command="true"
|
|
14
|
-
>
|
|
15
|
-
<transition
|
|
16
|
-
v-if="mappedOptions.backdrop || !!$slots.backdrop"
|
|
17
|
-
:name="mappedOptions.transitions?.backdrop"
|
|
18
|
-
>
|
|
19
|
-
<div
|
|
20
|
-
v-show="innerActive"
|
|
21
|
-
class="magic-command__backdrop"
|
|
22
|
-
@click.self="close"
|
|
23
|
-
>
|
|
24
|
-
<slot name="backdrop" />
|
|
25
|
-
</div>
|
|
26
|
-
</transition>
|
|
27
|
-
<transition
|
|
28
|
-
:name="mappedOptions.transitions?.content"
|
|
29
|
-
@before-leave="onBeforeLeave"
|
|
30
|
-
@leave="onLeave"
|
|
31
|
-
@after-leave="onAfterLeave"
|
|
32
|
-
@before-enter="onBeforeEnter"
|
|
33
|
-
@enter="onEnter"
|
|
34
|
-
@after-enter="onAfterEnter"
|
|
35
|
-
>
|
|
36
|
-
<div
|
|
37
|
-
v-show="innerActive"
|
|
38
|
-
class="magic-command__content"
|
|
39
|
-
@click.self="close"
|
|
40
|
-
>
|
|
41
|
-
<slot />
|
|
42
|
-
</div>
|
|
43
|
-
</transition>
|
|
44
|
-
</component>
|
|
45
|
-
</teleport>
|
|
46
|
-
</template>
|
|
47
|
-
|
|
48
|
-
<script setup lang="ts">
|
|
49
|
-
import {
|
|
50
|
-
ref,
|
|
51
|
-
watch,
|
|
52
|
-
nextTick,
|
|
53
|
-
toValue,
|
|
54
|
-
onBeforeUnmount,
|
|
55
|
-
provide,
|
|
56
|
-
type MaybeRef,
|
|
57
|
-
} from 'vue'
|
|
58
|
-
import { createDefu } from 'defu'
|
|
59
|
-
import { useMagicKeys } from '@vueuse/core'
|
|
60
|
-
import { defaultOptions } from './../utils/defaultOptions'
|
|
61
|
-
import { useCommandApi } from './../composables/useCommandApi'
|
|
62
|
-
import { useCommandCallback } from '../composables/private/useCommandCallback'
|
|
63
|
-
import { CommandInstanceId, CommandOptionsKey } from './../symbols'
|
|
64
|
-
|
|
65
|
-
import type { CommandOptions } from './../types/index'
|
|
66
|
-
|
|
67
|
-
import '@maas/vue-equipment/utils/css/animations/fade-in.css'
|
|
68
|
-
import '@maas/vue-equipment/utils/css/animations/fade-out.css'
|
|
69
|
-
|
|
70
|
-
// Prevent keys arrays from being merged with default
|
|
71
|
-
const customDefu = createDefu((obj, key, value) => {
|
|
72
|
-
if (key === 'open' || key === 'close' || key === 'next' || key === 'prev') {
|
|
73
|
-
obj[key] = value
|
|
74
|
-
return true
|
|
75
|
-
}
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
interface MagicCommandProps {
|
|
79
|
-
id: MaybeRef<string>
|
|
80
|
-
class?: MaybeRef<string>
|
|
81
|
-
props?: Record<string, unknown>
|
|
82
|
-
options?: CommandOptions
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const props = withDefaults(defineProps<MagicCommandProps>(), {
|
|
86
|
-
options: () => defaultOptions,
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
const keys = useMagicKeys()
|
|
90
|
-
const commandRef = ref<HTMLElement | undefined>(undefined)
|
|
91
|
-
const commandApi = useCommandApi(props.id, { focusTarget: commandRef })
|
|
92
|
-
const mappedOptions = customDefu(props.options, defaultOptions)
|
|
93
|
-
|
|
94
|
-
const {
|
|
95
|
-
isActive,
|
|
96
|
-
open,
|
|
97
|
-
close,
|
|
98
|
-
trapFocus,
|
|
99
|
-
releaseFocus,
|
|
100
|
-
lockScroll,
|
|
101
|
-
unlockScroll,
|
|
102
|
-
addScrollLockPadding,
|
|
103
|
-
removeScrollLockPadding,
|
|
104
|
-
} = commandApi
|
|
105
|
-
|
|
106
|
-
// Split isActive into two values to animate command smoothly
|
|
107
|
-
const innerActive = ref(false)
|
|
108
|
-
const wrapperActive = ref(false)
|
|
109
|
-
|
|
110
|
-
const {
|
|
111
|
-
onBeforeEnter,
|
|
112
|
-
onEnter,
|
|
113
|
-
onAfterEnter,
|
|
114
|
-
onBeforeLeave,
|
|
115
|
-
onLeave,
|
|
116
|
-
onAfterLeave,
|
|
117
|
-
} = useCommandCallback({
|
|
118
|
-
id: props.id,
|
|
119
|
-
mappedOptions,
|
|
120
|
-
addScrollLockPadding,
|
|
121
|
-
removeScrollLockPadding,
|
|
122
|
-
lockScroll,
|
|
123
|
-
unlockScroll,
|
|
124
|
-
trapFocus,
|
|
125
|
-
releaseFocus,
|
|
126
|
-
wrapperActive,
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
// Handle state
|
|
130
|
-
async function onOpen() {
|
|
131
|
-
wrapperActive.value = true
|
|
132
|
-
await nextTick()
|
|
133
|
-
innerActive.value = true
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function onClose() {
|
|
137
|
-
innerActive.value = false
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (mappedOptions.keys?.open) {
|
|
141
|
-
for (const key of mappedOptions.keys.open) {
|
|
142
|
-
watch(keys[key], (value) => {
|
|
143
|
-
if (value) {
|
|
144
|
-
open()
|
|
145
|
-
}
|
|
146
|
-
})
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if (mappedOptions.keys?.close) {
|
|
151
|
-
for (const key of mappedOptions.keys.close) {
|
|
152
|
-
watch(keys[key], (value) => {
|
|
153
|
-
if (value) {
|
|
154
|
-
close()
|
|
155
|
-
}
|
|
156
|
-
})
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
watch(isActive, async (value) => {
|
|
161
|
-
if (value) {
|
|
162
|
-
await onOpen()
|
|
163
|
-
} else {
|
|
164
|
-
onClose()
|
|
165
|
-
}
|
|
166
|
-
})
|
|
167
|
-
|
|
168
|
-
// Reset state on unmount
|
|
169
|
-
onBeforeUnmount(() => {
|
|
170
|
-
close()
|
|
171
|
-
})
|
|
172
|
-
|
|
173
|
-
provide(CommandInstanceId, props.id)
|
|
174
|
-
provide(CommandOptionsKey, mappedOptions)
|
|
175
|
-
</script>
|
|
176
|
-
|
|
177
|
-
<style>
|
|
178
|
-
:root{--magic-command-z-index:999;--magic-command-backdrop-color:rgba(0,0,0,.5);--magic-command-backdrop-filter:unset;--magic-command-content-align-items:center;--magic-command-content-justify-content:center;--magic-command-content-overflow-y:auto}@keyframes magic-command-content-enter{0%{opacity:0;transform:translateY(2rem)}to{opacity:1;transform:translateY(0)}}@keyframes magic-command-content-leave{0%{opacity:1;transform:scale(1)}to{opacity:0;transform:scale(1.02)}}.magic-command{align-items:center;background:transparent;border:none;color:inherit;display:flex;height:100%;inset:0;justify-content:center;padding:0;pointer-events:none;position:fixed;width:100%;z-index:var(--magic-command-z-index)}.magic-command__content{-webkit-overflow-scrolling:touch;align-items:var(--magic-command-content-align-items);display:flex;justify-content:var(--magic-command-content-justify-content);max-height:100%;overflow-y:var(--magic-command-content-overflow-y);pointer-events:auto;scroll-behavior:smooth;width:100%}.magic-command__backdrop{-webkit-backdrop-filter:var(--magic-command-backdrop-filter);backdrop-filter:var(--magic-command-backdrop-filter);background-color:var(--magic-command-backdrop-color);bottom:0;height:100%;left:0;pointer-events:auto;position:fixed;right:0;top:0;width:100%;z-index:-1}.magic-command--content-enter-active{animation:magic-command-content-enter .3s ease}.magic-command--content-leave-active{animation:magic-command-content-leave .3s ease}@media (prefers-reduced-motion){.magic-command--content-enter-active{animation:fade-in .3s ease}.magic-command--content-leave-active{animation:fade-out .3s ease}}.magic-command--backdrop-enter-active{animation:fade-in .3s ease}.magic-command--backdrop-leave-active{animation:fade-out .3s ease}
|
|
179
|
-
</style>
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { type Ref, type MaybeRef } from 'vue';
|
|
2
|
-
import type { CommandOptions } from '../../types.js';
|
|
3
|
-
type UseCommandCallbackArgs = {
|
|
4
|
-
id: MaybeRef<string>;
|
|
5
|
-
mappedOptions: CommandOptions;
|
|
6
|
-
addScrollLockPadding: () => void;
|
|
7
|
-
removeScrollLockPadding: () => void;
|
|
8
|
-
lockScroll: () => void;
|
|
9
|
-
unlockScroll: () => void;
|
|
10
|
-
trapFocus: () => void;
|
|
11
|
-
releaseFocus: () => void;
|
|
12
|
-
wrapperActive: Ref<boolean>;
|
|
13
|
-
};
|
|
14
|
-
export declare function useCommandCallback(args: UseCommandCallbackArgs): {
|
|
15
|
-
onBeforeEnter: (_el: Element) => void;
|
|
16
|
-
onEnter: (_el: Element) => void;
|
|
17
|
-
onAfterEnter: (_el: Element) => Promise<void>;
|
|
18
|
-
onBeforeLeave: (_el: Element) => void;
|
|
19
|
-
onLeave: (_el: Element) => void;
|
|
20
|
-
onAfterLeave: (_el: Element) => void;
|
|
21
|
-
};
|
|
22
|
-
export {};
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { toValue, nextTick } from "vue";
|
|
2
|
-
import { useCommandEmitter } from "./../useCommandEmitter.mjs";
|
|
3
|
-
export function useCommandCallback(args) {
|
|
4
|
-
const {
|
|
5
|
-
id,
|
|
6
|
-
mappedOptions,
|
|
7
|
-
addScrollLockPadding,
|
|
8
|
-
removeScrollLockPadding,
|
|
9
|
-
lockScroll,
|
|
10
|
-
unlockScroll,
|
|
11
|
-
trapFocus,
|
|
12
|
-
releaseFocus,
|
|
13
|
-
wrapperActive
|
|
14
|
-
} = args;
|
|
15
|
-
function onBeforeEnter(_el) {
|
|
16
|
-
useCommandEmitter().emit("beforeEnter", toValue(id));
|
|
17
|
-
if (mappedOptions.scrollLock) {
|
|
18
|
-
if (mappedOptions.scrollLockPadding) {
|
|
19
|
-
addScrollLockPadding();
|
|
20
|
-
}
|
|
21
|
-
lockScroll();
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
function onEnter(_el) {
|
|
25
|
-
useCommandEmitter().emit("enter", toValue(id));
|
|
26
|
-
}
|
|
27
|
-
async function onAfterEnter(_el) {
|
|
28
|
-
useCommandEmitter().emit("afterEnter", toValue(id));
|
|
29
|
-
if (mappedOptions.focusTrap) {
|
|
30
|
-
await nextTick();
|
|
31
|
-
trapFocus();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
function onBeforeLeave(_el) {
|
|
35
|
-
useCommandEmitter().emit("beforeLeave", toValue(id));
|
|
36
|
-
}
|
|
37
|
-
function onLeave(_el) {
|
|
38
|
-
useCommandEmitter().emit("leave", toValue(id));
|
|
39
|
-
}
|
|
40
|
-
function onAfterLeave(_el) {
|
|
41
|
-
useCommandEmitter().emit("afterLeave", toValue(id));
|
|
42
|
-
if (mappedOptions.scrollLock) {
|
|
43
|
-
unlockScroll();
|
|
44
|
-
if (mappedOptions.scrollLockPadding) {
|
|
45
|
-
removeScrollLockPadding();
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
if (mappedOptions.focusTrap) {
|
|
49
|
-
releaseFocus();
|
|
50
|
-
}
|
|
51
|
-
wrapperActive.value = false;
|
|
52
|
-
}
|
|
53
|
-
return {
|
|
54
|
-
onBeforeEnter,
|
|
55
|
-
onEnter,
|
|
56
|
-
onAfterEnter,
|
|
57
|
-
onBeforeLeave,
|
|
58
|
-
onLeave,
|
|
59
|
-
onAfterLeave
|
|
60
|
-
};
|
|
61
|
-
}
|