@maas/vue-equipment 1.0.0-beta.34 → 1.0.0-beta.35
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/.turbo/turbo-lint.log +92 -1
- package/dist/plugins/MagicAccordion/src/components/MagicAccordionContent.vue +15 -6
- package/dist/plugins/MagicAccordion/src/components/MagicAccordionTrigger.vue +15 -10
- package/dist/plugins/MagicAccordion/src/components/MagicAccordionView.vue +11 -5
- package/dist/plugins/MagicCommand/src/components/MagicCommandContent.vue +15 -8
- package/dist/plugins/MagicCommand/src/components/MagicCommandDrawer.vue +11 -5
- package/dist/plugins/MagicCommand/src/components/MagicCommandItem.vue +19 -9
- package/dist/plugins/MagicCommand/src/components/MagicCommandRenderer.vue +11 -5
- package/dist/plugins/MagicCommand/src/components/MagicCommandTrigger.vue +15 -10
- package/dist/plugins/MagicCommand/src/components/MagicCommandView.vue +11 -3
- package/dist/plugins/MagicCommand/src/composables/private/useCommandView.d.ts +1 -1
- package/dist/plugins/MagicCommand/src/composables/private/useCommandView.mjs +42 -37
- package/dist/plugins/MagicCommand/src/composables/useMagicCommand.mjs +21 -4
- package/dist/plugins/MagicCookie/src/components/MagicCookieItem.vue +12 -3
- package/dist/plugins/MagicCookie/src/components/MagicCookieView.vue +11 -5
- package/dist/plugins/MagicCookie/src/composables/private/useCookieItem.mjs +6 -1
- package/dist/plugins/MagicDraggable/src/components/MagicDraggable.vue +11 -1
- package/dist/plugins/MagicDraggable/src/composables/private/useDraggableDrag.mjs +8 -3
- package/dist/plugins/MagicDraggable/src/composables/private/useDraggableSnap.mjs +7 -2
- package/dist/plugins/MagicDrawer/src/components/MagicDrawer.vue +6 -1
- package/dist/plugins/MagicDrawer/src/composables/private/useDrawerDrag.mjs +6 -1
- package/dist/plugins/MagicDrawer/src/composables/private/useDrawerWheel.mjs +6 -1
- package/dist/plugins/MagicError/index.d.ts +5 -0
- package/dist/plugins/MagicError/index.mjs +3 -0
- package/dist/plugins/MagicError/nuxt.d.ts +2 -0
- package/dist/plugins/MagicError/nuxt.mjs +12 -0
- package/dist/plugins/MagicError/package.json +40 -0
- package/dist/plugins/MagicError/src/MagicError.d.ts +0 -0
- package/dist/plugins/MagicError/src/MagicError.mjs +0 -0
- package/dist/plugins/MagicError/src/class/MagicError.d.ts +6 -0
- package/dist/plugins/MagicError/src/class/MagicError.mjs +15 -0
- package/dist/plugins/MagicError/src/composables/useMagicError.d.ts +18 -0
- package/dist/plugins/MagicError/src/composables/useMagicError.mjs +31 -0
- package/dist/plugins/MagicMenu/src/components/MagicMenuChannel.vue +22 -10
- package/dist/plugins/MagicMenu/src/components/MagicMenuContent.vue +15 -6
- package/dist/plugins/MagicMenu/src/components/MagicMenuItem.vue +19 -9
- package/dist/plugins/MagicMenu/src/components/MagicMenuRemote.vue +19 -13
- package/dist/plugins/MagicMenu/src/components/MagicMenuTrigger.vue +15 -10
- package/dist/plugins/MagicMenu/src/components/MagicMenuView.vue +11 -3
- package/dist/plugins/MagicMenu/src/composables/private/useMenuItem.mjs +9 -1
- package/dist/plugins/MagicMenu/src/composables/private/useMenuKeyListener.mjs +16 -8
- package/dist/plugins/MagicMenu/src/composables/private/useMenuView.mjs +7 -2
- package/dist/plugins/MagicPie/src/components/MagicPie.vue +15 -2
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerAudio.vue +17 -7
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerAudioControls.vue +11 -5
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerDisplayTime.vue +11 -5
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerMuxPopover.vue +29 -14
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerOverlay.vue +11 -5
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerPoster.vue +11 -5
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerTimeline.vue +11 -5
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerVideo.vue +17 -7
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerVideoControls.vue +11 -5
- package/dist/plugins/MagicPlayer/src/composables/private/usePlayerMediaApi.mjs +65 -11
- package/dist/plugins/MagicPlayer/src/composables/private/usePlayerRuntime.d.ts +1 -0
- package/dist/plugins/MagicPlayer/src/composables/private/usePlayerRuntime.mjs +96 -16
- package/dist/plugins/MagicPlayer/src/composables/private/usePlayerVideoApi.mjs +7 -2
- package/dist/plugins/MagicPlayer/src/types/index.d.ts +2 -0
- package/dist/plugins/MagicPlayer/src/utils/defaultOptions.mjs +1 -0
- package/dist/plugins/MagicScroll/src/components/MagicScrollCollision.vue +12 -6
- package/dist/plugins/MagicScroll/src/components/MagicScrollScene.vue +11 -3
- package/dist/plugins/MagicToast/src/components/MagicToastView.vue +11 -3
- package/dist/plugins/MagicToast/src/composables/private/useToastCallback.d.ts +2 -2
- package/dist/plugins/MagicToast/src/composables/private/useToastCallback.mjs +7 -5
- package/package.json +11 -8
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { computed, nextTick } from "vue";
|
|
2
|
+
import { useMagicError } from "@maas/vue-equipment/plugins/MagicError";
|
|
2
3
|
import { useCommandState } from "./private/useCommandState.mjs";
|
|
3
4
|
import { useCommandItem } from "./private/useCommandItem.mjs";
|
|
4
5
|
import { useCommandView } from "./private/useCommandView.mjs";
|
|
6
|
+
const { throwError } = useMagicError({
|
|
7
|
+
prefix: "MagicCommand",
|
|
8
|
+
source: "useMagicCommand"
|
|
9
|
+
});
|
|
5
10
|
export function useMagicCommand(id) {
|
|
6
11
|
const { initializeState } = useCommandState(id);
|
|
7
12
|
const state = initializeState();
|
|
@@ -20,10 +25,16 @@ export function useMagicCommand(id) {
|
|
|
20
25
|
function selectItem(args) {
|
|
21
26
|
const { id: id2, viewId } = args;
|
|
22
27
|
if (!viewId) {
|
|
23
|
-
|
|
28
|
+
throwError({
|
|
29
|
+
message: "viewId is required to select an item",
|
|
30
|
+
errorCode: "view_id_required"
|
|
31
|
+
});
|
|
24
32
|
}
|
|
25
33
|
if (!id2) {
|
|
26
|
-
|
|
34
|
+
throwError({
|
|
35
|
+
message: "id is required to select an item",
|
|
36
|
+
errorCode: "id_required"
|
|
37
|
+
});
|
|
27
38
|
}
|
|
28
39
|
const { selectItem: selectItem2 } = useCommandItem({
|
|
29
40
|
instanceId: id2,
|
|
@@ -34,10 +45,16 @@ export function useMagicCommand(id) {
|
|
|
34
45
|
function unselectItem(args) {
|
|
35
46
|
const { id: id2, viewId } = args;
|
|
36
47
|
if (!viewId) {
|
|
37
|
-
|
|
48
|
+
throwError({
|
|
49
|
+
message: "viewId is required to select an item",
|
|
50
|
+
errorCode: "view_id_required"
|
|
51
|
+
});
|
|
38
52
|
}
|
|
39
53
|
if (!id2) {
|
|
40
|
-
|
|
54
|
+
throwError({
|
|
55
|
+
message: "id is required to select an item",
|
|
56
|
+
errorCode: "id_required"
|
|
57
|
+
});
|
|
41
58
|
}
|
|
42
59
|
const { unselectItem: unselectItem2 } = useCommandItem({
|
|
43
60
|
instanceId: id2,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div
|
|
3
3
|
class="magic-cookie-item"
|
|
4
|
+
:data-id="mappedId"
|
|
4
5
|
:data-optional="item.optional"
|
|
5
6
|
:data-active="item.active"
|
|
6
7
|
>
|
|
@@ -10,6 +11,9 @@
|
|
|
10
11
|
|
|
11
12
|
<script setup>
|
|
12
13
|
import { computed, inject, provide, onBeforeUnmount, useId } from "vue";
|
|
14
|
+
import {
|
|
15
|
+
useMagicError
|
|
16
|
+
} from "@maas/vue-equipment/plugins/MagicError";
|
|
13
17
|
import { useCookieItem } from "../composables/private/useCookieItem";
|
|
14
18
|
import {
|
|
15
19
|
MagicCookieInstanceId,
|
|
@@ -21,10 +25,15 @@ const { id, optional, maxAge } = defineProps({
|
|
|
21
25
|
optional: { type: Boolean, required: false },
|
|
22
26
|
maxAge: { type: Number, required: false }
|
|
23
27
|
});
|
|
28
|
+
const magicError = useMagicError({
|
|
29
|
+
prefix: "MagicCookie",
|
|
30
|
+
source: "MagicCookieItem"
|
|
31
|
+
});
|
|
24
32
|
const instanceId = inject(MagicCookieInstanceId, void 0);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
33
|
+
magicError.assert(instanceId, {
|
|
34
|
+
message: "MagicCookieItem must be nested inside MagicCookieProvider",
|
|
35
|
+
errorCode: "missing_instance_id"
|
|
36
|
+
});
|
|
28
37
|
const mappedId = computed(() => id ?? `magic-cookie-item-${useId()}`);
|
|
29
38
|
const mappedActive = computed(() => item.active);
|
|
30
39
|
const { initializeItem, deleteItem } = useCookieItem({
|
|
@@ -24,17 +24,23 @@
|
|
|
24
24
|
<script setup>
|
|
25
25
|
import { inject } from "vue";
|
|
26
26
|
import { AutoSize } from "@maas/vue-autosize";
|
|
27
|
+
import {
|
|
28
|
+
useMagicError
|
|
29
|
+
} from "@maas/vue-equipment/plugins/MagicError";
|
|
27
30
|
import { useCookieState } from "../composables/private/useCookieState";
|
|
28
31
|
import { useCookieCallback } from "../composables/private/useCookieCallback";
|
|
29
32
|
import { MagicCookieInstanceId } from "../symbols";
|
|
30
33
|
import "@maas/vue-equipment/utils/css/keyframes/fade-in.css";
|
|
31
34
|
import "@maas/vue-equipment/utils/css/keyframes/auto-size-out.css";
|
|
35
|
+
const magicError = useMagicError({
|
|
36
|
+
prefix: "MagicCookie",
|
|
37
|
+
source: "MagicCookieView"
|
|
38
|
+
});
|
|
32
39
|
const instanceId = inject(MagicCookieInstanceId, void 0);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
40
|
+
magicError.assert(instanceId, {
|
|
41
|
+
message: "MagicCookieView must be used within a MagicCookieProvider",
|
|
42
|
+
errorCode: "missing_instance_id"
|
|
43
|
+
});
|
|
38
44
|
const { initializeState } = useCookieState(instanceId);
|
|
39
45
|
const state = initializeState();
|
|
40
46
|
const {
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { reactive, toValue } from "vue";
|
|
2
2
|
import { useCookies } from "@vueuse/integrations/useCookies";
|
|
3
|
+
import { useMagicError } from "@maas/vue-equipment/plugins/MagicError";
|
|
3
4
|
import { useCookieState } from "./useCookieState.mjs";
|
|
4
5
|
export function useCookieItem(args) {
|
|
5
6
|
const { instanceId } = args;
|
|
7
|
+
const { logWarning } = useMagicError({
|
|
8
|
+
prefix: "MagicCookie",
|
|
9
|
+
source: "useCookieItem"
|
|
10
|
+
});
|
|
6
11
|
const { initializeState } = useCookieState(instanceId);
|
|
7
12
|
const state = initializeState();
|
|
8
13
|
function getBrowserCookie(id) {
|
|
@@ -67,7 +72,7 @@ export function useCookieItem(args) {
|
|
|
67
72
|
function setItemCookie(id) {
|
|
68
73
|
const item = getItem(id);
|
|
69
74
|
if (!item) {
|
|
70
|
-
|
|
75
|
+
logWarning(`Item ${id} not found. Cookie cannot be set.`);
|
|
71
76
|
return;
|
|
72
77
|
}
|
|
73
78
|
useCookies([id]).set(toValue(id), item.active, {
|
|
@@ -26,6 +26,9 @@
|
|
|
26
26
|
<script setup>
|
|
27
27
|
import { useTemplateRef, computed, toValue, toRefs } from "vue";
|
|
28
28
|
import { createDefu } from "defu";
|
|
29
|
+
import {
|
|
30
|
+
useMagicError
|
|
31
|
+
} from "@maas/vue-equipment/plugins/MagicError";
|
|
29
32
|
import { useDraggableDrag } from "../composables/private/useDraggableDrag";
|
|
30
33
|
import { useDraggableState } from "../composables/private/useDraggableState";
|
|
31
34
|
import { defaultOptions } from "../utils/defaultOptions";
|
|
@@ -36,6 +39,10 @@ const { id, options = {} } = defineProps({
|
|
|
36
39
|
id: { type: null, required: true },
|
|
37
40
|
options: { type: Object, required: false }
|
|
38
41
|
});
|
|
42
|
+
const magicError = useMagicError({
|
|
43
|
+
prefix: "MagicDraggable",
|
|
44
|
+
source: "MagicDraggable"
|
|
45
|
+
});
|
|
39
46
|
const customDefu = createDefu((obj, key, value) => {
|
|
40
47
|
if (key === "snapPoints") {
|
|
41
48
|
obj[key] = value;
|
|
@@ -45,7 +52,10 @@ const customDefu = createDefu((obj, key, value) => {
|
|
|
45
52
|
const mappedOptions = customDefu(options, defaultOptions);
|
|
46
53
|
const mappedId = toValue(id);
|
|
47
54
|
if (!mappedOptions.snapPoints.length) {
|
|
48
|
-
|
|
55
|
+
magicError.throwError({
|
|
56
|
+
message: "MagicDraggable must have at least one snap point set",
|
|
57
|
+
errorCode: "missing_snap_point"
|
|
58
|
+
});
|
|
49
59
|
}
|
|
50
60
|
const elRef = useTemplateRef("el");
|
|
51
61
|
const wrapperRef = useTemplateRef("wrapper");
|
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
import {
|
|
25
25
|
useMagicEmitter
|
|
26
26
|
} from "@maas/vue-equipment/plugins/MagicEmitter";
|
|
27
|
+
import { useMagicError } from "@maas/vue-equipment/plugins/MagicError";
|
|
27
28
|
import { useDraggableSnap } from "./useDraggableSnap.mjs";
|
|
28
29
|
import { useDraggableState } from "./useDraggableState.mjs";
|
|
29
30
|
import { useDraggableScrollLock } from "./useDraggableScrollLock.mjs";
|
|
@@ -38,6 +39,10 @@ export function useDraggableDrag(args) {
|
|
|
38
39
|
animation,
|
|
39
40
|
scrollLock
|
|
40
41
|
} = args;
|
|
42
|
+
const { logWarning } = useMagicError({
|
|
43
|
+
prefix: "MagicDraggable",
|
|
44
|
+
source: "useDraggableDrag"
|
|
45
|
+
});
|
|
41
46
|
const { initializeState } = useDraggableState(toValue(id));
|
|
42
47
|
const state = initializeState();
|
|
43
48
|
const {
|
|
@@ -127,11 +132,11 @@ export function useDraggableDrag(args) {
|
|
|
127
132
|
const childRect = toValue(elRect);
|
|
128
133
|
const parentRect = toValue(wrapperRect);
|
|
129
134
|
if (!childRect || !parentRect) {
|
|
130
|
-
|
|
135
|
+
logWarning("Could not calculate sizing");
|
|
131
136
|
return;
|
|
132
137
|
}
|
|
133
138
|
if (childRect.width > parentRect.width || childRect.height > parentRect.height) {
|
|
134
|
-
|
|
139
|
+
logWarning("Element is too small for its content");
|
|
135
140
|
return;
|
|
136
141
|
}
|
|
137
142
|
}
|
|
@@ -350,7 +355,7 @@ export function useDraggableDrag(args) {
|
|
|
350
355
|
if (elRect.value && wrapperRect.value) {
|
|
351
356
|
emitter.on("snapTo", snapToCallback);
|
|
352
357
|
if (elRect.value.width > wrapperRect.value.width || elRect.value.height > wrapperRect.value.height) {
|
|
353
|
-
|
|
358
|
+
logWarning("is too small for its content");
|
|
354
359
|
return;
|
|
355
360
|
}
|
|
356
361
|
}
|
|
@@ -2,12 +2,17 @@ import { ref, toRefs, computed, toValue, nextTick } from "vue";
|
|
|
2
2
|
import { computedWithControl } from "@vueuse/core";
|
|
3
3
|
import { interpolate } from "@maas/vue-equipment/utils";
|
|
4
4
|
import { useMagicEmitter } from "@maas/vue-equipment/plugins/MagicEmitter";
|
|
5
|
+
import { useMagicError } from "@maas/vue-equipment/plugins/MagicError";
|
|
5
6
|
import { defu } from "defu";
|
|
6
7
|
import { useDraggableState } from "./useDraggableState.mjs";
|
|
7
8
|
export function useDraggableSnap(args) {
|
|
8
9
|
const { id, animation, snapPoints } = args;
|
|
9
10
|
const { initializeState } = useDraggableState(toValue(id));
|
|
10
11
|
const state = initializeState();
|
|
12
|
+
const { logWarning } = useMagicError({
|
|
13
|
+
prefix: "MagicDraggable",
|
|
14
|
+
source: "useDraggableSnap"
|
|
15
|
+
});
|
|
11
16
|
const {
|
|
12
17
|
lastDraggedX,
|
|
13
18
|
lastDraggedY,
|
|
@@ -54,11 +59,11 @@ export function useDraggableSnap(args) {
|
|
|
54
59
|
const emitter = useMagicEmitter();
|
|
55
60
|
function mapSnapPoint(snapPoint) {
|
|
56
61
|
if (!wrapperRect.value) {
|
|
57
|
-
|
|
62
|
+
logWarning("Wrapper rect is not defined");
|
|
58
63
|
return void 0;
|
|
59
64
|
}
|
|
60
65
|
if (!elRect.value) {
|
|
61
|
-
|
|
66
|
+
logWarning("Element rect is not defined");
|
|
62
67
|
return void 0;
|
|
63
68
|
}
|
|
64
69
|
const mappedSnapPoint = typeof snapPoint === "string" ? [snapPoint] : snapPoint;
|
|
@@ -72,6 +72,7 @@ import {
|
|
|
72
72
|
} from "vue";
|
|
73
73
|
import { createDefu } from "defu";
|
|
74
74
|
import { onKeyStroke, unrefElement } from "@vueuse/core";
|
|
75
|
+
import { useMagicError } from "@maas/vue-equipment/plugins/MagicError";
|
|
75
76
|
import { useMetaViewport } from "@maas/vue-equipment/composables/useMetaViewport";
|
|
76
77
|
import { defaultOptions } from "./../utils/defaultOptions";
|
|
77
78
|
import { useDrawerDOM } from "../composables/private/useDrawerDOM";
|
|
@@ -121,6 +122,10 @@ const {
|
|
|
121
122
|
focusTrap: mappedOptions.focusTrap
|
|
122
123
|
});
|
|
123
124
|
const { isActive, open, close } = useMagicDrawer(id);
|
|
125
|
+
const { logWarning } = useMagicError({
|
|
126
|
+
prefix: "MagicDrawer",
|
|
127
|
+
source: "MagicDrawer"
|
|
128
|
+
});
|
|
124
129
|
const overshoot = shallowRef(0);
|
|
125
130
|
const {
|
|
126
131
|
position,
|
|
@@ -196,7 +201,7 @@ function convertToPixels(value) {
|
|
|
196
201
|
const regex = /^(\d*\.?\d+)\s*(rem|px)$/;
|
|
197
202
|
const match = value.match(regex);
|
|
198
203
|
if (!match) {
|
|
199
|
-
|
|
204
|
+
logWarning(
|
|
200
205
|
`--magic-drawer-drag-overshoot (${value}) needs to be specified in px or rem`
|
|
201
206
|
);
|
|
202
207
|
return 0;
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
import {
|
|
24
24
|
useMagicEmitter
|
|
25
25
|
} from "@maas/vue-equipment/plugins/MagicEmitter";
|
|
26
|
+
import { useMagicError } from "@maas/vue-equipment/plugins/MagicError";
|
|
26
27
|
import { useMagicDrawer } from "./../useMagicDrawer.mjs";
|
|
27
28
|
import { useDrawerSnap } from "./useDrawerSnap.mjs";
|
|
28
29
|
import { useDrawerGuards } from "./useDrawerGuards.mjs";
|
|
@@ -42,6 +43,10 @@ export function useDrawerDrag(args) {
|
|
|
42
43
|
preventDragClose,
|
|
43
44
|
disabled
|
|
44
45
|
} = args;
|
|
46
|
+
const { logWarning } = useMagicError({
|
|
47
|
+
prefix: "MagicDrawer",
|
|
48
|
+
source: "useDrawerDrag"
|
|
49
|
+
});
|
|
45
50
|
const { initializeState } = useDrawerState(toValue(id));
|
|
46
51
|
const state = initializeState();
|
|
47
52
|
const {
|
|
@@ -285,7 +290,7 @@ export function useDrawerDrag(args) {
|
|
|
285
290
|
function snapToCallback(payload) {
|
|
286
291
|
if (payload.id === toValue(id)) {
|
|
287
292
|
if (!toValue(isActive)) {
|
|
288
|
-
|
|
293
|
+
logWarning("Cannot snap to point when drawer is not open");
|
|
289
294
|
return;
|
|
290
295
|
} else {
|
|
291
296
|
snapTo({
|
|
@@ -5,9 +5,14 @@ import {
|
|
|
5
5
|
} from "vue";
|
|
6
6
|
import { unrefElement } from "@vueuse/core";
|
|
7
7
|
import WheelGestures, {} from "wheel-gestures";
|
|
8
|
+
import { useMagicError } from "@maas/vue-equipment/plugins/MagicError";
|
|
8
9
|
import { useDrawerState } from "./useDrawerState.mjs";
|
|
9
10
|
export function useDrawerWheel(args) {
|
|
10
11
|
const { id, elRef, position, disabled } = args;
|
|
12
|
+
const { logError } = useMagicError({
|
|
13
|
+
prefix: "MagicDrawer",
|
|
14
|
+
source: "useDrawerWheel"
|
|
15
|
+
});
|
|
11
16
|
const { initializeState } = useDrawerState(toValue(id));
|
|
12
17
|
const state = initializeState();
|
|
13
18
|
const { dragging, wheeling } = toRefs(state);
|
|
@@ -56,7 +61,7 @@ export function useDrawerWheel(args) {
|
|
|
56
61
|
dispatchEvent(startEvent);
|
|
57
62
|
wheeling.value = true;
|
|
58
63
|
} catch (e) {
|
|
59
|
-
|
|
64
|
+
logError(String(e));
|
|
60
65
|
return destroyWheelListener();
|
|
61
66
|
}
|
|
62
67
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { useMagicError } from './src/composables/useMagicError.js';
|
|
2
|
+
import { MagicError } from './src/class/MagicError.js';
|
|
3
|
+
import type { UseMagicErrorReturn } from './src/composables/useMagicError.js';
|
|
4
|
+
export { useMagicError, MagicError };
|
|
5
|
+
export type { UseMagicErrorReturn };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { defineNuxtModule, addImports } from "@nuxt/kit";
|
|
2
|
+
export default defineNuxtModule({
|
|
3
|
+
meta: {
|
|
4
|
+
name: "@maas/vue-equipment/nuxt/MagicError"
|
|
5
|
+
},
|
|
6
|
+
setup() {
|
|
7
|
+
addImports({
|
|
8
|
+
from: "@maas/vue-equipment/plugins/MagicError",
|
|
9
|
+
name: "useMagicError"
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@maas/magic-error",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Vue composable for centralized error handling with custom error classes",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"vue",
|
|
7
|
+
"composable",
|
|
8
|
+
"error",
|
|
9
|
+
"error-handling",
|
|
10
|
+
"typescript"
|
|
11
|
+
],
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"type": "module",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"main": "./dist/index.js",
|
|
21
|
+
"module": "./dist/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsup",
|
|
28
|
+
"build:types": "tsup --dts-only",
|
|
29
|
+
"dev": "tsup --watch",
|
|
30
|
+
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
|
|
31
|
+
"test": "vitest",
|
|
32
|
+
"test:coverage": "vitest --coverage"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"vue": "^3.0.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@vue/tsconfig": "^0.5.1"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export class MagicError extends Error {
|
|
2
|
+
errorCode;
|
|
3
|
+
timestamp;
|
|
4
|
+
source;
|
|
5
|
+
constructor(message, errorCode, source, options) {
|
|
6
|
+
super(message, options);
|
|
7
|
+
this.name = "MagicError";
|
|
8
|
+
this.errorCode = errorCode;
|
|
9
|
+
this.timestamp = Date.now();
|
|
10
|
+
this.source = source;
|
|
11
|
+
if (Error.captureStackTrace) {
|
|
12
|
+
Error.captureStackTrace(this, MagicError);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { MagicError } from '../class/MagicError.js';
|
|
2
|
+
export interface UseMagicErrorArgs {
|
|
3
|
+
prefix?: string;
|
|
4
|
+
source?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface ThrowErrorArgs {
|
|
7
|
+
message: string;
|
|
8
|
+
errorCode: string | number;
|
|
9
|
+
cause?: unknown;
|
|
10
|
+
}
|
|
11
|
+
export interface UseMagicErrorReturn {
|
|
12
|
+
assert<T>(value: T, args: ThrowErrorArgs): asserts value is NonNullable<T>;
|
|
13
|
+
throwError(args: ThrowErrorArgs): never;
|
|
14
|
+
logError(message: string): void;
|
|
15
|
+
logWarning(message: string): void;
|
|
16
|
+
MagicError: typeof MagicError;
|
|
17
|
+
}
|
|
18
|
+
export declare function useMagicError(args?: UseMagicErrorArgs): UseMagicErrorReturn;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { MagicError } from "../class/MagicError.mjs";
|
|
2
|
+
export function useMagicError(args = {}) {
|
|
3
|
+
const { prefix = "MagicError", source = "vue-equipment" } = args;
|
|
4
|
+
function logError(message) {
|
|
5
|
+
console.error(`[${prefix}]:`, message);
|
|
6
|
+
}
|
|
7
|
+
function logWarning(message) {
|
|
8
|
+
console.warn(`[${prefix}]:`, message);
|
|
9
|
+
}
|
|
10
|
+
function throwError(args2) {
|
|
11
|
+
const { message, errorCode, cause } = args2;
|
|
12
|
+
const mappedMessage = `[${prefix}]: ${message}`;
|
|
13
|
+
const error = new MagicError(mappedMessage, errorCode, source, {
|
|
14
|
+
cause
|
|
15
|
+
});
|
|
16
|
+
logError(message);
|
|
17
|
+
throw error;
|
|
18
|
+
}
|
|
19
|
+
function assert(value, args2) {
|
|
20
|
+
if (value === void 0 || value === null) {
|
|
21
|
+
throwError(args2);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
assert,
|
|
26
|
+
throwError,
|
|
27
|
+
logError,
|
|
28
|
+
logWarning,
|
|
29
|
+
MagicError
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
|
|
14
14
|
<script setup>
|
|
15
15
|
import { computed, inject, provide } from "vue";
|
|
16
|
+
import {
|
|
17
|
+
useMagicError
|
|
18
|
+
} from "@maas/vue-equipment/plugins/MagicError";
|
|
16
19
|
import { useMenuChannel } from "../composables/private/useMenuChannel";
|
|
17
20
|
import {
|
|
18
21
|
MagicMenuInstanceId,
|
|
@@ -26,23 +29,32 @@ const { transition, id } = defineProps({
|
|
|
26
29
|
id: { type: String, required: true },
|
|
27
30
|
transition: { type: String, required: false }
|
|
28
31
|
});
|
|
32
|
+
const magicError = useMagicError({
|
|
33
|
+
prefix: "MagicMenu",
|
|
34
|
+
source: "MagicMenu"
|
|
35
|
+
});
|
|
29
36
|
const instanceId = inject(MagicMenuInstanceId, void 0);
|
|
30
37
|
const viewId = inject(MagicMenuViewId, void 0);
|
|
31
38
|
const contentId = inject(MagicMenuContentId, void 0);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
magicError.assert(instanceId, {
|
|
40
|
+
message: "MagicMenuChannel must be nested inside MagicMenuProvider",
|
|
41
|
+
errorCode: "missing_instance_id"
|
|
42
|
+
});
|
|
43
|
+
magicError.assert(viewId, {
|
|
44
|
+
message: "MagicMenuChannel must be nested inside MagicMenuView",
|
|
45
|
+
errorCode: "missing_view_id"
|
|
46
|
+
});
|
|
47
|
+
magicError.assert(id, {
|
|
48
|
+
message: "MagicMenuChannel requires an id",
|
|
49
|
+
errorCode: "id_required"
|
|
50
|
+
});
|
|
41
51
|
const { initializeState } = useMenuState(instanceId);
|
|
42
52
|
const state = initializeState();
|
|
43
53
|
if (!contentId) {
|
|
44
54
|
if (state.options.debug) {
|
|
45
|
-
|
|
55
|
+
magicError.logWarning(
|
|
56
|
+
"MagicMenuChannel is not nested inside MagicMenuContent"
|
|
57
|
+
);
|
|
46
58
|
}
|
|
47
59
|
}
|
|
48
60
|
const mappedId = computed(() => `magic-menu-channel-${id}`);
|
|
@@ -70,6 +70,9 @@ import { useMenuState } from "../composables/private/useMenuState";
|
|
|
70
70
|
import { useMenuCallback } from "../composables/private/useMenuCallback";
|
|
71
71
|
import { useMenuDOM } from "../composables/private/useMenuDOM";
|
|
72
72
|
import { useMenuCursor } from "../composables/private/useMenuCursor";
|
|
73
|
+
import {
|
|
74
|
+
useMagicError
|
|
75
|
+
} from "@maas/vue-equipment/plugins/MagicError";
|
|
73
76
|
import { ModeTransitions } from "../utils/modeTransitionDefaults";
|
|
74
77
|
import { ModeDelayMouseleave } from "../utils/modeDelayDefaults";
|
|
75
78
|
import {
|
|
@@ -88,14 +91,20 @@ const { arrow = void 0, transition } = defineProps({
|
|
|
88
91
|
transition: { type: String, required: false },
|
|
89
92
|
referenceEl: { type: null, required: false }
|
|
90
93
|
});
|
|
94
|
+
const magicError = useMagicError({
|
|
95
|
+
prefix: "MagicMenu",
|
|
96
|
+
source: "MagicMenu"
|
|
97
|
+
});
|
|
91
98
|
const instanceId = inject(MagicMenuInstanceId, void 0);
|
|
92
99
|
const viewId = inject(MagicMenuViewId, void 0);
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
100
|
+
magicError.assert(instanceId, {
|
|
101
|
+
message: "MagicMenuContent must be nested inside MagicMenuProvider",
|
|
102
|
+
errorCode: "missing_instance_id"
|
|
103
|
+
});
|
|
104
|
+
magicError.assert(viewId, {
|
|
105
|
+
message: "MagicMenuContent must be nested inside MagicMenuView",
|
|
106
|
+
errorCode: "missing_view_id"
|
|
107
|
+
});
|
|
99
108
|
const { getView, unselectView } = useMenuView(instanceId);
|
|
100
109
|
const view = getView(viewId);
|
|
101
110
|
const { initializeState } = useMenuState(instanceId);
|
|
@@ -18,6 +18,9 @@
|
|
|
18
18
|
|
|
19
19
|
<script setup>
|
|
20
20
|
import { computed, inject, provide, onBeforeUnmount, watch, useId } from "vue";
|
|
21
|
+
import {
|
|
22
|
+
useMagicError
|
|
23
|
+
} from "@maas/vue-equipment/plugins/MagicError";
|
|
21
24
|
import { useMenuItem } from "../composables/private/useMenuItem";
|
|
22
25
|
import { useMenuState } from "../composables/private/useMenuState";
|
|
23
26
|
import { useMenuView } from "../composables/private/useMenuView";
|
|
@@ -33,18 +36,25 @@ const { id, disabled } = defineProps({
|
|
|
33
36
|
disabled: { type: Boolean, required: false }
|
|
34
37
|
});
|
|
35
38
|
const emit = defineEmits(["click"]);
|
|
39
|
+
const magicError = useMagicError({
|
|
40
|
+
prefix: "MagicMenu",
|
|
41
|
+
source: "MagicMenu"
|
|
42
|
+
});
|
|
36
43
|
const instanceId = inject(MagicMenuInstanceId, void 0);
|
|
37
44
|
const viewId = inject(MagicMenuViewId, void 0);
|
|
38
45
|
const contentId = inject(MagicMenuContentId, void 0);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
magicError.assert(instanceId, {
|
|
47
|
+
message: "MagicMenuItem must be nested inside MagicMenuProvider",
|
|
48
|
+
errorCode: "missing_instance_id"
|
|
49
|
+
});
|
|
50
|
+
magicError.assert(viewId, {
|
|
51
|
+
message: "MagicMenuItem must be nested inside MagicMenuView",
|
|
52
|
+
errorCode: "missing_view_id"
|
|
53
|
+
});
|
|
54
|
+
magicError.assert(contentId, {
|
|
55
|
+
message: "MagicMenuItem must be nested inside MagicMenuContent",
|
|
56
|
+
errorCode: "missing_content_id"
|
|
57
|
+
});
|
|
48
58
|
const mappedId = computed(() => id ?? `magic-menu-item-${useId()}`);
|
|
49
59
|
const mappedActive = computed(() => item.active);
|
|
50
60
|
const { initializeItem, deleteItem, selectItem, unselectItem } = useMenuItem({
|