@maas/vue-equipment 0.5.0 → 0.6.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.
Files changed (54) hide show
  1. package/dist/composables/index.js.map +1 -1
  2. package/dist/composables/index.mjs.map +1 -1
  3. package/dist/nuxt/module.json +1 -1
  4. package/dist/nuxt/module.mjs +16 -2
  5. package/dist/plugins/MagicMarquee/src/components/MagicMarquee.vue +3 -3
  6. package/dist/plugins/MagicMarquee/src/composables/{useMarquee.d.ts → useMarqueeApi.d.ts} +2 -2
  7. package/dist/plugins/MagicMarquee/src/composables/{useMarquee.mjs → useMarqueeApi.mjs} +1 -1
  8. package/dist/plugins/MagicModal/src/components/MagicModal.vue +39 -58
  9. package/dist/plugins/MagicModal/src/components/MagicModal.vue.d.ts +15 -15
  10. package/dist/plugins/MagicModal/src/composables/useModalApi.d.ts +4 -3
  11. package/dist/plugins/MagicModal/src/composables/useModalApi.mjs +4 -3
  12. package/dist/plugins/MagicModal/src/composables/useModalCallback.d.ts +22 -0
  13. package/dist/plugins/MagicModal/src/composables/useModalCallback.mjs +60 -0
  14. package/dist/plugins/MagicModal/src/types/index.d.ts +7 -5
  15. package/dist/plugins/MagicModal/src/utils/defaultOptions.d.ts +2 -2
  16. package/dist/plugins/MagicPlayer/src/composables/useControlsApi.mjs +1 -2
  17. package/dist/plugins/MagicPlayer/src/composables/useMediaApi.d.ts +1 -1
  18. package/dist/plugins/MagicPlayer/src/composables/useMediaApi.mjs +2 -2
  19. package/dist/plugins/MagicPlayer/src/composables/useRuntimeSourceProvider.mjs +1 -2
  20. package/dist/plugins/MagicPlayer/src/types/index.d.ts +1 -1
  21. package/dist/plugins/MagicScroll/index.mjs +2 -0
  22. package/dist/plugins/MagicScroll/src/components/MagicScrollMotion.vue +58 -0
  23. package/dist/plugins/MagicScroll/src/components/MagicScrollMotion.vue.d.ts +42 -0
  24. package/dist/plugins/MagicScroll/src/components/MagicScrollTransform.vue.d.ts +9 -9
  25. package/dist/plugins/MagicScroll/src/composables/useProgress.d.ts +1 -1
  26. package/dist/plugins/MagicScroll/src/composables/useProgress.mjs +1 -2
  27. package/dist/plugins/MagicScroll/src/types/injectionKeys.d.ts +1 -2
  28. package/dist/plugins/MagicToast/demo/DemoToast.vue +22 -0
  29. package/dist/plugins/MagicToast/demo/DemoToast.vue.d.ts +14 -0
  30. package/dist/plugins/MagicToast/index.d.ts +5 -0
  31. package/dist/plugins/MagicToast/index.mjs +9 -0
  32. package/dist/plugins/MagicToast/nuxt.d.ts +2 -0
  33. package/dist/plugins/MagicToast/nuxt.mjs +5 -0
  34. package/dist/plugins/MagicToast/src/components/MagicToast.vue +229 -0
  35. package/dist/plugins/MagicToast/src/components/MagicToast.vue.d.ts +28 -0
  36. package/dist/plugins/MagicToast/src/components/MagicToastComponent.vue +101 -0
  37. package/dist/plugins/MagicToast/src/components/MagicToastComponent.vue.d.ts +48 -0
  38. package/dist/plugins/MagicToast/src/composables/useToastApi.d.ts +11 -0
  39. package/dist/plugins/MagicToast/src/composables/useToastApi.mjs +60 -0
  40. package/dist/plugins/MagicToast/src/composables/useToastCallback.d.ts +21 -0
  41. package/dist/plugins/MagicToast/src/composables/useToastCallback.mjs +43 -0
  42. package/dist/plugins/MagicToast/src/composables/useToastEmitter.d.ts +15 -0
  43. package/dist/plugins/MagicToast/src/composables/useToastEmitter.mjs +9 -0
  44. package/dist/plugins/MagicToast/src/composables/useToastInternalApi.d.ts +4 -0
  45. package/dist/plugins/MagicToast/src/composables/useToastInternalApi.mjs +26 -0
  46. package/dist/plugins/MagicToast/src/composables/useToastStore.d.ts +17 -0
  47. package/dist/plugins/MagicToast/src/composables/useToastStore.mjs +41 -0
  48. package/dist/plugins/MagicToast/src/types/index.d.ts +42 -0
  49. package/dist/plugins/MagicToast/src/types/index.mjs +0 -0
  50. package/dist/plugins/MagicToast/src/utils/defaultOptions.d.ts +3 -0
  51. package/dist/plugins/MagicToast/src/utils/defaultOptions.mjs +14 -0
  52. package/dist/plugins/index.d.ts +0 -4
  53. package/dist/plugins/index.mjs +0 -4
  54. package/package.json +13 -1
