@witchcraft/ui 0.3.12 → 0.3.13
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/module.json +1 -1
- package/dist/runtime/components/LibColorInput/LibColorInput.d.vue.ts +2 -2
- package/dist/runtime/components/LibColorInput/LibColorInput.vue.d.ts +2 -2
- package/dist/runtime/components/LibColorPicker/LibColorPicker.d.vue.ts +3 -3
- package/dist/runtime/components/LibColorPicker/LibColorPicker.vue.d.ts +3 -3
- package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.d.vue.ts +3 -3
- package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.vue.d.ts +3 -3
- package/dist/runtime/components/LibNotifications/LibNotification.vue +16 -1
- package/dist/runtime/components/LibNotifications/LibNotificationTestMessageComponent.d.vue.ts +6 -0
- package/dist/runtime/components/LibNotifications/LibNotificationTestMessageComponent.vue +29 -0
- package/dist/runtime/components/LibNotifications/LibNotificationTestMessageComponent.vue.d.ts +6 -0
- package/dist/runtime/components/LibPopup/LibPopup.d.vue.ts +1 -1
- package/dist/runtime/components/LibPopup/LibPopup.vue.d.ts +1 -1
- package/dist/runtime/helpers/NotificationHandler.d.ts +5 -2
- package/dist/runtime/helpers/NotificationHandler.js +2 -1
- package/dist/runtime/types/index.d.ts +4 -0
- package/dist/runtime/utils/notifyIfError.d.ts +3 -1
- package/dist/runtime/utils/notifyIfError.js +4 -2
- package/package.json +1 -1
- package/src/runtime/components/LibNotifications/LibNotification.stories.ts +22 -1
- package/src/runtime/components/LibNotifications/LibNotification.vue +16 -1
- package/src/runtime/components/LibNotifications/LibNotificationTestMessageComponent.vue +27 -0
- package/src/runtime/helpers/NotificationHandler.ts +6 -2
- package/src/runtime/types/index.ts +5 -0
- package/src/runtime/utils/notifyIfError.ts +6 -2
package/dist/module.json
CHANGED
|
@@ -34,16 +34,16 @@ declare const _default: __VLS_WithSlots<import("vue").DefineComponent<Props & {
|
|
|
34
34
|
}> & Readonly<{
|
|
35
35
|
"onUpdate:modelValue"?: ((value: RgbaColor) => any) | undefined;
|
|
36
36
|
onCancel?: (() => any) | undefined;
|
|
37
|
-
onSave?: (() => any) | undefined;
|
|
38
37
|
"onUpdate:tempValue"?: ((value: RgbaColor | undefined) => any) | undefined;
|
|
38
|
+
onSave?: (() => any) | undefined;
|
|
39
39
|
}>, {
|
|
40
40
|
border: boolean;
|
|
41
41
|
allowAlpha: boolean;
|
|
42
|
+
copyTransform: (val: HsvaColor, stringVal: string) => any;
|
|
42
43
|
stringPrecision: number;
|
|
43
44
|
customRepresentation: {
|
|
44
45
|
fromHsvaToString: (hsva: HsvaColor, includeAlpha: boolean) => string;
|
|
45
46
|
};
|
|
46
|
-
copyTransform: (val: HsvaColor, stringVal: string) => any;
|
|
47
47
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
|
|
48
48
|
default?: (props: {
|
|
49
49
|
stringColor: any;
|
|
@@ -34,16 +34,16 @@ declare const _default: __VLS_WithSlots<import("vue").DefineComponent<Props & {
|
|
|
34
34
|
}> & Readonly<{
|
|
35
35
|
"onUpdate:modelValue"?: ((value: RgbaColor) => any) | undefined;
|
|
36
36
|
onCancel?: (() => any) | undefined;
|
|
37
|
-
onSave?: (() => any) | undefined;
|
|
38
37
|
"onUpdate:tempValue"?: ((value: RgbaColor | undefined) => any) | undefined;
|
|
38
|
+
onSave?: (() => any) | undefined;
|
|
39
39
|
}>, {
|
|
40
40
|
border: boolean;
|
|
41
41
|
allowAlpha: boolean;
|
|
42
|
+
copyTransform: (val: HsvaColor, stringVal: string) => any;
|
|
42
43
|
stringPrecision: number;
|
|
43
44
|
customRepresentation: {
|
|
44
45
|
fromHsvaToString: (hsva: HsvaColor, includeAlpha: boolean) => string;
|
|
45
46
|
};
|
|
46
|
-
copyTransform: (val: HsvaColor, stringVal: string) => any;
|
|
47
47
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
|
|
48
48
|
default?: (props: {
|
|
49
49
|
stringColor: any;
|
|
@@ -39,18 +39,18 @@ declare const __VLS_component: import("vue").DefineComponent<__VLS_PublicProps,
|
|
|
39
39
|
}, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
|
|
40
40
|
"onUpdate:modelValue"?: ((value: RgbaColor) => any) | undefined;
|
|
41
41
|
onCancel?: (() => any) | undefined;
|
|
42
|
-
onSave?: ((val: RgbaColor) => any) | undefined;
|
|
43
42
|
"onUpdate:tempValue"?: ((value: RgbaColor | undefined) => any) | undefined;
|
|
43
|
+
onSave?: ((val: RgbaColor) => any) | undefined;
|
|
44
44
|
}>, {
|
|
45
45
|
border: boolean;
|
|
46
|
-
valid: boolean;
|
|
47
46
|
allowAlpha: boolean;
|
|
47
|
+
copyTransform: (val: HsvaColor, stringVal: string) => any;
|
|
48
48
|
stringPrecision: number;
|
|
49
49
|
customRepresentation: {
|
|
50
50
|
fromHsvaToString: (hsva: HsvaColor, includeAlpha: boolean) => string;
|
|
51
51
|
fromStringToHsva?: (string: string) => HsvaColor | undefined;
|
|
52
52
|
};
|
|
53
|
-
|
|
53
|
+
valid: boolean;
|
|
54
54
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
55
55
|
declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
|
|
56
56
|
export default _default;
|
|
@@ -39,18 +39,18 @@ declare const __VLS_component: import("vue").DefineComponent<__VLS_PublicProps,
|
|
|
39
39
|
}, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
|
|
40
40
|
"onUpdate:modelValue"?: ((value: RgbaColor) => any) | undefined;
|
|
41
41
|
onCancel?: (() => any) | undefined;
|
|
42
|
-
onSave?: ((val: RgbaColor) => any) | undefined;
|
|
43
42
|
"onUpdate:tempValue"?: ((value: RgbaColor | undefined) => any) | undefined;
|
|
43
|
+
onSave?: ((val: RgbaColor) => any) | undefined;
|
|
44
44
|
}>, {
|
|
45
45
|
border: boolean;
|
|
46
|
-
valid: boolean;
|
|
47
46
|
allowAlpha: boolean;
|
|
47
|
+
copyTransform: (val: HsvaColor, stringVal: string) => any;
|
|
48
48
|
stringPrecision: number;
|
|
49
49
|
customRepresentation: {
|
|
50
50
|
fromHsvaToString: (hsva: HsvaColor, includeAlpha: boolean) => string;
|
|
51
51
|
fromStringToHsva?: (string: string) => HsvaColor | undefined;
|
|
52
52
|
};
|
|
53
|
-
|
|
53
|
+
valid: boolean;
|
|
54
54
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
55
55
|
declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
|
|
56
56
|
export default _default;
|
|
@@ -110,8 +110,8 @@ declare const _default: __VLS_WithSlots<import("vue").DefineComponent<Props & {
|
|
|
110
110
|
blur: (val: FocusEvent) => any;
|
|
111
111
|
input: (val: InputEvent) => any;
|
|
112
112
|
submit: (val: string, suggestion?: any) => any;
|
|
113
|
-
keydown: (val: KeyboardEvent) => any;
|
|
114
113
|
focus: (val: FocusEvent) => any;
|
|
114
|
+
keydown: (val: KeyboardEvent) => any;
|
|
115
115
|
indicatorClick: (val: MouseEvent) => any;
|
|
116
116
|
}, string, import("vue").PublicProps, Readonly<Props & {
|
|
117
117
|
values?: string[] | undefined;
|
|
@@ -122,10 +122,10 @@ declare const _default: __VLS_WithSlots<import("vue").DefineComponent<Props & {
|
|
|
122
122
|
onInput?: ((val: InputEvent) => any) | undefined;
|
|
123
123
|
onSubmit?: ((val: string, suggestion?: any) => any) | undefined;
|
|
124
124
|
"onUpdate:modelValue"?: ((value: string) => any) | undefined;
|
|
125
|
+
onFocus?: ((val: FocusEvent) => any) | undefined;
|
|
126
|
+
onKeydown?: ((val: KeyboardEvent) => any) | undefined;
|
|
125
127
|
"onUpdate:inputValue"?: ((value: string) => any) | undefined;
|
|
126
128
|
"onUpdate:values"?: ((value: string[] | undefined) => any) | undefined;
|
|
127
|
-
onKeydown?: ((val: KeyboardEvent) => any) | undefined;
|
|
128
|
-
onFocus?: ((val: FocusEvent) => any) | undefined;
|
|
129
129
|
onIndicatorClick?: ((val: MouseEvent) => any) | undefined;
|
|
130
130
|
}>, {
|
|
131
131
|
disabled: boolean;
|
|
@@ -110,8 +110,8 @@ declare const _default: __VLS_WithSlots<import("vue").DefineComponent<Props & {
|
|
|
110
110
|
blur: (val: FocusEvent) => any;
|
|
111
111
|
input: (val: InputEvent) => any;
|
|
112
112
|
submit: (val: string, suggestion?: any) => any;
|
|
113
|
-
keydown: (val: KeyboardEvent) => any;
|
|
114
113
|
focus: (val: FocusEvent) => any;
|
|
114
|
+
keydown: (val: KeyboardEvent) => any;
|
|
115
115
|
indicatorClick: (val: MouseEvent) => any;
|
|
116
116
|
}, string, import("vue").PublicProps, Readonly<Props & {
|
|
117
117
|
values?: string[] | undefined;
|
|
@@ -122,10 +122,10 @@ declare const _default: __VLS_WithSlots<import("vue").DefineComponent<Props & {
|
|
|
122
122
|
onInput?: ((val: InputEvent) => any) | undefined;
|
|
123
123
|
onSubmit?: ((val: string, suggestion?: any) => any) | undefined;
|
|
124
124
|
"onUpdate:modelValue"?: ((value: string) => any) | undefined;
|
|
125
|
+
onFocus?: ((val: FocusEvent) => any) | undefined;
|
|
126
|
+
onKeydown?: ((val: KeyboardEvent) => any) | undefined;
|
|
125
127
|
"onUpdate:inputValue"?: ((value: string) => any) | undefined;
|
|
126
128
|
"onUpdate:values"?: ((value: string[] | undefined) => any) | undefined;
|
|
127
|
-
onKeydown?: ((val: KeyboardEvent) => any) | undefined;
|
|
128
|
-
onFocus?: ((val: FocusEvent) => any) | undefined;
|
|
129
129
|
onIndicatorClick?: ((val: MouseEvent) => any) | undefined;
|
|
130
130
|
}>, {
|
|
131
131
|
disabled: boolean;
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
</div>
|
|
93
93
|
</div>
|
|
94
94
|
<slot
|
|
95
|
-
v-if="notification.message"
|
|
95
|
+
v-if="notification.message && !notification.component"
|
|
96
96
|
name="message"
|
|
97
97
|
v-bind="setSlotVar('message', {
|
|
98
98
|
class: `
|
|
@@ -112,6 +112,21 @@
|
|
|
112
112
|
{{ notification.message }}
|
|
113
113
|
</div>
|
|
114
114
|
</slot>
|
|
115
|
+
<Component
|
|
116
|
+
v-if="notification.component"
|
|
117
|
+
:is="notification.component"
|
|
118
|
+
v-bind="{
|
|
119
|
+
message: notification.message,
|
|
120
|
+
messageClasses: `
|
|
121
|
+
notification--message
|
|
122
|
+
whitespace-pre-wrap
|
|
123
|
+
text-neutral-800
|
|
124
|
+
dark:text-neutral-200
|
|
125
|
+
mb-1
|
|
126
|
+
`,
|
|
127
|
+
...notification.componentProps ?? {}
|
|
128
|
+
}"
|
|
129
|
+
/>
|
|
115
130
|
<div class="notification--footer flex items-end justify-between">
|
|
116
131
|
<div
|
|
117
132
|
v-if="notification.code"
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CustomNotificationComponentProps } from "../../types/index.js";
|
|
2
|
+
type __VLS_Props = CustomNotificationComponentProps & {
|
|
3
|
+
customProp: string;
|
|
4
|
+
};
|
|
5
|
+
declare const _default: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
6
|
+
export default _default;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="border-2 border-accent-500 p-1 px-2 rounded-sm bg-accent-500/10">
|
|
3
|
+
<div class="text-lg">
|
|
4
|
+
Custom Message Component
|
|
5
|
+
</div>
|
|
6
|
+
<div class="font-bold">
|
|
7
|
+
Original message:
|
|
8
|
+
</div>
|
|
9
|
+
<div
|
|
10
|
+
:class="props.messageClasses"
|
|
11
|
+
>
|
|
12
|
+
{{ props.message }}
|
|
13
|
+
</div>
|
|
14
|
+
<div class="font-bold">
|
|
15
|
+
Custom Prop:
|
|
16
|
+
</div>
|
|
17
|
+
<div>
|
|
18
|
+
{{ props.customProp }}
|
|
19
|
+
</div>
|
|
20
|
+
</div>
|
|
21
|
+
</template>
|
|
22
|
+
|
|
23
|
+
<script setup>
|
|
24
|
+
const props = defineProps({
|
|
25
|
+
message: { type: String, required: true },
|
|
26
|
+
messageClasses: { type: String, required: false },
|
|
27
|
+
customProp: { type: String, required: true }
|
|
28
|
+
});
|
|
29
|
+
</script>
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CustomNotificationComponentProps } from "../../types/index.js";
|
|
2
|
+
type __VLS_Props = CustomNotificationComponentProps & {
|
|
3
|
+
customProp: string;
|
|
4
|
+
};
|
|
5
|
+
declare const _default: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
6
|
+
export default _default;
|
|
@@ -22,12 +22,12 @@ declare const _default: __VLS_WithSlots<import("vue").DefineComponent<Props & {
|
|
|
22
22
|
"onUpdate:modelValue"?: ((value: boolean) => any) | undefined;
|
|
23
23
|
onClose?: (() => any) | undefined;
|
|
24
24
|
}>, {
|
|
25
|
-
canClose: boolean;
|
|
26
25
|
useDialogForBackdrop: false;
|
|
27
26
|
useBackdrop: boolean;
|
|
28
27
|
preferredHorizontal: ("center" | "right" | "left" | "either" | "center-screen" | "right-most" | "left-most" | "center-most")[] | import("../../main.lib.js").PopupPositioner;
|
|
29
28
|
preferredVertical: ("top" | "bottom" | "center" | "either" | "center-screen" | "top-most" | "bottom-most" | "center-most")[] | import("../../main.lib.js").PopupPositioner;
|
|
30
29
|
avoidRepositioning: boolean;
|
|
30
|
+
canClose: boolean;
|
|
31
31
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
|
|
32
32
|
button?: (props: {
|
|
33
33
|
extractEl: (_: any) => any;
|
|
@@ -22,12 +22,12 @@ declare const _default: __VLS_WithSlots<import("vue").DefineComponent<Props & {
|
|
|
22
22
|
"onUpdate:modelValue"?: ((value: boolean) => any) | undefined;
|
|
23
23
|
onClose?: (() => any) | undefined;
|
|
24
24
|
}>, {
|
|
25
|
-
canClose: boolean;
|
|
26
25
|
useDialogForBackdrop: false;
|
|
27
26
|
useBackdrop: boolean;
|
|
28
27
|
preferredHorizontal: ("center" | "right" | "left" | "either" | "center-screen" | "right-most" | "left-most" | "center-most")[] | import("../../main.lib.js").PopupPositioner;
|
|
29
28
|
preferredVertical: ("top" | "bottom" | "center" | "either" | "center-screen" | "top-most" | "bottom-most" | "center-most")[] | import("../../main.lib.js").PopupPositioner;
|
|
30
29
|
avoidRepositioning: boolean;
|
|
30
|
+
canClose: boolean;
|
|
31
31
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
|
|
32
32
|
button?: (props: {
|
|
33
33
|
extractEl: (_: any) => any;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AnyFunction, MakeRequired } from "@alanscodelog/utils";
|
|
2
|
-
import { type Reactive } from "vue";
|
|
2
|
+
import { type Component, type Reactive } from "vue";
|
|
3
3
|
export declare class NotificationHandler<TRawEntry extends RawNotificationEntry<any, any> = RawNotificationEntry<any, any>, TEntry extends NotificationEntry<TRawEntry> = NotificationEntry<TRawEntry>> {
|
|
4
4
|
timeout: number;
|
|
5
5
|
debug: boolean;
|
|
@@ -26,7 +26,6 @@ export declare class NotificationHandler<TRawEntry extends RawNotificationEntry<
|
|
|
26
26
|
}
|
|
27
27
|
export type NotificationPromise<TOption extends string = string> = Promise<TOption>;
|
|
28
28
|
export type RawNotificationEntry<TOptions extends string[] = ["Ok", "Cancel"], TCancellable extends boolean | TOptions[number] = "Cancel"> = {
|
|
29
|
-
message: string;
|
|
30
29
|
title?: string;
|
|
31
30
|
code?: string;
|
|
32
31
|
/** @default ["Ok", "Cancel"] */
|
|
@@ -41,6 +40,10 @@ export type RawNotificationEntry<TOptions extends string[] = ["Ok", "Cancel"], T
|
|
|
41
40
|
/** @default false if cancellable, otherwise the default timeout */
|
|
42
41
|
timeout?: number | boolean;
|
|
43
42
|
icon?: string;
|
|
43
|
+
message: string;
|
|
44
|
+
component?: string | Component;
|
|
45
|
+
/** By default the component is passed the message and the messageClasses. Both will be overriden if you set them on componentProps. */
|
|
46
|
+
componentProps?: Record<string, any>;
|
|
44
47
|
};
|
|
45
48
|
export type NotificationEntry<TRawEntry extends RawNotificationEntry<any, any> = RawNotificationEntry<any, any>> = Omit<MakeRequired<TRawEntry, "options" | "requiresAction" | "default" | "dangerous">, "cancellable"> & {
|
|
46
49
|
promise: NotificationPromise;
|
|
@@ -4,7 +4,7 @@ import { indent } from "@alanscodelog/utils/indent";
|
|
|
4
4
|
import { isBlank } from "@alanscodelog/utils/isBlank";
|
|
5
5
|
import { pretty } from "@alanscodelog/utils/pretty";
|
|
6
6
|
import { setReadOnly } from "@alanscodelog/utils/setReadOnly";
|
|
7
|
-
import { reactive } from "vue";
|
|
7
|
+
import { markRaw, reactive } from "vue";
|
|
8
8
|
export class NotificationHandler {
|
|
9
9
|
timeout = 5e3;
|
|
10
10
|
debug = false;
|
|
@@ -87,6 +87,7 @@ export class NotificationHandler {
|
|
|
87
87
|
default: "Ok",
|
|
88
88
|
cancellable: rawEntry.cancellable,
|
|
89
89
|
...rawEntry,
|
|
90
|
+
component: rawEntry.component && typeof rawEntry.component !== "string" ? markRaw(rawEntry.component) : void 0,
|
|
90
91
|
dangerous: rawEntry.dangerous ?? [],
|
|
91
92
|
timeout: rawEntry.timeout === true ? this.timeout : rawEntry.timeout !== void 0 && rawEntry.timeout !== false ? rawEntry.timeout : void 0
|
|
92
93
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { NotificationEntry } from "../helpers/NotificationHandler.js";
|
|
1
2
|
/**
|
|
2
3
|
* Notifies the user if the given value is an error. Useful for making non-critical errors don't go unnoticed.
|
|
3
4
|
*
|
|
@@ -5,10 +6,11 @@
|
|
|
5
6
|
*
|
|
6
7
|
* If the value is not an error, it is returned.
|
|
7
8
|
*/
|
|
8
|
-
export declare function notifyIfError<T>(err: T, { logger, ns, force }?: {
|
|
9
|
+
export declare function notifyIfError<T>(err: T, { logger, ns, force, entry }?: {
|
|
9
10
|
logger?: {
|
|
10
11
|
debug: (...args: any[]) => void;
|
|
11
12
|
};
|
|
12
13
|
ns?: string;
|
|
13
14
|
force?: boolean;
|
|
15
|
+
entry?: Partial<NotificationEntry<any>>;
|
|
14
16
|
}): T;
|
|
@@ -3,7 +3,8 @@ import { useNotificationHandler } from "../composables/useNotificationHandler.js
|
|
|
3
3
|
export function notifyIfError(err, {
|
|
4
4
|
logger,
|
|
5
5
|
ns,
|
|
6
|
-
force = false
|
|
6
|
+
force = false,
|
|
7
|
+
entry
|
|
7
8
|
} = {}) {
|
|
8
9
|
if (force || err instanceof Error) {
|
|
9
10
|
const errMessage = {
|
|
@@ -22,7 +23,8 @@ export function notifyIfError(err, {
|
|
|
22
23
|
...errMessage,
|
|
23
24
|
options: ["Ok"],
|
|
24
25
|
cancellable: "Ok",
|
|
25
|
-
timeout: true
|
|
26
|
+
timeout: true,
|
|
27
|
+
...entry
|
|
26
28
|
});
|
|
27
29
|
}
|
|
28
30
|
return err;
|
package/package.json
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import type { Meta, StoryObj } from "@storybook/vue3"
|
|
3
3
|
|
|
4
4
|
import LibNotification from "./LibNotification.vue"
|
|
5
|
+
import LibNotificationTestMessageComponent from "./LibNotificationTestMessageComponent.vue"
|
|
5
6
|
|
|
6
7
|
import { NotificationHandler } from "../../helpers/NotificationHandler.js"
|
|
7
8
|
import * as components from "../index.js"
|
|
@@ -21,7 +22,11 @@ type Story = StoryObj<typeof LibNotification>
|
|
|
21
22
|
|
|
22
23
|
export const Primary: Story = {
|
|
23
24
|
render: args => ({
|
|
24
|
-
components: {
|
|
25
|
+
components: {
|
|
26
|
+
...components,
|
|
27
|
+
LibNotification,
|
|
28
|
+
LibNotificationTestMessageComponent
|
|
29
|
+
},
|
|
25
30
|
setup() {
|
|
26
31
|
return { args }
|
|
27
32
|
},
|
|
@@ -136,3 +141,19 @@ export const CustomDefaultAndDangerousOption: Story = {
|
|
|
136
141
|
})
|
|
137
142
|
}
|
|
138
143
|
}
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
export const CustomMessageComponent: Story = {
|
|
147
|
+
...Primary,
|
|
148
|
+
args: {
|
|
149
|
+
...Primary.args,
|
|
150
|
+
// @ts-expect-error calling protected method
|
|
151
|
+
notification: handler._createEntry({
|
|
152
|
+
...Primary.args!.notification,
|
|
153
|
+
component: LibNotificationTestMessageComponent,
|
|
154
|
+
componentProps: {
|
|
155
|
+
customProp: "Custom Prop"
|
|
156
|
+
}
|
|
157
|
+
})
|
|
158
|
+
}
|
|
159
|
+
}
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
</div>
|
|
91
91
|
</div>
|
|
92
92
|
<slot
|
|
93
|
-
v-if="notification.message"
|
|
93
|
+
v-if="notification.message && !notification.component"
|
|
94
94
|
name="message"
|
|
95
95
|
v-bind="setSlotVar('message', {
|
|
96
96
|
class: `
|
|
@@ -110,6 +110,21 @@
|
|
|
110
110
|
{{ notification.message }}
|
|
111
111
|
</div>
|
|
112
112
|
</slot>
|
|
113
|
+
<Component
|
|
114
|
+
v-if="notification.component"
|
|
115
|
+
:is="notification.component"
|
|
116
|
+
v-bind="{
|
|
117
|
+
message: notification.message,
|
|
118
|
+
messageClasses: `
|
|
119
|
+
notification--message
|
|
120
|
+
whitespace-pre-wrap
|
|
121
|
+
text-neutral-800
|
|
122
|
+
dark:text-neutral-200
|
|
123
|
+
mb-1
|
|
124
|
+
`,
|
|
125
|
+
...(notification.componentProps ?? {})
|
|
126
|
+
}"
|
|
127
|
+
/>
|
|
113
128
|
<div class="notification--footer flex items-end justify-between">
|
|
114
129
|
<div
|
|
115
130
|
v-if="notification.code"
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="border-2 border-accent-500 p-1 px-2 rounded-sm bg-accent-500/10">
|
|
3
|
+
<div class="text-lg">
|
|
4
|
+
Custom Message Component
|
|
5
|
+
</div>
|
|
6
|
+
<div class="font-bold">
|
|
7
|
+
Original message:
|
|
8
|
+
</div>
|
|
9
|
+
<div
|
|
10
|
+
:class="props.messageClasses"
|
|
11
|
+
>
|
|
12
|
+
{{ props.message }}
|
|
13
|
+
</div>
|
|
14
|
+
<div class="font-bold">
|
|
15
|
+
Custom Prop:
|
|
16
|
+
</div>
|
|
17
|
+
<div>
|
|
18
|
+
{{ props.customProp }}
|
|
19
|
+
</div>
|
|
20
|
+
</div>
|
|
21
|
+
</template>
|
|
22
|
+
|
|
23
|
+
<script setup lang="ts">
|
|
24
|
+
import type { CustomNotificationComponentProps } from "../../types/index.js"
|
|
25
|
+
|
|
26
|
+
const props = defineProps<CustomNotificationComponentProps & { customProp: string }>()
|
|
27
|
+
</script>
|
|
@@ -5,7 +5,7 @@ import { indent } from "@alanscodelog/utils/indent"
|
|
|
5
5
|
import { isBlank } from "@alanscodelog/utils/isBlank"
|
|
6
6
|
import { pretty } from "@alanscodelog/utils/pretty"
|
|
7
7
|
import { setReadOnly } from "@alanscodelog/utils/setReadOnly"
|
|
8
|
-
import { type Reactive, reactive } from "vue"
|
|
8
|
+
import { type Component, markRaw, type Reactive, reactive } from "vue"
|
|
9
9
|
|
|
10
10
|
export class NotificationHandler<
|
|
11
11
|
TRawEntry extends RawNotificationEntry<any, any> = RawNotificationEntry<any, any>,
|
|
@@ -99,6 +99,7 @@ export class NotificationHandler<
|
|
|
99
99
|
default: "Ok",
|
|
100
100
|
cancellable: rawEntry.cancellable,
|
|
101
101
|
...rawEntry,
|
|
102
|
+
component: rawEntry.component && typeof rawEntry.component !== "string" ? markRaw(rawEntry.component) : undefined,
|
|
102
103
|
dangerous: rawEntry.dangerous ?? [],
|
|
103
104
|
timeout: rawEntry.timeout === true
|
|
104
105
|
? this.timeout
|
|
@@ -211,7 +212,6 @@ export type RawNotificationEntry<
|
|
|
211
212
|
TOptions extends string[] = ["Ok", "Cancel"],
|
|
212
213
|
TCancellable extends boolean | TOptions[number] = "Cancel"
|
|
213
214
|
> = {
|
|
214
|
-
message: string
|
|
215
215
|
title?: string
|
|
216
216
|
code?: string
|
|
217
217
|
/** @default ["Ok", "Cancel"] */
|
|
@@ -226,6 +226,10 @@ export type RawNotificationEntry<
|
|
|
226
226
|
/** @default false if cancellable, otherwise the default timeout */
|
|
227
227
|
timeout?: number | boolean
|
|
228
228
|
icon?: string
|
|
229
|
+
message: string
|
|
230
|
+
component?: string | Component
|
|
231
|
+
/** By default the component is passed the message and the messageClasses. Both will be overriden if you set them on componentProps. */
|
|
232
|
+
componentProps?: Record<string, any>
|
|
229
233
|
}
|
|
230
234
|
|
|
231
235
|
export type NotificationEntry<
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TypedError } from "@alanscodelog/utils/TypedError"
|
|
2
2
|
|
|
3
3
|
import { useNotificationHandler } from "../composables/useNotificationHandler.js"
|
|
4
|
+
import type { NotificationEntry } from "../helpers/NotificationHandler.js"
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Notifies the user if the given value is an error. Useful for making non-critical errors don't go unnoticed.
|
|
@@ -13,13 +14,15 @@ export function notifyIfError<T>(
|
|
|
13
14
|
err: T, {
|
|
14
15
|
logger,
|
|
15
16
|
ns,
|
|
16
|
-
force = false
|
|
17
|
+
force = false,
|
|
18
|
+
entry
|
|
17
19
|
}: {
|
|
18
20
|
logger?: { debug: (...args: any[]) => void }
|
|
19
21
|
/* Logger namespace. */
|
|
20
22
|
ns?: string
|
|
21
23
|
/* force interpret as error, for catch blocks */
|
|
22
24
|
force?: boolean
|
|
25
|
+
entry?: Partial<NotificationEntry<any>>
|
|
23
26
|
} = {}): T {
|
|
24
27
|
if (force || err instanceof Error) {
|
|
25
28
|
const errMessage = {
|
|
@@ -38,7 +41,8 @@ export function notifyIfError<T>(
|
|
|
38
41
|
...errMessage,
|
|
39
42
|
options: ["Ok"],
|
|
40
43
|
cancellable: "Ok",
|
|
41
|
-
timeout: true
|
|
44
|
+
timeout: true,
|
|
45
|
+
...entry
|
|
42
46
|
})
|
|
43
47
|
}
|
|
44
48
|
return err
|