@maas/vue-equipment 0.29.2 → 0.29.3
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/composables/index.js +5 -10
- package/dist/composables/index.js.map +1 -1
- package/dist/composables/index.mjs +5 -10
- package/dist/composables/index.mjs.map +1 -1
- package/dist/nuxt/module.json +1 -1
- package/dist/nuxt/module.mjs +16 -9
- package/dist/plugins/MagicCommand/index.d.ts +2 -4
- package/dist/plugins/MagicCommand/index.mjs +2 -2
- package/dist/plugins/MagicCommand/src/components/MagicCommandBody.vue +3 -3
- package/dist/plugins/MagicCommand/src/components/MagicCommandDrawer.vue +2 -2
- package/dist/plugins/MagicCommand/src/components/MagicCommandDrawer.vue.d.ts +2 -2
- package/dist/plugins/MagicCommand/src/components/MagicCommandItem.vue +4 -4
- package/dist/plugins/MagicCommand/src/components/MagicCommandItem.vue.d.ts +5 -5
- package/dist/plugins/MagicCommand/src/components/MagicCommandModal.vue +2 -2
- package/dist/plugins/MagicCommand/src/components/MagicCommandModal.vue.d.ts +2 -2
- package/dist/plugins/MagicCommand/src/components/MagicCommandProvider.vue +4 -4
- package/dist/plugins/MagicCommand/src/components/MagicCommandProvider.vue.d.ts +5 -5
- package/dist/plugins/MagicCommand/src/components/MagicCommandView.vue +4 -2
- package/dist/plugins/MagicCommand/src/components/MagicCommandView.vue.d.ts +3 -3
- package/dist/plugins/MagicCommand/src/composables/private/useCommandScroll.mjs +1 -1
- package/dist/plugins/MagicCommand/src/composables/private/useCommandStore.mjs +1 -1
- package/dist/plugins/MagicCommand/src/symbols/index.d.ts +3 -3
- package/dist/plugins/MagicCommand/src/symbols/index.mjs +2 -2
- package/dist/plugins/MagicCommand/src/types/index.d.ts +5 -5
- package/dist/plugins/MagicCommand/src/utils/defaultOptions.d.ts +2 -2
- package/dist/plugins/MagicCookie/index.d.ts +0 -2
- package/dist/plugins/MagicCookie/src/components/MagicCookie.vue +6 -7
- package/dist/plugins/MagicCookie/src/components/MagicCookie.vue.d.ts +6 -6
- package/dist/plugins/MagicCookie/src/composables/private/useCookieApi.d.ts +17 -0
- package/dist/plugins/MagicCookie/src/composables/private/{defineCookieApi.mjs → useCookieApi.mjs} +4 -4
- package/dist/plugins/MagicCookie/src/composables/useMagicCookie.d.ts +5 -5
- package/dist/plugins/MagicCookie/src/composables/useMagicCookie.mjs +4 -4
- package/dist/plugins/MagicCookie/src/types/index.d.ts +6 -10
- package/dist/plugins/MagicDraggable/index.d.ts +2 -2
- package/dist/plugins/MagicDraggable/src/components/MagicDraggable.vue +4 -4
- package/dist/plugins/MagicDraggable/src/components/MagicDraggable.vue.d.ts +6 -6
- package/dist/plugins/MagicDraggable/src/composables/private/useDraggableState.d.ts +1 -2
- package/dist/plugins/MagicDraggable/src/types/index.d.ts +1 -1
- package/dist/plugins/MagicDraggable/src/utils/defaultOptions.d.ts +4 -4
- package/dist/plugins/MagicDrawer/index.d.ts +2 -2
- package/dist/plugins/MagicDrawer/src/components/MagicDrawer.vue +3 -4
- package/dist/plugins/MagicDrawer/src/components/MagicDrawer.vue.d.ts +3 -3
- package/dist/plugins/MagicDrawer/src/composables/private/useDrawerCallback.d.ts +2 -2
- package/dist/plugins/MagicDrawer/src/composables/private/useDrawerDOM.d.ts +3 -3
- package/dist/plugins/MagicDrawer/src/composables/private/useDrawerDOM.mjs +2 -2
- package/dist/plugins/MagicDrawer/src/composables/private/useDrawerDrag.mjs +3 -1
- package/dist/plugins/MagicDrawer/src/composables/private/useDrawerProgress.mjs +3 -1
- package/dist/plugins/MagicDrawer/src/composables/private/useDrawerState.mjs +1 -3
- package/dist/plugins/MagicDrawer/src/types/index.d.ts +1 -1
- package/dist/plugins/MagicDrawer/src/utils/defaultOptions.d.ts +7 -7
- package/dist/plugins/MagicEmitter/src/composables/useMagicEmitter.d.ts +494 -170
- package/dist/plugins/MagicEmitter/src/types/index.d.ts +9 -9
- package/dist/plugins/MagicMarquee/nuxt.mjs +1 -5
- package/dist/plugins/MagicMarquee/src/components/MagicMarquee.vue +3 -3
- package/dist/plugins/MagicMarquee/src/components/MagicMarquee.vue.d.ts +3 -3
- package/dist/plugins/MagicMenu/index.d.ts +4 -0
- package/dist/plugins/MagicMenu/index.mjs +27 -0
- package/dist/plugins/MagicMenu/nuxt.d.ts +2 -0
- package/dist/plugins/MagicMenu/nuxt.mjs +14 -0
- package/dist/plugins/MagicMenu/src/components/MagicMenuContent.vue +140 -0
- package/dist/plugins/MagicMenu/src/components/MagicMenuContent.vue.d.ts +26 -0
- package/dist/plugins/MagicMenu/src/components/MagicMenuFloat.vue +169 -0
- package/dist/plugins/MagicMenu/src/components/MagicMenuFloat.vue.d.ts +24 -0
- package/dist/plugins/MagicMenu/src/components/MagicMenuItem.vue +137 -0
- package/dist/plugins/MagicMenu/src/components/MagicMenuItem.vue.d.ts +29 -0
- package/dist/plugins/MagicMenu/src/components/MagicMenuProvider.vue +106 -0
- package/dist/plugins/MagicMenu/src/components/MagicMenuProvider.vue.d.ts +24 -0
- package/dist/plugins/MagicMenu/src/components/MagicMenuTrigger.vue +122 -0
- package/dist/plugins/MagicMenu/src/components/MagicMenuTrigger.vue.d.ts +26 -0
- package/dist/plugins/MagicMenu/src/components/MagicMenuView.vue +53 -0
- package/dist/plugins/MagicMenu/src/components/MagicMenuView.vue.d.ts +21 -0
- package/dist/plugins/MagicMenu/src/composables/private/useMenuCallback.d.ts +18 -0
- package/dist/plugins/MagicMenu/src/composables/private/useMenuCallback.mjs +52 -0
- package/dist/plugins/MagicMenu/src/composables/private/useMenuDOM.d.ts +6 -0
- package/dist/plugins/MagicMenu/src/composables/private/useMenuDOM.mjs +42 -0
- package/dist/plugins/MagicMenu/src/composables/private/useMenuItem.d.ts +15 -0
- package/dist/plugins/MagicMenu/src/composables/private/useMenuItem.mjs +75 -0
- package/dist/plugins/MagicMenu/src/composables/private/useMenuKeyListener.d.ts +10 -0
- package/dist/plugins/MagicMenu/src/composables/private/useMenuKeyListener.mjs +178 -0
- package/dist/plugins/MagicMenu/src/composables/private/useMenuState.d.ts +7 -0
- package/dist/plugins/MagicMenu/src/composables/private/useMenuState.mjs +48 -0
- package/dist/plugins/MagicMenu/src/composables/private/useMenuTrigger.d.ts +18 -0
- package/dist/plugins/MagicMenu/src/composables/private/useMenuTrigger.mjs +262 -0
- package/dist/plugins/MagicMenu/src/composables/private/useMenuUtils.d.ts +3 -0
- package/dist/plugins/MagicMenu/src/composables/private/useMenuUtils.mjs +16 -0
- package/dist/plugins/MagicMenu/src/composables/private/useMenuView.d.ts +20 -0
- package/dist/plugins/MagicMenu/src/composables/private/useMenuView.mjs +116 -0
- package/dist/plugins/MagicMenu/src/symbols/index.d.ts +9 -0
- package/dist/plugins/MagicMenu/src/symbols/index.mjs +16 -0
- package/dist/plugins/MagicMenu/src/types/index.d.ts +72 -0
- package/dist/plugins/MagicMenu/src/types/index.mjs +0 -0
- package/dist/plugins/MagicMenu/src/utils/defaultOptions.d.ts +4 -0
- package/dist/plugins/MagicMenu/src/utils/defaultOptions.mjs +9 -0
- package/dist/plugins/MagicModal/index.d.ts +2 -2
- package/dist/plugins/MagicModal/src/components/MagicModal.vue +4 -4
- package/dist/plugins/MagicModal/src/components/MagicModal.vue.d.ts +5 -5
- package/dist/plugins/MagicModal/src/composables/private/useModalCallback.d.ts +2 -2
- package/dist/plugins/MagicModal/src/composables/private/useModalDOM.d.ts +3 -3
- package/dist/plugins/MagicModal/src/composables/private/useModalDOM.mjs +2 -2
- package/dist/plugins/MagicModal/src/types/index.d.ts +1 -1
- package/dist/plugins/MagicModal/src/utils/defaultOptions.d.ts +2 -2
- package/dist/plugins/MagicNoise/index.d.ts +1 -2
- package/dist/plugins/MagicNoise/index.mjs +1 -2
- package/dist/plugins/MagicNoise/nuxt.mjs +1 -5
- package/dist/plugins/MagicNoise/src/components/MagicNoise.vue +4 -4
- package/dist/plugins/MagicNoise/src/components/MagicNoise.vue.d.ts +5 -5
- package/dist/plugins/MagicNoise/src/composables/private/useNoiseApi.d.ts +2 -2
- package/dist/plugins/MagicNoise/src/types/index.d.ts +1 -1
- package/dist/plugins/MagicNoise/src/utils/defaultOptions.d.ts +2 -2
- package/dist/plugins/MagicPlayer/index.d.ts +0 -1
- package/dist/plugins/MagicPlayer/src/components/MagicAudioPlayer.vue +2 -2
- package/dist/plugins/MagicPlayer/src/components/MagicAudioPlayer.vue.d.ts +3 -3
- package/dist/plugins/MagicPlayer/src/components/MagicAudioPlayerControls.vue +2 -2
- package/dist/plugins/MagicPlayer/src/components/MagicAudioPlayerControls.vue.d.ts +2 -2
- package/dist/plugins/MagicPlayer/src/components/MagicPlayer.vue +9 -30
- package/dist/plugins/MagicPlayer/src/components/MagicPlayer.vue.d.ts +10 -14
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerControls.vue +79 -56
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerControls.vue.d.ts +20 -2
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerDisplayTime.vue +2 -2
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerDisplayTime.vue.d.ts +3 -3
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerMuxPopover.vue +9 -7
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerMuxPopover.vue.d.ts +2 -2
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerOverlay.vue +2 -2
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerOverlay.vue.d.ts +2 -2
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerTimeline.vue +2 -3
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerTimeline.vue.d.ts +2 -2
- package/dist/plugins/MagicPlayer/src/composables/private/usePlayerMediaApi.mjs +3 -0
- package/dist/plugins/MagicPlayer/src/composables/private/usePlayerRuntime.d.ts +2 -2
- package/dist/plugins/MagicPlayer/src/composables/private/usePlayerRuntime.mjs +23 -4
- package/dist/plugins/MagicPlayer/src/types/index.d.ts +1 -1
- package/dist/plugins/MagicScroll/index.d.ts +3 -3
- package/dist/plugins/MagicScroll/index.mjs +1 -2
- package/dist/plugins/MagicScroll/src/components/MagicScrollCollision.vue +11 -7
- package/dist/plugins/MagicScroll/src/components/MagicScrollCollision.vue.d.ts +2 -2
- package/dist/plugins/MagicScroll/src/components/MagicScrollMotion.vue +2 -2
- package/dist/plugins/MagicScroll/src/components/MagicScrollMotion.vue.d.ts +3 -3
- package/dist/plugins/MagicScroll/src/components/MagicScrollProvider.vue +2 -2
- package/dist/plugins/MagicScroll/src/components/MagicScrollProvider.vue.d.ts +3 -3
- package/dist/plugins/MagicScroll/src/components/MagicScrollScene.vue +2 -2
- package/dist/plugins/MagicScroll/src/components/MagicScrollScene.vue.d.ts +3 -3
- package/dist/plugins/MagicScroll/src/components/MagicScrollTransform.vue +2 -2
- package/dist/plugins/MagicScroll/src/components/MagicScrollTransform.vue.d.ts +3 -3
- package/dist/plugins/MagicScroll/src/composables/private/useCollisionDetect.d.ts +28 -0
- package/dist/plugins/MagicScroll/src/composables/private/useCollisionDetect.mjs +144 -0
- package/dist/plugins/MagicScroll/src/composables/private/useScrollApi.d.ts +0 -1
- package/dist/plugins/MagicScroll/src/types/index.d.ts +19 -25
- package/dist/plugins/MagicToast/index.d.ts +0 -2
- package/dist/plugins/MagicToast/src/components/MagicToast.vue +4 -4
- package/dist/plugins/MagicToast/src/components/MagicToast.vue.d.ts +2 -2
- package/dist/plugins/MagicToast/src/components/MagicToastComponent.vue +4 -4
- package/dist/plugins/MagicToast/src/components/MagicToastComponent.vue.d.ts +5 -5
- package/dist/plugins/MagicToast/src/composables/private/useToastApi.d.ts +1 -1
- package/dist/plugins/MagicToast/src/composables/private/useToastCallback.d.ts +3 -3
- package/dist/plugins/MagicToast/src/composables/private/useToastCallback.mjs +5 -7
- package/dist/plugins/MagicToast/src/composables/private/useToastInternalApi.d.ts +2 -2
- package/dist/plugins/MagicToast/src/composables/private/useToastStore.d.ts +4 -14
- package/dist/plugins/MagicToast/src/composables/useMagicToast.d.ts +6 -6
- package/dist/plugins/MagicToast/src/types/index.d.ts +20 -21
- package/dist/plugins/MagicToast/src/utils/defaultOptions.d.ts +2 -2
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/index.mjs +1 -0
- package/dist/utils/index.js +4 -8
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +4 -8
- package/dist/utils/index.mjs.map +1 -1
- package/package.json +9 -4
- package/dist/plugins/MagicCookie/src/composables/private/defineCookieApi.d.ts +0 -12
- package/dist/plugins/MagicScroll/src/composables/useCollisionDetect.d.ts +0 -6
- package/dist/plugins/MagicScroll/src/composables/useCollisionDetect.mjs +0 -119
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="magic-menu-provider" ref="elRef">
|
|
3
|
+
<slot />
|
|
4
|
+
</div>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script lang="ts" setup>
|
|
8
|
+
import { ref, provide, watch, type MaybeRef, onBeforeUnmount } from 'vue'
|
|
9
|
+
import { onClickOutside, onKeyStroke, usePointer } from '@vueuse/core'
|
|
10
|
+
import { defu } from 'defu'
|
|
11
|
+
import { useMenuState } from '../composables/private/useMenuState'
|
|
12
|
+
import { useMenuView } from '../composables/private/useMenuView'
|
|
13
|
+
import { useMenuKeyListener } from '../composables/private/useMenuKeyListener'
|
|
14
|
+
import { MagicMenuInstanceId } from '../symbols'
|
|
15
|
+
import { defaultOptions } from '../utils/defaultOptions'
|
|
16
|
+
|
|
17
|
+
import type { MagicMenuOptions } from '../types'
|
|
18
|
+
|
|
19
|
+
interface MagicMenuProviderProps {
|
|
20
|
+
id: MaybeRef<string>
|
|
21
|
+
options?: MagicMenuOptions
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const props = defineProps<MagicMenuProviderProps>()
|
|
25
|
+
const elRef = ref<HTMLElement | undefined>(undefined)
|
|
26
|
+
|
|
27
|
+
const mappedOptions = defu(props.options, defaultOptions)
|
|
28
|
+
|
|
29
|
+
const { initializeState, deleteState } = useMenuState(props.id)
|
|
30
|
+
const state = initializeState(mappedOptions)
|
|
31
|
+
|
|
32
|
+
// If the mode changes, save the current pointer position
|
|
33
|
+
// If the pointer moves, switch to mouse mode
|
|
34
|
+
const lastX = ref(0)
|
|
35
|
+
const lastY = ref(0)
|
|
36
|
+
|
|
37
|
+
const { x, y } = usePointer()
|
|
38
|
+
|
|
39
|
+
watch(
|
|
40
|
+
() => state?.input.type,
|
|
41
|
+
(value) => {
|
|
42
|
+
if (value === 'keyboard') {
|
|
43
|
+
lastX.value = x.value
|
|
44
|
+
lastY.value = y.value
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
watch([x, y], ([x, y]) => {
|
|
50
|
+
if (x !== lastX.value || y !== lastY.value) {
|
|
51
|
+
if (state) {
|
|
52
|
+
state.input.type = 'pointer'
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
// Add key listener
|
|
58
|
+
const {
|
|
59
|
+
onArrowRight,
|
|
60
|
+
onArrowLeft,
|
|
61
|
+
onArrowUp,
|
|
62
|
+
onArrowDown,
|
|
63
|
+
onEscape,
|
|
64
|
+
onEnter,
|
|
65
|
+
onTab,
|
|
66
|
+
} = useMenuKeyListener(props.id)
|
|
67
|
+
|
|
68
|
+
onKeyStroke('ArrowRight', onArrowRight)
|
|
69
|
+
onKeyStroke('ArrowLeft', onArrowLeft)
|
|
70
|
+
onKeyStroke('ArrowDown', onArrowDown)
|
|
71
|
+
onKeyStroke('ArrowUp', onArrowUp)
|
|
72
|
+
onKeyStroke('Escape', onEscape)
|
|
73
|
+
onKeyStroke('Enter', onEnter)
|
|
74
|
+
onKeyStroke('Tab', onTab)
|
|
75
|
+
|
|
76
|
+
// Handle off-click
|
|
77
|
+
const { unselectAllViews } = useMenuView(props.id)
|
|
78
|
+
|
|
79
|
+
onClickOutside(
|
|
80
|
+
elRef,
|
|
81
|
+
() => {
|
|
82
|
+
if (state) {
|
|
83
|
+
state.active = false
|
|
84
|
+
}
|
|
85
|
+
unselectAllViews()
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
ignore: [
|
|
89
|
+
'.magic-menu-view',
|
|
90
|
+
'.magic-menu-item',
|
|
91
|
+
'.magic-menu-cursor-blocker',
|
|
92
|
+
],
|
|
93
|
+
}
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
// Lifecycle
|
|
97
|
+
onBeforeUnmount(() => {
|
|
98
|
+
deleteState()
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
provide(MagicMenuInstanceId, props.id)
|
|
102
|
+
</script>
|
|
103
|
+
|
|
104
|
+
<style>
|
|
105
|
+
.magic-menu-provider{outline:none;-webkit-user-select:none;-moz-user-select:none;user-select:none}
|
|
106
|
+
</style>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type MaybeRef } from 'vue';
|
|
2
|
+
import type { MagicMenuOptions } from '../types';
|
|
3
|
+
interface MagicMenuProviderProps {
|
|
4
|
+
id: MaybeRef<string>;
|
|
5
|
+
options?: MagicMenuOptions;
|
|
6
|
+
}
|
|
7
|
+
declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__VLS_TypePropsToOption<MagicMenuProviderProps>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToOption<MagicMenuProviderProps>>>, {}, {}>, {
|
|
8
|
+
default?(_: {}): any;
|
|
9
|
+
}>;
|
|
10
|
+
export default _default;
|
|
11
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
12
|
+
new (): {
|
|
13
|
+
$slots: S;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
17
|
+
type __VLS_TypePropsToOption<T> = {
|
|
18
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
19
|
+
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
20
|
+
} : {
|
|
21
|
+
type: import('vue').PropType<T[K]>;
|
|
22
|
+
required: true;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
class="magic-menu-trigger"
|
|
4
|
+
ref="elRef"
|
|
5
|
+
:class="{ '-active': view?.active, '-disabled': mappedDisabled }"
|
|
6
|
+
:data-id="`${viewId}-trigger`"
|
|
7
|
+
:tabindex="mappedTabindex"
|
|
8
|
+
@click="onClick"
|
|
9
|
+
@contextmenu="onClick"
|
|
10
|
+
@mouseenter="onMouseenter"
|
|
11
|
+
@mouseleave="onMouseleave"
|
|
12
|
+
>
|
|
13
|
+
<slot :is-active="view?.active" :is-disabled="mappedDisabled" />
|
|
14
|
+
</div>
|
|
15
|
+
</template>
|
|
16
|
+
|
|
17
|
+
<script lang="ts" setup>
|
|
18
|
+
import { computed, inject, onBeforeUnmount, ref, watch } from 'vue'
|
|
19
|
+
import { useMenuState } from '../composables/private/useMenuState'
|
|
20
|
+
import { useMenuView } from '../composables/private/useMenuView'
|
|
21
|
+
import { useMenuItem } from '../composables/private/useMenuItem'
|
|
22
|
+
import { useMenuTrigger } from '../composables/private/useMenuTrigger'
|
|
23
|
+
import {
|
|
24
|
+
MagicMenuInstanceId,
|
|
25
|
+
MagicMenuViewId,
|
|
26
|
+
MagicMenuItemId,
|
|
27
|
+
} from '../symbols'
|
|
28
|
+
|
|
29
|
+
import type { MenuTrigger } from '../types'
|
|
30
|
+
|
|
31
|
+
interface MagicMenuTriggerProps {
|
|
32
|
+
disabled?: boolean
|
|
33
|
+
trigger?: MenuTrigger[]
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const props = defineProps<MagicMenuTriggerProps>()
|
|
37
|
+
const elRef = ref<HTMLElement | undefined>(undefined)
|
|
38
|
+
|
|
39
|
+
const instanceId = inject(MagicMenuInstanceId, undefined)
|
|
40
|
+
const viewId = inject(MagicMenuViewId, undefined)
|
|
41
|
+
const itemId = inject(MagicMenuItemId, undefined)
|
|
42
|
+
|
|
43
|
+
if (!instanceId) {
|
|
44
|
+
throw new Error('MagicMenuTrigger must be nested inside MagicMenuProvider')
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (!viewId) {
|
|
48
|
+
throw new Error('MagicMenuTrigger must be nested inside MagicMenuView')
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const { getView, getRelativeViewIndex } = useMenuView(instanceId)
|
|
52
|
+
const view = getView(viewId)
|
|
53
|
+
const viewIndex = getRelativeViewIndex(viewId)
|
|
54
|
+
|
|
55
|
+
const { initializeState } = useMenuState(instanceId)
|
|
56
|
+
const state = initializeState()
|
|
57
|
+
|
|
58
|
+
const { getItem } = useMenuItem({ instanceId, viewId })
|
|
59
|
+
const item = getItem(itemId ?? '')
|
|
60
|
+
|
|
61
|
+
const mappedDisabled = computed(() => props.disabled ?? item?.disabled)
|
|
62
|
+
|
|
63
|
+
const mappedTrigger = computed<MenuTrigger[]>(() => {
|
|
64
|
+
if (props.trigger?.length) {
|
|
65
|
+
return props.trigger
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
switch (state.options.mode) {
|
|
69
|
+
case 'menubar':
|
|
70
|
+
return view?.parent.item
|
|
71
|
+
? ['mouseenter', 'mouseleave', 'click']
|
|
72
|
+
: ['mouseenter', 'click']
|
|
73
|
+
case 'dropdown':
|
|
74
|
+
return view?.parent.item
|
|
75
|
+
? ['mouseenter', 'mouseleave', 'click']
|
|
76
|
+
: ['click']
|
|
77
|
+
case 'context':
|
|
78
|
+
return view?.parent.item
|
|
79
|
+
? ['mouseenter', 'mouseleave', 'click']
|
|
80
|
+
: ['right-click']
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
const mappedTabindex = computed(() => {
|
|
85
|
+
if (viewIndex === 0 && state.options.mode !== 'context' && !itemId) {
|
|
86
|
+
return 0
|
|
87
|
+
} else {
|
|
88
|
+
return undefined
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
const { initialize, destroy, onMouseenter, onClick, onMouseleave } =
|
|
93
|
+
useMenuTrigger({
|
|
94
|
+
instanceId,
|
|
95
|
+
viewId,
|
|
96
|
+
itemId,
|
|
97
|
+
mappedDisabled,
|
|
98
|
+
mappedTrigger,
|
|
99
|
+
elRef,
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
// Initialize watcher
|
|
103
|
+
initialize()
|
|
104
|
+
|
|
105
|
+
watch(
|
|
106
|
+
elRef,
|
|
107
|
+
(value) => {
|
|
108
|
+
if (view && value) {
|
|
109
|
+
view.children.trigger = value
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
{ immediate: true }
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
onBeforeUnmount(() => {
|
|
116
|
+
destroy()
|
|
117
|
+
})
|
|
118
|
+
</script>
|
|
119
|
+
|
|
120
|
+
<style>
|
|
121
|
+
.magic-menu-trigger{cursor:var(--magic-menu-trigger-cursor,pointer)}
|
|
122
|
+
</style>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { MenuTrigger } from '../types';
|
|
2
|
+
interface MagicMenuTriggerProps {
|
|
3
|
+
disabled?: boolean;
|
|
4
|
+
trigger?: MenuTrigger[];
|
|
5
|
+
}
|
|
6
|
+
declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__VLS_TypePropsToOption<MagicMenuTriggerProps>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToOption<MagicMenuTriggerProps>>>, {}, {}>, {
|
|
7
|
+
default?(_: {
|
|
8
|
+
isActive: boolean | undefined;
|
|
9
|
+
isDisabled: boolean;
|
|
10
|
+
}): any;
|
|
11
|
+
}>;
|
|
12
|
+
export default _default;
|
|
13
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
14
|
+
new (): {
|
|
15
|
+
$slots: S;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
19
|
+
type __VLS_TypePropsToOption<T> = {
|
|
20
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
21
|
+
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
22
|
+
} : {
|
|
23
|
+
type: import('vue').PropType<T[K]>;
|
|
24
|
+
required: true;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="magic-menu-view" :id="mappedId">
|
|
3
|
+
<slot />
|
|
4
|
+
</div>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script lang="ts" setup>
|
|
8
|
+
import { computed, inject, onBeforeUnmount, provide } from 'vue'
|
|
9
|
+
import { uuid } from '@maas/vue-equipment/utils'
|
|
10
|
+
import { useMenuView } from '../composables/private/useMenuView'
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
MagicMenuInstanceId,
|
|
14
|
+
MagicMenuViewId,
|
|
15
|
+
MagicMenuParentTree,
|
|
16
|
+
MagicMenuItemId,
|
|
17
|
+
MagicMenuViewActive,
|
|
18
|
+
} from '../symbols'
|
|
19
|
+
|
|
20
|
+
interface MagicMenuViewProps {
|
|
21
|
+
id?: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const props = defineProps<MagicMenuViewProps>()
|
|
25
|
+
|
|
26
|
+
const parentTree = inject(MagicMenuParentTree, [])
|
|
27
|
+
const instanceId = inject(MagicMenuInstanceId, undefined)
|
|
28
|
+
const itemId = inject(MagicMenuItemId, undefined)
|
|
29
|
+
|
|
30
|
+
if (!instanceId) {
|
|
31
|
+
throw new Error('MagicMenuView must be nested inside MagicMenuProvider')
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const mappedId = computed(() => props.id ?? `magic-menu-view-${uuid()}`)
|
|
35
|
+
const mappedParentTree = computed(() => [...parentTree, mappedId.value])
|
|
36
|
+
|
|
37
|
+
// Register view
|
|
38
|
+
const { initializeView, deleteView } = useMenuView(instanceId)
|
|
39
|
+
const view = initializeView({
|
|
40
|
+
id: mappedId.value,
|
|
41
|
+
parent: { views: parentTree, item: itemId ?? '' },
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
// Pass id, active state and parent tree to children
|
|
45
|
+
provide(MagicMenuParentTree, mappedParentTree.value)
|
|
46
|
+
provide(MagicMenuViewId, mappedId.value)
|
|
47
|
+
provide(MagicMenuViewActive, view.active)
|
|
48
|
+
|
|
49
|
+
// Lifecycle
|
|
50
|
+
onBeforeUnmount(() => {
|
|
51
|
+
deleteView(mappedId.value)
|
|
52
|
+
})
|
|
53
|
+
</script>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
interface MagicMenuViewProps {
|
|
2
|
+
id?: string;
|
|
3
|
+
}
|
|
4
|
+
declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__VLS_TypePropsToOption<MagicMenuViewProps>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToOption<MagicMenuViewProps>>>, {}, {}>, {
|
|
5
|
+
default?(_: {}): any;
|
|
6
|
+
}>;
|
|
7
|
+
export default _default;
|
|
8
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
9
|
+
new (): {
|
|
10
|
+
$slots: S;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
14
|
+
type __VLS_TypePropsToOption<T> = {
|
|
15
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
16
|
+
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
17
|
+
} : {
|
|
18
|
+
type: import('vue').PropType<T[K]>;
|
|
19
|
+
required: true;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type MaybeRef } from 'vue';
|
|
2
|
+
import type { MenuState } from '../../types.js';
|
|
3
|
+
type UseMenuCallbackArgs = {
|
|
4
|
+
state: MenuState;
|
|
5
|
+
instanceId: MaybeRef<string>;
|
|
6
|
+
viewId: string;
|
|
7
|
+
lockScroll: () => void;
|
|
8
|
+
unlockScroll: () => void;
|
|
9
|
+
};
|
|
10
|
+
export declare function useMenuCallback(args: UseMenuCallbackArgs): {
|
|
11
|
+
onBeforeEnter: (_el: Element) => void;
|
|
12
|
+
onEnter: (_el: Element) => void;
|
|
13
|
+
onAfterEnter: (_el: Element) => void;
|
|
14
|
+
onBeforeLeave: (_el: Element) => void;
|
|
15
|
+
onLeave: (_el: Element) => void;
|
|
16
|
+
onAfterLeave: (_el: Element) => void;
|
|
17
|
+
};
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { toValue } from "vue";
|
|
2
|
+
import { useMagicEmitter } from "@maas/vue-equipment/plugins";
|
|
3
|
+
export function useMenuCallback(args) {
|
|
4
|
+
const { state, instanceId, viewId, lockScroll, unlockScroll } = args;
|
|
5
|
+
const emitter = useMagicEmitter();
|
|
6
|
+
function onBeforeEnter(_el) {
|
|
7
|
+
emitter.emit("beforeEnter", { id: toValue(instanceId), view: viewId });
|
|
8
|
+
}
|
|
9
|
+
function onEnter(_el) {
|
|
10
|
+
emitter.emit("enter", { id: toValue(instanceId), view: viewId });
|
|
11
|
+
}
|
|
12
|
+
function onAfterEnter(_el) {
|
|
13
|
+
emitter.emit("afterEnter", { id: toValue(instanceId), view: viewId });
|
|
14
|
+
switch (state.options.mode) {
|
|
15
|
+
case "dropdown":
|
|
16
|
+
lockScroll();
|
|
17
|
+
break;
|
|
18
|
+
case "menubar":
|
|
19
|
+
break;
|
|
20
|
+
case "context":
|
|
21
|
+
lockScroll();
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function onBeforeLeave(_el) {
|
|
26
|
+
emitter.emit("beforeLeave", { id: toValue(instanceId), view: viewId });
|
|
27
|
+
}
|
|
28
|
+
function onLeave(_el) {
|
|
29
|
+
emitter.emit("leave", { id: toValue(instanceId), view: viewId });
|
|
30
|
+
}
|
|
31
|
+
function onAfterLeave(_el) {
|
|
32
|
+
emitter.emit("afterLeave", { id: toValue(instanceId), view: viewId });
|
|
33
|
+
switch (state.options.mode) {
|
|
34
|
+
case "dropdown":
|
|
35
|
+
unlockScroll();
|
|
36
|
+
break;
|
|
37
|
+
case "menubar":
|
|
38
|
+
break;
|
|
39
|
+
case "context":
|
|
40
|
+
unlockScroll();
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
onBeforeEnter,
|
|
46
|
+
onEnter,
|
|
47
|
+
onAfterEnter,
|
|
48
|
+
onBeforeLeave,
|
|
49
|
+
onLeave,
|
|
50
|
+
onAfterLeave
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ref } from "vue";
|
|
2
|
+
import { useScrollLock } from "@vueuse/core";
|
|
3
|
+
import { matchClass } from "@maas/vue-equipment/utils";
|
|
4
|
+
const scrollLock = typeof window !== "undefined" ? useScrollLock(document?.documentElement) : ref(false);
|
|
5
|
+
export function useMenuDOM() {
|
|
6
|
+
const positionFixedElements = ref([]);
|
|
7
|
+
function lockScroll() {
|
|
8
|
+
scrollLock.value = true;
|
|
9
|
+
}
|
|
10
|
+
function unlockScroll() {
|
|
11
|
+
scrollLock.value = false;
|
|
12
|
+
}
|
|
13
|
+
function addScrollLockPadding() {
|
|
14
|
+
if (typeof window === "undefined")
|
|
15
|
+
return;
|
|
16
|
+
const exclude = new RegExp(/magic-menu?/);
|
|
17
|
+
const scrollbarWidth = window.innerWidth - document.body.offsetWidth;
|
|
18
|
+
document.body.style.setProperty("--scrollbar-width", `${scrollbarWidth}px`);
|
|
19
|
+
document.body.style.paddingRight = "var(--scrollbar-width)";
|
|
20
|
+
positionFixedElements.value = [
|
|
21
|
+
...document.body.getElementsByTagName("*")
|
|
22
|
+
].filter(
|
|
23
|
+
(x) => getComputedStyle(x, null).getPropertyValue("position") === "fixed" && !matchClass(x, exclude)
|
|
24
|
+
);
|
|
25
|
+
positionFixedElements.value.forEach(
|
|
26
|
+
(elem) => elem.style.paddingRight = "var(--scrollbar-width)"
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
function removeScrollLockPadding() {
|
|
30
|
+
document.body.style.paddingRight = "";
|
|
31
|
+
document.body.style.removeProperty("--scrollbar-width");
|
|
32
|
+
positionFixedElements.value.forEach(
|
|
33
|
+
(elem) => elem.style.paddingRight = ""
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
lockScroll,
|
|
38
|
+
unlockScroll,
|
|
39
|
+
addScrollLockPadding,
|
|
40
|
+
removeScrollLockPadding
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type MaybeRef } from 'vue';
|
|
2
|
+
import type { MenuItem } from '../../types/index.js';
|
|
3
|
+
type UseMenuItemArgs = {
|
|
4
|
+
instanceId: MaybeRef<string>;
|
|
5
|
+
viewId: string;
|
|
6
|
+
};
|
|
7
|
+
type InitializeItemArgs = Pick<MenuItem, 'id' | 'disabled'>;
|
|
8
|
+
export declare function useMenuItem(args: UseMenuItemArgs): {
|
|
9
|
+
initializeItem: (args: InitializeItemArgs) => MenuItem;
|
|
10
|
+
deleteItem: (id: string) => void;
|
|
11
|
+
getItem: (id: string) => MenuItem | undefined;
|
|
12
|
+
selectItem: (id: string) => void;
|
|
13
|
+
unselectItem: (id: string) => void;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { reactive } from "vue";
|
|
2
|
+
import { useMenuView } from "./useMenuView.mjs";
|
|
3
|
+
import { useMenuState } from "./useMenuState.mjs";
|
|
4
|
+
export function useMenuItem(args) {
|
|
5
|
+
const { instanceId, viewId } = args;
|
|
6
|
+
const { initializeState } = useMenuState(instanceId);
|
|
7
|
+
const state = initializeState();
|
|
8
|
+
const { getView, unselectNonTreeViews } = useMenuView(instanceId);
|
|
9
|
+
const view = getView(viewId);
|
|
10
|
+
if (!view) {
|
|
11
|
+
throw new Error(`View ${viewId} not found`);
|
|
12
|
+
}
|
|
13
|
+
function createItem(args2) {
|
|
14
|
+
const { id, disabled } = args2;
|
|
15
|
+
const item = {
|
|
16
|
+
id,
|
|
17
|
+
active: false,
|
|
18
|
+
disabled
|
|
19
|
+
};
|
|
20
|
+
return reactive(item);
|
|
21
|
+
}
|
|
22
|
+
function addItem(args2) {
|
|
23
|
+
const item = createItem(args2);
|
|
24
|
+
if (view?.items) {
|
|
25
|
+
view.items = [...view?.items, item];
|
|
26
|
+
}
|
|
27
|
+
return item;
|
|
28
|
+
}
|
|
29
|
+
function unselectSiblings(id) {
|
|
30
|
+
return view?.items.filter((item) => item.id !== id).forEach((item) => item.active = false);
|
|
31
|
+
}
|
|
32
|
+
function initializeItem(args2) {
|
|
33
|
+
const { id } = args2;
|
|
34
|
+
const instance = getItem(id);
|
|
35
|
+
if (!instance) {
|
|
36
|
+
const item = addItem(args2);
|
|
37
|
+
return item;
|
|
38
|
+
}
|
|
39
|
+
return instance;
|
|
40
|
+
}
|
|
41
|
+
function deleteItem(id) {
|
|
42
|
+
if (!view?.items)
|
|
43
|
+
return;
|
|
44
|
+
view.items = view.items.filter((x) => x.id !== id);
|
|
45
|
+
}
|
|
46
|
+
function getItem(id) {
|
|
47
|
+
return view?.items.find((item) => {
|
|
48
|
+
return item.id === id;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
function selectItem(id) {
|
|
52
|
+
const instance = getItem(id);
|
|
53
|
+
if (instance) {
|
|
54
|
+
instance.active = true;
|
|
55
|
+
unselectSiblings(id);
|
|
56
|
+
unselectNonTreeViews(viewId);
|
|
57
|
+
if (view) {
|
|
58
|
+
state.input.view = view.id;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function unselectItem(id) {
|
|
63
|
+
const instance = getItem(id);
|
|
64
|
+
if (instance) {
|
|
65
|
+
instance.active = false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
initializeItem,
|
|
70
|
+
deleteItem,
|
|
71
|
+
getItem,
|
|
72
|
+
selectItem,
|
|
73
|
+
unselectItem
|
|
74
|
+
};
|
|
75
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type MaybeRef } from 'vue';
|
|
2
|
+
export declare function useMenuKeyListener(instanceId: MaybeRef<string>): {
|
|
3
|
+
onArrowRight: (e: KeyboardEvent) => Promise<void>;
|
|
4
|
+
onArrowLeft: (e: KeyboardEvent) => void;
|
|
5
|
+
onArrowUp: (e: KeyboardEvent) => void;
|
|
6
|
+
onArrowDown: (e: KeyboardEvent) => void;
|
|
7
|
+
onEscape: (e: KeyboardEvent) => void;
|
|
8
|
+
onEnter: (e: KeyboardEvent) => Promise<void>;
|
|
9
|
+
onTab: (e: KeyboardEvent) => void;
|
|
10
|
+
};
|