@@ -0,0 +1,60 @@
1
+ import {
2
+ computed,
3
+ onUnmounted,
4
+ onBeforeMount,
5
+ toValue,
6
+ markRaw
7
+ } from "vue";
8
+ import { v4 as uuidv4 } from "uuid";
9
+ import { useToastStore } from "./useToastStore.mjs";
10
+ export function useToastApi(id) {
11
+ const { findInstance, addInstance, removeInstance } = useToastStore();
12
+ const mappedId = computed(() => toValue(id) || uuidv4());
13
+ const instance = computed(() => findInstance(toValue(mappedId)));
14
+ function initialize() {
15
+ const id2 = toValue(mappedId);
16
+ if (!findInstance(id2)) {
17
+ return addInstance(id2);
18
+ }
19
+ }
20
+ function destroy(id2) {
21
+ if (!id2)
22
+ return;
23
+ clear();
24
+ removeInstance(toValue(id2));
25
+ }
26
+ const toasts = computed(() => instance.value?.toasts);
27
+ const count = computed(() => toasts.value?.length);
28
+ const oldest = computed(() => toasts.value?.[0]);
29
+ async function add(options) {
30
+ const { component, props, duration } = options;
31
+ const id2 = instance.value?.add({
32
+ props,
33
+ duration,
34
+ component: markRaw(component)
35
+ });
36
+ return id2;
37
+ }
38
+ function remove(id2) {
39
+ instance.value?.remove(id2);
40
+ }
41
+ function clear() {
42
+ if (!instance.value)
43
+ return;
44
+ instance.value.toasts = [];
45
+ }
46
+ onBeforeMount(() => {
47
+ initialize();
48
+ });
49
+ onUnmounted(() => {
50
+ destroy(toValue(mappedId));
51
+ });
52
+ return {
53
+ toasts,
54
+ count,
55
+ oldest,
56
+ add,
57
+ remove,
58
+ clear
59
+ };
60
+ }
@@ -0,0 +1,21 @@
1
+ import { type Ref, type MaybeRef } from 'vue';
2
+ import type { Options, Toast } from './../types/index.js';
3
+ type Args = {
4
+ id: MaybeRef<string>;
5
+ mappedOptions: Options;
6
+ count: Ref<number | undefined>;
7
+ oldest: Ref<Toast | undefined>;
8
+ };
9
+ export declare function useToastCallback({ id, mappedOptions, count, oldest }: Args): {
10
+ onBeforeEnter: (_el: Element) => void;
11
+ onEnter: (_el: Element) => void;
12
+ onAfterEnter: (el: Element) => void;
13
+ onBeforeLeave: (_el: Element) => void;
14
+ onLeave: (el: Element) => void;
15
+ onAfterLeave: (_el: Element) => void;
16
+ activeElements: Ref<{
17
+ id: string;
18
+ height: number;
19
+ }[]>;
20
+ };
21
+ export {};
@@ -0,0 +1,43 @@
1
+ import { ref, toValue } from "vue";
2
+ import { useToastEmitter } from "./useToastEmitter.mjs";
3
+ export function useToastCallback({ id, mappedOptions, count, oldest }) {
4
+ const activeElements = ref([]);
5
+ function onBeforeEnter(_el) {
6
+ useToastEmitter().emit("beforeEnter", toValue(id));
7
+ }
8
+ function onEnter(_el) {
9
+ useToastEmitter().emit("enter", toValue(id));
10
+ if (count.value && mappedOptions.layout?.max && count.value > mappedOptions.layout.max) {
11
+ oldest.value?.remove();
12
+ }
13
+ }
14
+ function onAfterEnter(el) {
15
+ useToastEmitter().emit("afterEnter", toValue(id));
16
+ const mappedEl = el;
17
+ activeElements.value = [
18
+ ...activeElements.value,
19
+ { id: el.id, height: mappedEl.offsetHeight }
20
+ ];
21
+ }
22
+ function onBeforeLeave(_el) {
23
+ useToastEmitter().emit("beforeLeave", toValue(id));
24
+ }
25
+ function onLeave(el) {
26
+ useToastEmitter().emit("leave", toValue(id));
27
+ activeElements.value = activeElements.value.filter(
28
+ (item) => item.id !== el.id
29
+ );
30
+ }
31
+ function onAfterLeave(_el) {
32
+ useToastEmitter().emit("afterLeave", toValue(id));
33
+ }
34
+ return {
35
+ onBeforeEnter,
36
+ onEnter,
37
+ onAfterEnter,
38
+ onBeforeLeave,
39
+ onLeave,
40
+ onAfterLeave,
41
+ activeElements
42
+ };
43
+ }
@@ -0,0 +1,15 @@
1
+ import type { ToastEvents } from '../types.js';
2
+ export declare function useToastEmitter(): {
3
+ on: {
4
+ <Key extends keyof ToastEvents>(type: Key, handler: import("mitt").Handler<ToastEvents[Key]>): void;
5
+ (type: "*", handler: import("mitt").WildcardHandler<ToastEvents>): void;
6
+ };
7
+ off: {
8
+ <Key_1 extends keyof ToastEvents>(type: Key_1, handler?: import("mitt").Handler<ToastEvents[Key_1]> | undefined): void;
9
+ (type: "*", handler: import("mitt").WildcardHandler<ToastEvents>): void;
10
+ };
11
+ emit: {
12
+ <Key_2 extends keyof ToastEvents>(type: Key_2, event: ToastEvents[Key_2]): void;
13
+ <Key_3 extends keyof ToastEvents>(type: undefined extends ToastEvents[Key_3] ? Key_3 : never): void;
14
+ };
15
+ };
@@ -0,0 +1,9 @@
1
+ import mitt from "mitt";
2
+ const emitter = mitt();
3
+ export function useToastEmitter() {
4
+ return {
5
+ on: emitter.on,
6
+ off: emitter.off,
7
+ emit: emitter.emit
8
+ };
9
+ }
@@ -0,0 +1,4 @@
1
+ import type { ToastInstance, AddArgs } from './../types.js';
2
+ export declare function useToastInternalApi(): {
3
+ addToast: (args: AddArgs, ctx: ToastInstance) => string;
4
+ };
@@ -0,0 +1,26 @@
1
+ import { v4 as uuidv4 } from "uuid";
2
+ export function useToastInternalApi() {
3
+ function removeToastAfterTimeout(id, duration, ctx) {
4
+ if (duration > 0) {
5
+ setTimeout(() => {
6
+ ctx.remove(id);
7
+ }, duration);
8
+ }
9
+ }
10
+ function addToast(args, ctx) {
11
+ const id = uuidv4();
12
+ let { component, props, duration = 0 } = args;
13
+ const toast = {
14
+ component,
15
+ props,
16
+ id,
17
+ remove: () => ctx.remove(id)
18
+ };
19
+ ctx.toasts.push(toast);
20
+ removeToastAfterTimeout(id, duration, ctx);
21
+ return id;
22
+ }
23
+ return {
24
+ addToast
25
+ };
26
+ }
@@ -0,0 +1,17 @@
1
+ import type { ToastInstance, AddArgs } from '../types/index.js';
2
+ export declare function useToastStore(): {
3
+ toastStore: import("vue").Ref<{
4
+ id: string;
5
+ toasts: {
6
+ id: string;
7
+ component: Object;
8
+ props?: Record<string, any> | undefined;
9
+ remove: Function;
10
+ }[];
11
+ add: (args: AddArgs) => string;
12
+ remove: (id: string) => void;
13
+ }[]>;
14
+ findInstance: (id: string) => ToastInstance | undefined;
15
+ addInstance: (id: string) => ToastInstance;
16
+ removeInstance: (id: string) => void;
17
+ };
@@ -0,0 +1,41 @@
1
+ import { ref } from "vue";
2
+ import { useToastInternalApi } from "./useToastInternalApi.mjs";
3
+ const toastStore = ref([]);
4
+ export function useToastStore() {
5
+ const { addToast } = useToastInternalApi();
6
+ function createInstance(id) {
7
+ const instance = {
8
+ id,
9
+ toasts: [],
10
+ add: function(args) {
11
+ return addToast(args, this);
12
+ },
13
+ remove: function(id2) {
14
+ this.toasts = this.toasts.filter((toast) => toast.id !== id2);
15
+ }
16
+ };
17
+ return instance;
18
+ }
19
+ function findInstance(id) {
20
+ const instance = toastStore.value.find(
21
+ (instance2) => instance2.id === id
22
+ );
23
+ return instance;
24
+ }
25
+ function addInstance(id) {
26
+ const instance = createInstance(id);
27
+ toastStore.value.push(instance);
28
+ return instance;
29
+ }
30
+ function removeInstance(id) {
31
+ toastStore.value = toastStore.value.filter(
32
+ (instance) => instance.id !== id
33
+ );
34
+ }
35
+ return {
36
+ toastStore,
37
+ findInstance,
38
+ addInstance,
39
+ removeInstance
40
+ };
41
+ }
@@ -0,0 +1,42 @@
1
+ import type { MaybeRef } from 'vue';
2
+ type Toast = {
3
+ id: string;
4
+ component: Object;
5
+ props?: MaybeRef<Record<string, any>>;
6
+ remove: Function;
7
+ };
8
+ type ToastInstance = {
9
+ id: string;
10
+ toasts: Toast[];
11
+ add: (args: AddArgs) => string;
12
+ remove: (id: string) => void;
13
+ };
14
+ type Options = {
15
+ teleport?: {
16
+ target?: string;
17
+ disabled?: boolean;
18
+ };
19
+ transitions?: {
20
+ list: string;
21
+ };
22
+ layout?: {
23
+ expand?: boolean | 'hover' | 'click';
24
+ max?: false | number;
25
+ };
26
+ };
27
+ type ActiveElement = {
28
+ id: string;
29
+ height: number;
30
+ };
31
+ type ToastEvents = {
32
+ beforeEnter: string;
33
+ enter: string;
34
+ afterEnter: string;
35
+ beforeLeave: string;
36
+ leave: string;
37
+ afterLeave: string;
38
+ };
39
+ type AddArgs = Pick<Toast, 'component' | 'props'> & {
40
+ duration?: number;
41
+ };
42
+ export type { Toast, ToastInstance, Options, ActiveElement, ToastEvents, AddArgs, };
File without changes
@@ -0,0 +1,3 @@
1
+ import type { Options } from '../types/index.js';
2
+ declare const defaultOptions: Options;
3
+ export { defaultOptions };
@@ -0,0 +1,14 @@
1
+ const defaultOptions = {
2
+ teleport: {
3
+ target: "body",
4
+ disabled: false
5
+ },
6
+ transitions: {
7
+ list: "magic-toast--list"
8
+ },
9
+ layout: {
10
+ expand: "click",
11
+ max: 4
12
+ }
13
+ };
14
+ export { defaultOptions };
@@ -1,4 +0,0 @@
1
- export * from './MagicModal.js';
2
- export * from './MagicPlayer.js';
3
- export * from './MagicScroll.js';
4
- export * from './MagicMarquee.js';
@@ -1,4 +0,0 @@
1
- export * from "./MagicModal/index.mjs";
2
- export * from "./MagicPlayer/index.mjs";
3
- export * from "./MagicScroll/index.mjs";
4
- export * from "./MagicMarquee/index.mjs";
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.5.0",
4
+ "version": "0.6.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.5",
@@ -54,15 +54,21 @@
54
54
  "license": "MIT",
55
55
  "main": "./dist/nuxt/module.cjs",
56
56
  "peerDependencies": {
57
+ "@maas/magic-timer": "^0.1.3",
57
58
  "@vueuse/core": "^10.3.0",
58
59
  "@vueuse/integrations": "^10.3.0",
59
60
  "focus-trap": "^7.5.2",
60
61
  "hls.js": "^1.4.10",
62
+ "luxon": "^3.4.2",
61
63
  "mitt": "^3.0.1",
64
+ "motion": "^10.16.2",
62
65
  "nuxt": "^3.5.1",
63
66
  "uuid": "^9.0.0"
64
67
  },
65
68
  "peerDependenciesMeta": {
69
+ "@maas/magic-timer": {
70
+ "optional": false
71
+ },
66
72
  "@vueuse/core": {
67
73
  "optional": false
68
74
  },
@@ -72,9 +78,15 @@
72
78
  "hls.js": {
73
79
  "optional": false
74
80
  },
81
+ "luxon": {
82
+ "optional": false
83
+ },
75
84
  "mitt": {
76
85
  "optional": false
77
86
  },
87
+ "motion": {
88
+ "optional": false
89
+ },
78
90
  "nuxt": {
79
91
  "optional": false
80
92
  },