@maas/vue-equipment 0.21.6 → 0.22.1
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/nuxt/module.mjs +7 -0
- package/dist/plugins/MagicCommand/demo/DefaultView.vue +57 -0
- package/dist/plugins/MagicCommand/demo/DefaultView.vue.d.ts +2 -0
- package/dist/plugins/MagicCommand/demo/DemoItem.vue +18 -0
- package/dist/plugins/MagicCommand/demo/DemoItem.vue.d.ts +21 -0
- package/dist/plugins/MagicCommand/demo/ProjectView.vue +55 -0
- package/dist/plugins/MagicCommand/demo/ProjectView.vue.d.ts +2 -0
- package/dist/plugins/MagicCommand/index.d.ts +8 -0
- package/dist/plugins/MagicCommand/index.mjs +28 -0
- package/dist/plugins/MagicCommand/nuxt.d.ts +0 -0
- package/dist/plugins/MagicCommand/nuxt.mjs +27 -0
- package/dist/plugins/MagicCommand/src/components/MagicCommand.vue +180 -0
- package/dist/plugins/MagicCommand/src/components/MagicCommand.vue.d.ts +43 -0
- package/dist/plugins/MagicCommand/src/components/MagicCommandBody.vue +86 -0
- package/dist/plugins/MagicCommand/src/components/MagicCommandBody.vue.d.ts +9 -0
- package/dist/plugins/MagicCommand/src/components/MagicCommandFooter.vue +5 -0
- package/dist/plugins/MagicCommand/src/components/MagicCommandFooter.vue.d.ts +9 -0
- package/dist/plugins/MagicCommand/src/components/MagicCommandGroup.vue +5 -0
- package/dist/plugins/MagicCommand/src/components/MagicCommandGroup.vue.d.ts +9 -0
- package/dist/plugins/MagicCommand/src/components/MagicCommandHead.vue +5 -0
- package/dist/plugins/MagicCommand/src/components/MagicCommandHead.vue.d.ts +9 -0
- package/dist/plugins/MagicCommand/src/components/MagicCommandItem.vue +91 -0
- package/dist/plugins/MagicCommand/src/components/MagicCommandItem.vue.d.ts +44 -0
- package/dist/plugins/MagicCommand/src/components/MagicCommandView.vue +49 -0
- package/dist/plugins/MagicCommand/src/components/MagicCommandView.vue.d.ts +36 -0
- package/dist/plugins/MagicCommand/src/composables/private/useCommandCallback.d.ts +22 -0
- package/dist/plugins/MagicCommand/src/composables/private/useCommandCallback.mjs +61 -0
- package/dist/plugins/MagicCommand/src/composables/private/useCommandItem.d.ts +9 -0
- package/dist/plugins/MagicCommand/src/composables/private/useCommandItem.mjs +54 -0
- package/dist/plugins/MagicCommand/src/composables/private/useCommandScroll.d.ts +7 -0
- package/dist/plugins/MagicCommand/src/composables/private/useCommandScroll.mjs +44 -0
- package/dist/plugins/MagicCommand/src/composables/private/useCommandStore.d.ts +20 -0
- package/dist/plugins/MagicCommand/src/composables/private/useCommandStore.mjs +48 -0
- package/dist/plugins/MagicCommand/src/composables/private/useCommandView.d.ts +6 -0
- package/dist/plugins/MagicCommand/src/composables/private/useCommandView.mjs +25 -0
- package/dist/plugins/MagicCommand/src/composables/useCommandApi.d.ts +21 -0
- package/dist/plugins/MagicCommand/src/composables/useCommandApi.mjs +85 -0
- package/dist/plugins/MagicCommand/src/composables/useCommandEmitter.d.ts +15 -0
- package/dist/plugins/MagicCommand/src/composables/useCommandEmitter.mjs +9 -0
- package/dist/plugins/MagicCommand/src/symbols/index.d.ts +5 -0
- package/dist/plugins/MagicCommand/src/symbols/index.mjs +3 -0
- package/dist/plugins/MagicCommand/src/types/index.d.ts +30 -0
- package/dist/plugins/MagicCommand/src/types/index.mjs +0 -0
- package/dist/plugins/MagicCommand/src/utils/defaultOptions.d.ts +5 -0
- package/dist/plugins/MagicCommand/src/utils/defaultOptions.mjs +23 -0
- package/dist/plugins/MagicDrawer/src/composables/useDrawerApi.mjs +3 -1
- package/dist/plugins/MagicScroll/src/components/MagicScrollMotion.vue +2 -2
- package/dist/plugins/MagicScroll/src/components/MagicScrollMotion.vue.d.ts +2 -2
- package/dist/plugins/MagicScroll/src/components/MagicScrollTransform.vue.d.ts +1 -1
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/index.mjs +1 -0
- package/package.json +1 -1
package/dist/nuxt/module.json
CHANGED
package/dist/nuxt/module.mjs
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { defineNuxtModule, createResolver, extendViteConfig, installModule, addImportsSources } from '@nuxt/kit';
|
|
2
2
|
|
|
3
3
|
const functions$1 = [
|
|
4
|
+
{
|
|
5
|
+
name: "MagicCommand",
|
|
6
|
+
"package": "plugins",
|
|
7
|
+
lastUpdated: 1708513784000,
|
|
8
|
+
docs: "https://maas.egineering/vue-equipment/plugins/MagicCommand/",
|
|
9
|
+
description: "command"
|
|
10
|
+
},
|
|
4
11
|
{
|
|
5
12
|
name: "MagicCookie",
|
|
6
13
|
"package": "plugins",
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<magic-command-view
|
|
3
|
+
id="default-view"
|
|
4
|
+
:default="true"
|
|
5
|
+
class="bg-neutral-800 border border-solid border-neutral-600 w-[40rem] max-h-[30rem] rounded-xl overflow-hidden flex flex-col"
|
|
6
|
+
>
|
|
7
|
+
<magic-command-head class="p-2">
|
|
8
|
+
<div class="w-full border border-neutral-600 p-3 border-b-solid">
|
|
9
|
+
<magic-command-input>
|
|
10
|
+
<input type="text" placeholder="Search" />
|
|
11
|
+
</magic-command-input>
|
|
12
|
+
</div>
|
|
13
|
+
</magic-command-head>
|
|
14
|
+
<magic-command-body class="h-full pb-2">
|
|
15
|
+
<magic-command-group>
|
|
16
|
+
<h2 class="p-4 text-xs text-neutral-600">Suggestions</h2>
|
|
17
|
+
<magic-command-item
|
|
18
|
+
v-slot="{ isActive }"
|
|
19
|
+
:default="true"
|
|
20
|
+
:callback="projectItemCallback"
|
|
21
|
+
>
|
|
22
|
+
<demo-item :is-active="isActive">View Projects</demo-item>
|
|
23
|
+
</magic-command-item>
|
|
24
|
+
</magic-command-group>
|
|
25
|
+
<magic-command-group>
|
|
26
|
+
<h2 class="p-4 text-xs text-neutral-600">Filter</h2>
|
|
27
|
+
<magic-command-item
|
|
28
|
+
v-for="nth in 20"
|
|
29
|
+
:key="nth"
|
|
30
|
+
:callback="() => itemCallback(nth)"
|
|
31
|
+
v-slot="{ isActive }"
|
|
32
|
+
>
|
|
33
|
+
<demo-item :is-active="isActive">{{ nth }}</demo-item>
|
|
34
|
+
</magic-command-item>
|
|
35
|
+
</magic-command-group>
|
|
36
|
+
</magic-command-body>
|
|
37
|
+
</magic-command-view>
|
|
38
|
+
</template>
|
|
39
|
+
|
|
40
|
+
<script setup lang="ts">
|
|
41
|
+
import { inject } from 'vue'
|
|
42
|
+
import { useCommandApi, CommandInstanceId } from '@maas/vue-equipment/plugins'
|
|
43
|
+
import DemoItem from './DemoItem.vue'
|
|
44
|
+
|
|
45
|
+
const commandId = inject(CommandInstanceId, '')
|
|
46
|
+
|
|
47
|
+
const commandApi = useCommandApi(commandId)
|
|
48
|
+
const { selectView } = commandApi
|
|
49
|
+
|
|
50
|
+
function itemCallback(nth: number) {
|
|
51
|
+
console.log(nth)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function projectItemCallback() {
|
|
55
|
+
selectView('project-view')
|
|
56
|
+
}
|
|
57
|
+
</script>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="px-2">
|
|
3
|
+
<span
|
|
4
|
+
class="p-2 flex items-center rounded-md"
|
|
5
|
+
:class="{ 'bg-neutral-700': isActive }"
|
|
6
|
+
>
|
|
7
|
+
<slot />
|
|
8
|
+
</span>
|
|
9
|
+
</div>
|
|
10
|
+
</template>
|
|
11
|
+
|
|
12
|
+
<script setup lang="ts">
|
|
13
|
+
interface Props {
|
|
14
|
+
isActive: boolean
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
defineProps<Props>()
|
|
18
|
+
</script>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
isActive: boolean;
|
|
3
|
+
}
|
|
4
|
+
declare const _default: __VLS_WithTemplateSlots<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
|
+
default?(_: {}): any;
|
|
6
|
+
}>;
|
|
7
|
+
export default _default;
|
|
8
|
+
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
9
|
+
type __VLS_TypePropsToRuntimeProps<T> = {
|
|
10
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
11
|
+
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
12
|
+
} : {
|
|
13
|
+
type: import('vue').PropType<T[K]>;
|
|
14
|
+
required: true;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
18
|
+
new (): {
|
|
19
|
+
$slots: S;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<magic-command-view
|
|
3
|
+
id="project-view"
|
|
4
|
+
class="bg-neutral-800 border border-solid border-neutral-600 w-[40rem] max-h-[30rem] rounded-xl overflow-hidden flex flex-col"
|
|
5
|
+
>
|
|
6
|
+
<magic-command-head class="p-2">
|
|
7
|
+
<div class="w-full border border-neutral-600 p-3 border-b-solid">
|
|
8
|
+
<magic-command-input>
|
|
9
|
+
<input type="text" placeholder="Search Projects" />
|
|
10
|
+
</magic-command-input>
|
|
11
|
+
</div>
|
|
12
|
+
</magic-command-head>
|
|
13
|
+
<magic-command-body class="h-full pb-2">
|
|
14
|
+
<magic-command-group>
|
|
15
|
+
<magic-command-item
|
|
16
|
+
v-for="nth in 10"
|
|
17
|
+
:key="nth"
|
|
18
|
+
:callback="() => itemCallback(nth)"
|
|
19
|
+
:default="nth === 1"
|
|
20
|
+
v-slot="{ isActive }"
|
|
21
|
+
>
|
|
22
|
+
<demo-item :is-active="isActive">Project {{ nth }}</demo-item>
|
|
23
|
+
</magic-command-item>
|
|
24
|
+
</magic-command-group>
|
|
25
|
+
</magic-command-body>
|
|
26
|
+
<magic-command-footer class="px-2">
|
|
27
|
+
<div
|
|
28
|
+
class="w-full border border-neutral-600 p-2 border-t-solid flex items-center"
|
|
29
|
+
>
|
|
30
|
+
<button
|
|
31
|
+
@click="selectLastView"
|
|
32
|
+
class="leading-none text-xs text-neutral-600"
|
|
33
|
+
>
|
|
34
|
+
Go Back
|
|
35
|
+
</button>
|
|
36
|
+
</div>
|
|
37
|
+
</magic-command-footer>
|
|
38
|
+
</magic-command-view>
|
|
39
|
+
</template>
|
|
40
|
+
|
|
41
|
+
<script setup lang="ts">
|
|
42
|
+
import { inject } from 'vue'
|
|
43
|
+
import { useCommandApi, CommandInstanceId } from '@maas/vue-equipment/plugins'
|
|
44
|
+
|
|
45
|
+
import DemoItem from './DemoItem.vue'
|
|
46
|
+
|
|
47
|
+
const commandId = inject(CommandInstanceId, '')
|
|
48
|
+
|
|
49
|
+
const commandApi = useCommandApi(commandId)
|
|
50
|
+
const { selectLastView } = commandApi
|
|
51
|
+
|
|
52
|
+
function itemCallback(nth: number) {
|
|
53
|
+
console.log(nth)
|
|
54
|
+
}
|
|
55
|
+
</script>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useCommandApi } from './src/composables/useCommandApi.js';
|
|
2
|
+
import { useCommandEmitter } from './src/composables/useCommandEmitter.js';
|
|
3
|
+
import { CommandInstanceId, CommandOptionsKey } from './src/symbols.js';
|
|
4
|
+
import type { Plugin } from 'vue';
|
|
5
|
+
import type { CommandEvents } from './src/types/index.js';
|
|
6
|
+
declare const MagicCommandPlugin: Plugin;
|
|
7
|
+
export { MagicCommandPlugin, useCommandApi, useCommandEmitter, CommandInstanceId, CommandOptionsKey, };
|
|
8
|
+
export type { CommandEvents };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import MagicCommand from "./src/components/MagicCommand.vue";
|
|
2
|
+
import MagicCommandBody from "./src/components/MagicCommandBody.vue";
|
|
3
|
+
import MagicCommandFooter from "./src/components/MagicCommandFooter.vue";
|
|
4
|
+
import MagicCommandGroup from "./src/components/MagicCommandGroup.vue";
|
|
5
|
+
import MagicCommandHead from "./src/components/MagicCommandHead.vue";
|
|
6
|
+
import MagicCommandItem from "./src/components/MagicCommandItem.vue";
|
|
7
|
+
import MagicCommandView from "./src/components/MagicCommandView.vue";
|
|
8
|
+
import { useCommandApi } from "./src/composables/useCommandApi.mjs";
|
|
9
|
+
import { useCommandEmitter } from "./src/composables/useCommandEmitter.mjs";
|
|
10
|
+
import { CommandInstanceId, CommandOptionsKey } from "./src/symbols/index.mjs";
|
|
11
|
+
const MagicCommandPlugin = {
|
|
12
|
+
install: (app) => {
|
|
13
|
+
app.component("MagicCommand", MagicCommand);
|
|
14
|
+
app.component("MagicCommandBody", MagicCommandBody);
|
|
15
|
+
app.component("MagicCommandFooter", MagicCommandFooter);
|
|
16
|
+
app.component("MagicCommandGroup", MagicCommandGroup);
|
|
17
|
+
app.component("MagicCommandHead", MagicCommandHead);
|
|
18
|
+
app.component("MagicCommandItem", MagicCommandItem);
|
|
19
|
+
app.component("MagicCommandView", MagicCommandView);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
export {
|
|
23
|
+
MagicCommandPlugin,
|
|
24
|
+
useCommandApi,
|
|
25
|
+
useCommandEmitter,
|
|
26
|
+
CommandInstanceId,
|
|
27
|
+
CommandOptionsKey
|
|
28
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineNuxtModule,
|
|
3
|
+
createResolver,
|
|
4
|
+
addComponentsDir,
|
|
5
|
+
addImports
|
|
6
|
+
} from "@nuxt/kit";
|
|
7
|
+
export default defineNuxtModule({
|
|
8
|
+
meta: {
|
|
9
|
+
name: "@maas/vue-equipment/nuxt/MagicCommand"
|
|
10
|
+
},
|
|
11
|
+
setup() {
|
|
12
|
+
const resolver = createResolver(import.meta.url);
|
|
13
|
+
addComponentsDir({
|
|
14
|
+
path: resolver.resolve("src/components"),
|
|
15
|
+
global: true,
|
|
16
|
+
pathPrefix: false
|
|
17
|
+
});
|
|
18
|
+
addImports({
|
|
19
|
+
from: "@maas/vue-equipment/plugins/MagicCommand",
|
|
20
|
+
name: "useCommandApi"
|
|
21
|
+
});
|
|
22
|
+
addImports({
|
|
23
|
+
from: "@maas/vue-equipment/plugins/MagicCommand",
|
|
24
|
+
name: "useCommandEmitter"
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
});
|
|
@@ -0,0 +1,180 @@
|
|
|
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
|
+
@click.self="close"
|
|
14
|
+
aria-command="true"
|
|
15
|
+
>
|
|
16
|
+
<transition
|
|
17
|
+
v-if="mappedOptions.backdrop || !!$slots.backdrop"
|
|
18
|
+
:name="mappedOptions.transitions?.backdrop"
|
|
19
|
+
>
|
|
20
|
+
<div
|
|
21
|
+
v-show="innerActive"
|
|
22
|
+
class="magic-command__backdrop"
|
|
23
|
+
@click.self="close"
|
|
24
|
+
>
|
|
25
|
+
<slot name="backdrop" />
|
|
26
|
+
</div>
|
|
27
|
+
</transition>
|
|
28
|
+
<transition
|
|
29
|
+
:name="mappedOptions.transitions?.content"
|
|
30
|
+
@before-leave="onBeforeLeave"
|
|
31
|
+
@leave="onLeave"
|
|
32
|
+
@after-leave="onAfterLeave"
|
|
33
|
+
@before-enter="onBeforeEnter"
|
|
34
|
+
@enter="onEnter"
|
|
35
|
+
@after-enter="onAfterEnter"
|
|
36
|
+
>
|
|
37
|
+
<div
|
|
38
|
+
v-show="innerActive"
|
|
39
|
+
class="magic-command__content"
|
|
40
|
+
@click.self="close"
|
|
41
|
+
>
|
|
42
|
+
<slot />
|
|
43
|
+
</div>
|
|
44
|
+
</transition>
|
|
45
|
+
</component>
|
|
46
|
+
</teleport>
|
|
47
|
+
</template>
|
|
48
|
+
|
|
49
|
+
<script setup lang="ts">
|
|
50
|
+
import {
|
|
51
|
+
ref,
|
|
52
|
+
watch,
|
|
53
|
+
nextTick,
|
|
54
|
+
toValue,
|
|
55
|
+
onBeforeUnmount,
|
|
56
|
+
provide,
|
|
57
|
+
type MaybeRef,
|
|
58
|
+
} from 'vue'
|
|
59
|
+
import { createDefu } from 'defu'
|
|
60
|
+
import { useMagicKeys } from '@vueuse/core'
|
|
61
|
+
import { defaultOptions } from './../utils/defaultOptions'
|
|
62
|
+
import { useCommandApi } from './../composables/useCommandApi'
|
|
63
|
+
import { useCommandCallback } from '../composables/private/useCommandCallback'
|
|
64
|
+
import { CommandInstanceId, CommandOptionsKey } from './../symbols'
|
|
65
|
+
|
|
66
|
+
import type { CommandOptions } from './../types/index'
|
|
67
|
+
|
|
68
|
+
import '@maas/vue-equipment/utils/css/animations/fade-in.css'
|
|
69
|
+
import '@maas/vue-equipment/utils/css/animations/fade-out.css'
|
|
70
|
+
|
|
71
|
+
// Prevent keys arrays from being merged with default
|
|
72
|
+
const customDefu = createDefu((obj, key, value) => {
|
|
73
|
+
if (key === 'open' || key === 'close' || key === 'next' || key === 'prev') {
|
|
74
|
+
obj[key] = value
|
|
75
|
+
return true
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
interface MagicCommandProps {
|
|
80
|
+
id: MaybeRef<string>
|
|
81
|
+
class?: MaybeRef<string>
|
|
82
|
+
props?: Record<string, unknown>
|
|
83
|
+
options?: CommandOptions
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const props = withDefaults(defineProps<MagicCommandProps>(), {
|
|
87
|
+
options: () => defaultOptions,
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
const keys = useMagicKeys()
|
|
91
|
+
const commandRef = ref<HTMLElement | undefined>(undefined)
|
|
92
|
+
const commandApi = useCommandApi(props.id, { focusTarget: commandRef })
|
|
93
|
+
const mappedOptions = customDefu(props.options, defaultOptions)
|
|
94
|
+
|
|
95
|
+
const {
|
|
96
|
+
isActive,
|
|
97
|
+
open,
|
|
98
|
+
close,
|
|
99
|
+
trapFocus,
|
|
100
|
+
releaseFocus,
|
|
101
|
+
lockScroll,
|
|
102
|
+
unlockScroll,
|
|
103
|
+
addScrollLockPadding,
|
|
104
|
+
removeScrollLockPadding,
|
|
105
|
+
} = commandApi
|
|
106
|
+
|
|
107
|
+
// Split isActive into two values to animate command smoothly
|
|
108
|
+
const innerActive = ref(false)
|
|
109
|
+
const wrapperActive = ref(false)
|
|
110
|
+
|
|
111
|
+
const {
|
|
112
|
+
onBeforeEnter,
|
|
113
|
+
onEnter,
|
|
114
|
+
onAfterEnter,
|
|
115
|
+
onBeforeLeave,
|
|
116
|
+
onLeave,
|
|
117
|
+
onAfterLeave,
|
|
118
|
+
} = useCommandCallback({
|
|
119
|
+
id: props.id,
|
|
120
|
+
mappedOptions,
|
|
121
|
+
addScrollLockPadding,
|
|
122
|
+
removeScrollLockPadding,
|
|
123
|
+
lockScroll,
|
|
124
|
+
unlockScroll,
|
|
125
|
+
trapFocus,
|
|
126
|
+
releaseFocus,
|
|
127
|
+
wrapperActive,
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
// Handle state
|
|
131
|
+
async function onOpen() {
|
|
132
|
+
wrapperActive.value = true
|
|
133
|
+
await nextTick()
|
|
134
|
+
innerActive.value = true
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function onClose() {
|
|
138
|
+
innerActive.value = false
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (mappedOptions.keys?.open) {
|
|
142
|
+
for (const key of mappedOptions.keys.open) {
|
|
143
|
+
watch(keys[key], (value) => {
|
|
144
|
+
if (value) {
|
|
145
|
+
open()
|
|
146
|
+
}
|
|
147
|
+
})
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (mappedOptions.keys?.close) {
|
|
152
|
+
for (const key of mappedOptions.keys.close) {
|
|
153
|
+
watch(keys[key], (value) => {
|
|
154
|
+
if (value) {
|
|
155
|
+
close()
|
|
156
|
+
}
|
|
157
|
+
})
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
watch(isActive, async (value) => {
|
|
162
|
+
if (value) {
|
|
163
|
+
await onOpen()
|
|
164
|
+
} else {
|
|
165
|
+
onClose()
|
|
166
|
+
}
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
// Reset state on unmount
|
|
170
|
+
onBeforeUnmount(() => {
|
|
171
|
+
close()
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
provide(CommandInstanceId, props.id)
|
|
175
|
+
provide(CommandOptionsKey, mappedOptions)
|
|
176
|
+
</script>
|
|
177
|
+
|
|
178
|
+
<style>
|
|
179
|
+
: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;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);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;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}
|
|
180
|
+
</style>
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type MaybeRef } from 'vue';
|
|
2
|
+
import type { CommandOptions } from './../types/index';
|
|
3
|
+
import '@maas/vue-equipment/utils/css/animations/fade-in.css';
|
|
4
|
+
import '@maas/vue-equipment/utils/css/animations/fade-out.css';
|
|
5
|
+
interface MagicCommandProps {
|
|
6
|
+
id: MaybeRef<string>;
|
|
7
|
+
class?: MaybeRef<string>;
|
|
8
|
+
props?: Record<string, unknown>;
|
|
9
|
+
options?: CommandOptions;
|
|
10
|
+
}
|
|
11
|
+
declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<MagicCommandProps>, {
|
|
12
|
+
options: () => CommandOptions;
|
|
13
|
+
}>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<MagicCommandProps>, {
|
|
14
|
+
options: () => CommandOptions;
|
|
15
|
+
}>>>, {
|
|
16
|
+
options: CommandOptions;
|
|
17
|
+
}, {}>, {
|
|
18
|
+
backdrop?(_: {}): any;
|
|
19
|
+
default?(_: {}): any;
|
|
20
|
+
}>;
|
|
21
|
+
export default _default;
|
|
22
|
+
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
23
|
+
type __VLS_TypePropsToRuntimeProps<T> = {
|
|
24
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
25
|
+
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
26
|
+
} : {
|
|
27
|
+
type: import('vue').PropType<T[K]>;
|
|
28
|
+
required: true;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
type __VLS_WithDefaults<P, D> = {
|
|
32
|
+
[K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
|
|
33
|
+
default: D[K];
|
|
34
|
+
}> : P[K];
|
|
35
|
+
};
|
|
36
|
+
type __VLS_Prettify<T> = {
|
|
37
|
+
[K in keyof T]: T[K];
|
|
38
|
+
} & {};
|
|
39
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
40
|
+
new (): {
|
|
41
|
+
$slots: S;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="magic-command-body" ref="elRef">
|
|
3
|
+
<slot />
|
|
4
|
+
</div>
|
|
5
|
+
</template>
|
|
6
|
+
<script lang="ts" setup>
|
|
7
|
+
import { inject, ref, watch, nextTick } from 'vue'
|
|
8
|
+
import { useMagicKeys } from '@vueuse/core'
|
|
9
|
+
|
|
10
|
+
import { useCommandItem } from '../composables/private/useCommandItem'
|
|
11
|
+
import { useCommandScroll } from '../composables/private/useCommandScroll'
|
|
12
|
+
import { CommandInstanceId, CommandOptionsKey } from '../symbols'
|
|
13
|
+
|
|
14
|
+
import type { CommandOptions } from '../types'
|
|
15
|
+
|
|
16
|
+
const elRef = ref<HTMLElement | undefined>(undefined)
|
|
17
|
+
|
|
18
|
+
const commandId = inject(CommandInstanceId, '')
|
|
19
|
+
const options = inject(CommandOptionsKey, {} as CommandOptions)
|
|
20
|
+
|
|
21
|
+
const { activeItem, nextItem, prevItem } = useCommandItem(commandId)
|
|
22
|
+
const { findElement, isElementAbove, isElementBelow, scrollInFromBottom } =
|
|
23
|
+
useCommandScroll(elRef)
|
|
24
|
+
|
|
25
|
+
const keys = useMagicKeys()
|
|
26
|
+
|
|
27
|
+
const nextTimeout = ref<NodeJS.Timeout | undefined>(undefined)
|
|
28
|
+
const prevTimeout = ref<NodeJS.Timeout | undefined>(undefined)
|
|
29
|
+
const nextInterval = ref<NodeJS.Timer | undefined>(undefined)
|
|
30
|
+
const prevInterval = ref<NodeJS.Timer | undefined>(undefined)
|
|
31
|
+
|
|
32
|
+
if (options.keys?.next) {
|
|
33
|
+
for (const key of options.keys.next) {
|
|
34
|
+
watch(keys[key], (value) => {
|
|
35
|
+
if (value) {
|
|
36
|
+
nextItem(options.loop)
|
|
37
|
+
nextTimeout.value = setTimeout(() => {
|
|
38
|
+
nextInterval.value = setInterval(() => {
|
|
39
|
+
nextItem(options.loop)
|
|
40
|
+
}, 100)
|
|
41
|
+
}, 500)
|
|
42
|
+
} else {
|
|
43
|
+
clearTimeout(nextTimeout.value)
|
|
44
|
+
clearInterval(nextInterval.value)
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (options.keys?.prev) {
|
|
51
|
+
for (const key of options.keys.prev) {
|
|
52
|
+
watch(keys[key], (value) => {
|
|
53
|
+
if (value) {
|
|
54
|
+
prevItem(options.loop)
|
|
55
|
+
prevTimeout.value = setTimeout(() => {
|
|
56
|
+
prevInterval.value = setInterval(() => {
|
|
57
|
+
prevItem(options.loop)
|
|
58
|
+
}, 100)
|
|
59
|
+
}, 500)
|
|
60
|
+
} else {
|
|
61
|
+
clearTimeout(prevTimeout.value)
|
|
62
|
+
clearInterval(prevInterval.value)
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
watch(activeItem, async (value) => {
|
|
69
|
+
if (!value) return
|
|
70
|
+
|
|
71
|
+
nextTick(() => {
|
|
72
|
+
const element = findElement(value)
|
|
73
|
+
if (element) {
|
|
74
|
+
if (isElementAbove(element)) {
|
|
75
|
+
element.scrollIntoView()
|
|
76
|
+
} else if (isElementBelow(element)) {
|
|
77
|
+
scrollInFromBottom(element)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
})
|
|
82
|
+
</script>
|
|
83
|
+
|
|
84
|
+
<style>
|
|
85
|
+
:root{--magic-command-body-height:100%;--magic-command-body-overflow-y:auto}.magic-command-body{height:var(--magic-command-body-height);overflow-y:var(--magic-command-body-overflow-y)}
|
|
86
|
+
</style>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>, {
|
|
2
|
+
default?(_: {}): any;
|
|
3
|
+
}>;
|
|
4
|
+
export default _default;
|
|
5
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
6
|
+
new (): {
|
|
7
|
+
$slots: S;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>, {
|
|
2
|
+
default?(_: {}): any;
|
|
3
|
+
}>;
|
|
4
|
+
export default _default;
|
|
5
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
6
|
+
new (): {
|
|
7
|
+
$slots: S;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>, {
|
|
2
|
+
default?(_: {}): any;
|
|
3
|
+
}>;
|
|
4
|
+
export default _default;
|
|
5
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
6
|
+
new (): {
|
|
7
|
+
$slots: S;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>, {
|
|
2
|
+
default?(_: {}): any;
|
|
3
|
+
}>;
|
|
4
|
+
export default _default;
|
|
5
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
6
|
+
new (): {
|
|
7
|
+
$slots: S;
|
|
8
|
+
};
|
|
9
|
+
};
|