@leaflink/stash 50.14.0 → 50.15.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.
- package/dist/useToasts.d.ts +33 -9
- package/dist/useToasts.js +33 -28
- package/dist/useToasts.js.map +1 -1
- package/package.json +1 -1
package/dist/useToasts.d.ts
CHANGED
|
@@ -17,23 +17,47 @@ export declare type Toast = {
|
|
|
17
17
|
status: StatusSeverity;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
declare type ToastIdOrUndefined<O extends ToastOptions | undefined> = O extends {
|
|
21
|
+
id: string;
|
|
22
|
+
} ? Toast['id'] | undefined : Toast['id'];
|
|
23
|
+
|
|
24
|
+
export declare interface ToastOptions {
|
|
25
|
+
/**
|
|
26
|
+
* The timeout in milliseconds before the toast is automatically dismissed. If set to `false`, the toast will persist until the user clicks on it.
|
|
27
|
+
* @default DEFAULT_TIMEOUT
|
|
28
|
+
*/
|
|
21
29
|
timeout?: number | boolean;
|
|
22
|
-
|
|
30
|
+
/**
|
|
31
|
+
* A group name ensures only one toast with the same group and status is visible at any given time.
|
|
32
|
+
* Toasts with the same group but different statuses will be treated as separate and will display concurrently.
|
|
33
|
+
*/
|
|
34
|
+
group?: string;
|
|
35
|
+
}
|
|
23
36
|
|
|
24
|
-
declare function useToasts(globalOptions?: ToastOptions): {
|
|
37
|
+
declare function useToasts(globalOptions?: Omit<ToastOptions, 'group'>): {
|
|
25
38
|
active: readonly {
|
|
26
39
|
readonly id: string;
|
|
27
40
|
readonly text: string | RenderFunction;
|
|
28
41
|
readonly status: "error" | "warning" | "info" | "success";
|
|
29
42
|
}[];
|
|
30
|
-
remove:
|
|
31
|
-
|
|
43
|
+
remove: {
|
|
44
|
+
(toastId: Toast['id']): void;
|
|
45
|
+
(options: {
|
|
46
|
+
group: string;
|
|
47
|
+
status: StatusSeverity;
|
|
48
|
+
}): void;
|
|
49
|
+
};
|
|
50
|
+
create: {
|
|
51
|
+
(text: Toast['text'], status: StatusSeverity, options?: Omit<ToastOptions, 'group'>): Toast['id'];
|
|
52
|
+
(text: Toast['text'], status: StatusSeverity, options: ToastOptions & {
|
|
53
|
+
id: string;
|
|
54
|
+
}): Toast['id'] | undefined;
|
|
55
|
+
};
|
|
32
56
|
removeAll: () => void;
|
|
33
|
-
error: (text: Toast['text'], options?:
|
|
34
|
-
info: (text: Toast['text'], options?:
|
|
35
|
-
success: (text: Toast['text'], options?:
|
|
36
|
-
warning: (text: Toast['text'], options?:
|
|
57
|
+
error: <O extends ToastOptions>(text: Toast['text'], options?: O) => ToastIdOrUndefined<O>;
|
|
58
|
+
info: <O_1 extends ToastOptions>(text: Toast['text'], options?: O_1 | undefined) => ToastIdOrUndefined<O_1>;
|
|
59
|
+
success: <O_2 extends ToastOptions>(text: Toast['text'], options?: O_2 | undefined) => ToastIdOrUndefined<O_2>;
|
|
60
|
+
warning: <O_3 extends ToastOptions>(text: Toast['text'], options?: O_3 | undefined) => ToastIdOrUndefined<O_3>;
|
|
37
61
|
};
|
|
38
62
|
export default useToasts;
|
|
39
63
|
|
package/dist/useToasts.js
CHANGED
|
@@ -1,43 +1,48 @@
|
|
|
1
1
|
import p from "lodash-es/merge";
|
|
2
2
|
import T from "lodash-es/uniqueId";
|
|
3
|
-
import { ref as
|
|
4
|
-
const
|
|
5
|
-
function
|
|
6
|
-
function
|
|
7
|
-
|
|
3
|
+
import { ref as h, reactive as y, readonly as b } from "vue";
|
|
4
|
+
const w = 5e3, n = h([]);
|
|
5
|
+
function M(a = { timeout: w }) {
|
|
6
|
+
function f(e) {
|
|
7
|
+
const t = typeof e == "string" ? e : void 0, { group: i = void 0, status: r = void 0 } = typeof e == "object" ? e : {};
|
|
8
|
+
if (!t && (!i || !r))
|
|
9
|
+
throw new Error("Must provide either a toast ID or both group and type");
|
|
10
|
+
const o = i && r ? `toast-${r}-${i}` : String(t), c = n.value.findIndex(({ id: l }) => l === o);
|
|
11
|
+
c !== -1 && n.value.splice(c, 1);
|
|
8
12
|
}
|
|
9
|
-
function
|
|
10
|
-
const
|
|
11
|
-
|
|
13
|
+
function u(e, t, i) {
|
|
14
|
+
const r = p({}, a, i), o = r != null && r.group ? `toast-${t}-${r.group}` : T("toast-");
|
|
15
|
+
if (!(r != null && r.group && n.value.some(({ id: c }) => c === o)))
|
|
16
|
+
return n.value.push({ text: e, id: o, status: t }), typeof r.timeout == "number" && setTimeout(() => f(o), Math.abs(r.timeout)), o;
|
|
12
17
|
}
|
|
13
18
|
function s() {
|
|
14
|
-
|
|
19
|
+
n.value = [];
|
|
15
20
|
}
|
|
16
|
-
function
|
|
17
|
-
return
|
|
21
|
+
function m(e, t) {
|
|
22
|
+
return u(e, "error", t);
|
|
18
23
|
}
|
|
19
|
-
function
|
|
20
|
-
return
|
|
24
|
+
function v(e, t) {
|
|
25
|
+
return u(e, "info", t);
|
|
21
26
|
}
|
|
22
|
-
function
|
|
23
|
-
return
|
|
27
|
+
function d(e, t) {
|
|
28
|
+
return u(e, "success", t);
|
|
24
29
|
}
|
|
25
|
-
function
|
|
26
|
-
return
|
|
30
|
+
function g(e, t) {
|
|
31
|
+
return u(e, "warning", t);
|
|
27
32
|
}
|
|
28
|
-
return
|
|
33
|
+
return y({
|
|
29
34
|
/**
|
|
30
35
|
* The list of toasts that are currently visible.
|
|
31
36
|
*/
|
|
32
|
-
active: b(
|
|
37
|
+
active: b(n),
|
|
33
38
|
/**
|
|
34
|
-
* Removes an active/visible toast.
|
|
39
|
+
* Removes an active/visible toast by id or by group and type.
|
|
35
40
|
*/
|
|
36
|
-
remove:
|
|
41
|
+
remove: f,
|
|
37
42
|
/**
|
|
38
43
|
* Creates a new toast and makes it active/visible.
|
|
39
44
|
*/
|
|
40
|
-
create:
|
|
45
|
+
create: u,
|
|
41
46
|
/**
|
|
42
47
|
* Removes all active/visible toasts.
|
|
43
48
|
*/
|
|
@@ -45,23 +50,23 @@ function E(c = { timeout: h }) {
|
|
|
45
50
|
/**
|
|
46
51
|
* Creates a new "error" toast.
|
|
47
52
|
*/
|
|
48
|
-
error:
|
|
53
|
+
error: m,
|
|
49
54
|
/**
|
|
50
55
|
* Creates a new "info" toast.
|
|
51
56
|
*/
|
|
52
|
-
info:
|
|
57
|
+
info: v,
|
|
53
58
|
/**
|
|
54
59
|
* Creates a new "success" toast.
|
|
55
60
|
*/
|
|
56
|
-
success:
|
|
61
|
+
success: d,
|
|
57
62
|
/**
|
|
58
63
|
* Creates a new "warning" toast.
|
|
59
64
|
*/
|
|
60
|
-
warning:
|
|
65
|
+
warning: g
|
|
61
66
|
});
|
|
62
67
|
}
|
|
63
68
|
export {
|
|
64
|
-
|
|
65
|
-
|
|
69
|
+
w as DEFAULT_TIMEOUT,
|
|
70
|
+
M as default
|
|
66
71
|
};
|
|
67
72
|
//# sourceMappingURL=useToasts.js.map
|
package/dist/useToasts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useToasts.js","sources":["../src/composables/useToasts/useToasts.ts"],"sourcesContent":["import merge from 'lodash-es/merge';\nimport uniqueId from 'lodash-es/uniqueId';\nimport { reactive, readonly, ref, RenderFunction } from 'vue';\n\nimport { StatusSeverity } from '../../../types/statusLevels';\n\nexport const DEFAULT_TIMEOUT = 5000;\n\nexport type Toast = {\n id: string;\n text: string | RenderFunction;\n status: StatusSeverity;\n};\n\nexport
|
|
1
|
+
{"version":3,"file":"useToasts.js","sources":["../src/composables/useToasts/useToasts.ts"],"sourcesContent":["import merge from 'lodash-es/merge';\nimport uniqueId from 'lodash-es/uniqueId';\nimport { reactive, readonly, ref, RenderFunction } from 'vue';\n\nimport { StatusSeverity } from '../../../types/statusLevels';\n\nexport const DEFAULT_TIMEOUT = 5000;\n\nexport type Toast = {\n id: string;\n text: string | RenderFunction;\n status: StatusSeverity;\n};\n\nexport interface ToastOptions {\n /**\n * The timeout in milliseconds before the toast is automatically dismissed. If set to `false`, the toast will persist until the user clicks on it.\n * @default DEFAULT_TIMEOUT\n */\n timeout?: number | boolean;\n /**\n * A group name ensures only one toast with the same group and status is visible at any given time.\n * Toasts with the same group but different statuses will be treated as separate and will display concurrently.\n */\n group?: string;\n}\n\ntype ToastIdOrUndefined<O extends ToastOptions | undefined> = O extends { id: string }\n ? Toast['id'] | undefined\n : Toast['id'];\n\nconst active = ref<Toast[]>([]);\n\nexport default function useToasts(globalOptions: Omit<ToastOptions, 'group'> = { timeout: DEFAULT_TIMEOUT }) {\n // method overloads\n function remove(toastId: Toast['id']): void;\n function remove(options: { group: string; status: StatusSeverity }): void;\n function remove(toastIdOrOptions: Toast['id'] | { group: string; status: StatusSeverity }) {\n const toastId = typeof toastIdOrOptions === 'string' ? toastIdOrOptions : undefined;\n const { group = undefined, status = undefined } = typeof toastIdOrOptions === 'object' ? toastIdOrOptions : {};\n\n if (!toastId && (!group || !status)) {\n throw new Error('Must provide either a toast ID or both group and type');\n }\n\n const idToRemove = group && status ? `toast-${status}-${group}` : String(toastId);\n const index = active.value.findIndex(({ id }) => id === idToRemove);\n if (index === -1) {\n return;\n }\n\n active.value.splice(index, 1);\n }\n\n // method overloads\n function create(text: Toast['text'], status: StatusSeverity, options?: Omit<ToastOptions, 'group'>): Toast['id'];\n function create(\n text: Toast['text'],\n status: StatusSeverity,\n options: ToastOptions & { id: string },\n ): Toast['id'] | undefined;\n function create(text: Toast['text'], status: StatusSeverity, localOptions?: ToastOptions): Toast['id'] | undefined {\n const options = merge({}, globalOptions, localOptions);\n\n const id = options?.group ? `toast-${status}-${options.group}` : uniqueId('toast-');\n if (options?.group && active.value.some(({ id: existingId }) => existingId === id)) {\n return;\n }\n\n active.value.push({ text, id, status });\n\n if (typeof options.timeout === 'number') {\n setTimeout(() => remove(id), Math.abs(options.timeout));\n }\n\n return id;\n }\n\n function removeAll() {\n active.value = [];\n }\n\n function error<O extends ToastOptions>(text: Toast['text'], options?: O): ToastIdOrUndefined<O> {\n return create(text, 'error', options);\n }\n\n function info<O extends ToastOptions>(text: Toast['text'], options?: O): ToastIdOrUndefined<O> {\n return create(text, 'info', options);\n }\n\n function success<O extends ToastOptions>(text: Toast['text'], options?: O): ToastIdOrUndefined<O> {\n return create(text, 'success', options);\n }\n\n function warning<O extends ToastOptions>(text: Toast['text'], options?: O): ToastIdOrUndefined<O> {\n return create(text, 'warning', options);\n }\n\n return reactive({\n /**\n * The list of toasts that are currently visible.\n */\n active: readonly(active),\n\n /**\n * Removes an active/visible toast by id or by group and type.\n */\n remove,\n\n /**\n * Creates a new toast and makes it active/visible.\n */\n create,\n\n /**\n * Removes all active/visible toasts.\n */\n removeAll,\n\n /**\n * Creates a new \"error\" toast.\n */\n error,\n\n /**\n * Creates a new \"info\" toast.\n */\n info,\n\n /**\n * Creates a new \"success\" toast.\n */\n success,\n\n /**\n * Creates a new \"warning\" toast.\n */\n warning,\n });\n}\n"],"names":["DEFAULT_TIMEOUT","active","ref","useToasts","globalOptions","remove","toastIdOrOptions","toastId","group","status","idToRemove","index","id","create","text","localOptions","options","merge","uniqueId","existingId","removeAll","error","info","success","warning","reactive","readonly"],"mappings":";;;AAMO,MAAMA,IAAkB,KAyBzBC,IAASC,EAAa,EAAE;AAE9B,SAAwBC,EAAUC,IAA6C,EAAE,SAASJ,KAAmB;AAI3G,WAASK,EAAOC,GAA2E;AACzF,UAAMC,IAAU,OAAOD,KAAqB,WAAWA,IAAmB,QACpE,EAAE,OAAAE,IAAQ,QAAW,QAAAC,IAAS,WAAc,OAAOH,KAAqB,WAAWA,IAAmB,CAAC;AAE7G,QAAI,CAACC,MAAY,CAACC,KAAS,CAACC;AACpB,YAAA,IAAI,MAAM,uDAAuD;AAGnE,UAAAC,IAAaF,KAASC,IAAS,SAASA,CAAM,IAAID,CAAK,KAAK,OAAOD,CAAO,GAC1EI,IAAQV,EAAO,MAAM,UAAU,CAAC,EAAE,IAAAW,EAAA,MAASA,MAAOF,CAAU;AAClE,IAAIC,MAAU,MAIPV,EAAA,MAAM,OAAOU,GAAO,CAAC;AAAA,EAAA;AAUrB,WAAAE,EAAOC,GAAq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