@reykjavik/webtools 0.3.11 → 0.3.12
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/CHANGELOG.md +6 -5
- package/README.md +5 -2
- package/alertsStore/index.d.ts +34 -20
- package/alertsStore/index.js +2 -1
- package/esm/alertsStore/index.d.ts +34 -20
- package/esm/alertsStore/index.js +2 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,14 +4,15 @@
|
|
|
4
4
|
|
|
5
5
|
- ... <!-- Add new lines here. -->
|
|
6
6
|
|
|
7
|
-
## 0.3.
|
|
7
|
+
## 0.3.12
|
|
8
8
|
|
|
9
|
-
_2026-03-
|
|
9
|
+
_2026-03-17_
|
|
10
10
|
|
|
11
|
-
- `@reykjavik/webtools/alertsStore
|
|
12
|
-
- feat:
|
|
11
|
+
- `@reykjavik/webtools/alertsStore`:
|
|
12
|
+
- feat: Make alert `type` property disabled by default, enabled via config
|
|
13
|
+
- feat: Add `AlerterConfig.title?:boolean` to enable optional alert `title`s
|
|
13
14
|
|
|
14
|
-
## 0.3.7 – 0.3.
|
|
15
|
+
## 0.3.7 – 0.3.11
|
|
15
16
|
|
|
16
17
|
_2026-03-16_
|
|
17
18
|
|
package/README.md
CHANGED
|
@@ -1032,7 +1032,6 @@ setTimeout(unsubscribe, 3_600_000);
|
|
|
1032
1032
|
import { alerter } from '../alerterStore';
|
|
1033
1033
|
alerter.success({
|
|
1034
1034
|
message: 'All is good',
|
|
1035
|
-
// type: 'something',
|
|
1036
1035
|
// flags: ['pristine'],
|
|
1037
1036
|
duration: 'MEDIUM',
|
|
1038
1037
|
delay: 500, // Optional delay
|
|
@@ -1086,7 +1085,11 @@ The configuration options are as follows:
|
|
|
1086
1085
|
The allowed alert "types", which can be used to, for example, dispatch both
|
|
1087
1086
|
"toasts" vs. "static alert banners" via the same store.
|
|
1088
1087
|
This can also be used for more basic styling or categorization purposes.
|
|
1089
|
-
Default:
|
|
1088
|
+
Default: `[ ]` (No types and the `type` property not allowed).
|
|
1089
|
+
|
|
1090
|
+
- **`title?: boolean`**
|
|
1091
|
+
Whether to allow an optional `title` property on alerts.
|
|
1092
|
+
Default: `false`.
|
|
1090
1093
|
|
|
1091
1094
|
- **`flags?: Array<string>`**
|
|
1092
1095
|
The allowed alert "flags", which can be changed during the lifetime of an
|
package/alertsStore/index.d.ts
CHANGED
|
@@ -13,14 +13,6 @@ declare const messageSchema: v.UnionSchema<[v.StringSchema<undefined>, v.ArraySc
|
|
|
13
13
|
readonly text: v.StringSchema<undefined>;
|
|
14
14
|
}, undefined>], undefined>, undefined>], undefined>;
|
|
15
15
|
export type AlertMessage = v.InferOutput<typeof messageSchema>;
|
|
16
|
-
type _AlertNotification<Level, Type, Flag> = {
|
|
17
|
-
level: Level;
|
|
18
|
-
message: AlertMessage;
|
|
19
|
-
type?: Type;
|
|
20
|
-
flags?: Array<Flag>;
|
|
21
|
-
duration?: number;
|
|
22
|
-
id: string;
|
|
23
|
-
};
|
|
24
16
|
declare const defaultAlertLevels: readonly ["info", "warning", "success", "error"];
|
|
25
17
|
declare const defaultDurations: {
|
|
26
18
|
BLINK: number;
|
|
@@ -36,7 +28,7 @@ declare const defaultDurations: {
|
|
|
36
28
|
*
|
|
37
29
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#type-alerterconfig
|
|
38
30
|
*/
|
|
39
|
-
export type AlerterConfig<Level extends string = (typeof defaultAlertLevels)[number], Type extends string = string, Flag extends string = string, Duration extends string = keyof typeof defaultDurations, Durations extends Record<Duration, number> = Record<Duration, number>> = {
|
|
31
|
+
export type AlerterConfig<Level extends string = (typeof defaultAlertLevels)[number], Type extends string = string, Flag extends string = string, Title extends boolean = false, Duration extends string = keyof typeof defaultDurations, Durations extends Record<Duration, number> = Record<Duration, number>> = {
|
|
40
32
|
/**
|
|
41
33
|
* Identifier for the alerts store, used to create the key to persist alerts
|
|
42
34
|
* in `sessionStorage` (or other provided storage).
|
|
@@ -60,7 +52,7 @@ export type AlerterConfig<Level extends string = (typeof defaultAlertLevels)[num
|
|
|
60
52
|
*
|
|
61
53
|
* This can also be used for more basic styling or categorization purposes.
|
|
62
54
|
*
|
|
63
|
-
* Default:
|
|
55
|
+
* Default: `[ ]` (No types and the `type` property not allowed).
|
|
64
56
|
*/
|
|
65
57
|
types?: Array<Type>;
|
|
66
58
|
/**
|
|
@@ -97,6 +89,12 @@ export type AlerterConfig<Level extends string = (typeof defaultAlertLevels)[num
|
|
|
97
89
|
* is `0` (indefinite)
|
|
98
90
|
*/
|
|
99
91
|
defaultDuration?: Durations extends Record<infer D, number> ? D : never;
|
|
92
|
+
/**
|
|
93
|
+
* Whether to allow an optional `title` property on alerts.
|
|
94
|
+
*
|
|
95
|
+
* Default: `false`.
|
|
96
|
+
*/
|
|
97
|
+
title?: Title;
|
|
100
98
|
/**
|
|
101
99
|
* Optional custom storage object to use instead of `sessionStorage` (the
|
|
102
100
|
* default) for persisting alerts across page reloads, etc.
|
|
@@ -112,7 +110,7 @@ export type AlerterConfig<Level extends string = (typeof defaultAlertLevels)[num
|
|
|
112
110
|
*
|
|
113
111
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#createalerterstore
|
|
114
112
|
*/
|
|
115
|
-
export declare const createAlerterStore: <Level extends string = (typeof defaultAlertLevels)[number], Type extends string = string, Flag extends string = string, Duration extends string = keyof typeof defaultDurations>(cfg?: AlerterConfig<Level, Type, Flag, Duration>) => {
|
|
113
|
+
export declare const createAlerterStore: <Level extends string = (typeof defaultAlertLevels)[number], Type extends string = string, Flag extends string = string, Title extends boolean = false, Duration extends string = keyof typeof defaultDurations>(cfg?: AlerterConfig<Level, Type, Flag, Title, Duration>) => {
|
|
116
114
|
/**
|
|
117
115
|
* Singleton object with methods for showing alerts of different levels.
|
|
118
116
|
* Pass a payload object to the method of the level you want to dispatch,
|
|
@@ -135,13 +133,6 @@ export declare const createAlerterStore: <Level extends string = (typeof default
|
|
|
135
133
|
* them.)
|
|
136
134
|
*/
|
|
137
135
|
message: AlertMessage;
|
|
138
|
-
/**
|
|
139
|
-
* Allows distinguishing between different "types" of alerts, for example,
|
|
140
|
-
* to dispatch both "toasts" vs. "static alert banners" via the same store.
|
|
141
|
-
*
|
|
142
|
-
* May also be used for more basic styling or categorization purposes.
|
|
143
|
-
*/
|
|
144
|
-
type?: Type;
|
|
145
136
|
/**
|
|
146
137
|
* Flag values can be changed during the lifetime of
|
|
147
138
|
* an alert using the `setFlags` function on each `AlertInfo` object.
|
|
@@ -159,7 +150,20 @@ export declare const createAlerterStore: <Level extends string = (typeof default
|
|
|
159
150
|
*/
|
|
160
151
|
duration?: Duration;
|
|
161
152
|
delay?: number;
|
|
162
|
-
}
|
|
153
|
+
} & (Title extends true ? {
|
|
154
|
+
/**
|
|
155
|
+
* Optional title to accompany the alert message.
|
|
156
|
+
*/
|
|
157
|
+
title?: string;
|
|
158
|
+
} : unknown) & (string extends Type ? unknown : {
|
|
159
|
+
/**
|
|
160
|
+
* Allows distinguishing between different "types" of alerts, for example,
|
|
161
|
+
* to dispatch both "toasts" vs. "static alert banners" via the same store.
|
|
162
|
+
*
|
|
163
|
+
* May also be used for more basic styling or categorization purposes.
|
|
164
|
+
*/
|
|
165
|
+
type?: Type;
|
|
166
|
+
})) => void>;
|
|
163
167
|
/**
|
|
164
168
|
* Subscribes to alert events. The provided callback will be called whenever a
|
|
165
169
|
* alert is added or cleared.
|
|
@@ -172,7 +176,17 @@ export declare const createAlerterStore: <Level extends string = (typeof default
|
|
|
172
176
|
*
|
|
173
177
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#createalerterstore
|
|
174
178
|
*/
|
|
175
|
-
subscribe: (callback: (notifications: Array<
|
|
179
|
+
subscribe: (callback: (notifications: Array<{
|
|
180
|
+
level: Level;
|
|
181
|
+
message: AlertMessage;
|
|
182
|
+
flags?: Flag[] | undefined;
|
|
183
|
+
duration?: number;
|
|
184
|
+
id: string;
|
|
185
|
+
} & (Title extends true ? {
|
|
186
|
+
title?: string;
|
|
187
|
+
} : unknown) & (string extends Type ? unknown : {
|
|
188
|
+
type?: Type | undefined;
|
|
189
|
+
}) & {
|
|
176
190
|
/** Dispatcher function that dismisses/hides/removes the callback */
|
|
177
191
|
dismiss: () => void;
|
|
178
192
|
/**
|
package/alertsStore/index.js
CHANGED
|
@@ -95,8 +95,9 @@ const createAlerterStore = (cfg = {}) => {
|
|
|
95
95
|
: defaultDefaultDuration;
|
|
96
96
|
const _notificationSchema = v.object({
|
|
97
97
|
level: v.picklist(alertLevels),
|
|
98
|
+
title: cfg.title ? v.optional(v.string()) : v.never(),
|
|
98
99
|
message: messageSchema,
|
|
99
|
-
type:
|
|
100
|
+
type: cfg.types && cfg.types.length ? v.optional(v.picklist(cfg.types)) : v.never(),
|
|
100
101
|
flags: v.optional(v.array(cfg.flags ? v.picklist(cfg.flags) : v.string())),
|
|
101
102
|
duration: v.optional(v.number()),
|
|
102
103
|
id: v.string(),
|
|
@@ -13,14 +13,6 @@ declare const messageSchema: v.UnionSchema<[v.StringSchema<undefined>, v.ArraySc
|
|
|
13
13
|
readonly text: v.StringSchema<undefined>;
|
|
14
14
|
}, undefined>], undefined>, undefined>], undefined>;
|
|
15
15
|
export type AlertMessage = v.InferOutput<typeof messageSchema>;
|
|
16
|
-
type _AlertNotification<Level, Type, Flag> = {
|
|
17
|
-
level: Level;
|
|
18
|
-
message: AlertMessage;
|
|
19
|
-
type?: Type;
|
|
20
|
-
flags?: Array<Flag>;
|
|
21
|
-
duration?: number;
|
|
22
|
-
id: string;
|
|
23
|
-
};
|
|
24
16
|
declare const defaultAlertLevels: readonly ["info", "warning", "success", "error"];
|
|
25
17
|
declare const defaultDurations: {
|
|
26
18
|
BLINK: number;
|
|
@@ -36,7 +28,7 @@ declare const defaultDurations: {
|
|
|
36
28
|
*
|
|
37
29
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#type-alerterconfig
|
|
38
30
|
*/
|
|
39
|
-
export type AlerterConfig<Level extends string = (typeof defaultAlertLevels)[number], Type extends string = string, Flag extends string = string, Duration extends string = keyof typeof defaultDurations, Durations extends Record<Duration, number> = Record<Duration, number>> = {
|
|
31
|
+
export type AlerterConfig<Level extends string = (typeof defaultAlertLevels)[number], Type extends string = string, Flag extends string = string, Title extends boolean = false, Duration extends string = keyof typeof defaultDurations, Durations extends Record<Duration, number> = Record<Duration, number>> = {
|
|
40
32
|
/**
|
|
41
33
|
* Identifier for the alerts store, used to create the key to persist alerts
|
|
42
34
|
* in `sessionStorage` (or other provided storage).
|
|
@@ -60,7 +52,7 @@ export type AlerterConfig<Level extends string = (typeof defaultAlertLevels)[num
|
|
|
60
52
|
*
|
|
61
53
|
* This can also be used for more basic styling or categorization purposes.
|
|
62
54
|
*
|
|
63
|
-
* Default:
|
|
55
|
+
* Default: `[ ]` (No types and the `type` property not allowed).
|
|
64
56
|
*/
|
|
65
57
|
types?: Array<Type>;
|
|
66
58
|
/**
|
|
@@ -97,6 +89,12 @@ export type AlerterConfig<Level extends string = (typeof defaultAlertLevels)[num
|
|
|
97
89
|
* is `0` (indefinite)
|
|
98
90
|
*/
|
|
99
91
|
defaultDuration?: Durations extends Record<infer D, number> ? D : never;
|
|
92
|
+
/**
|
|
93
|
+
* Whether to allow an optional `title` property on alerts.
|
|
94
|
+
*
|
|
95
|
+
* Default: `false`.
|
|
96
|
+
*/
|
|
97
|
+
title?: Title;
|
|
100
98
|
/**
|
|
101
99
|
* Optional custom storage object to use instead of `sessionStorage` (the
|
|
102
100
|
* default) for persisting alerts across page reloads, etc.
|
|
@@ -112,7 +110,7 @@ export type AlerterConfig<Level extends string = (typeof defaultAlertLevels)[num
|
|
|
112
110
|
*
|
|
113
111
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#createalerterstore
|
|
114
112
|
*/
|
|
115
|
-
export declare const createAlerterStore: <Level extends string = (typeof defaultAlertLevels)[number], Type extends string = string, Flag extends string = string, Duration extends string = keyof typeof defaultDurations>(cfg?: AlerterConfig<Level, Type, Flag, Duration>) => {
|
|
113
|
+
export declare const createAlerterStore: <Level extends string = (typeof defaultAlertLevels)[number], Type extends string = string, Flag extends string = string, Title extends boolean = false, Duration extends string = keyof typeof defaultDurations>(cfg?: AlerterConfig<Level, Type, Flag, Title, Duration>) => {
|
|
116
114
|
/**
|
|
117
115
|
* Singleton object with methods for showing alerts of different levels.
|
|
118
116
|
* Pass a payload object to the method of the level you want to dispatch,
|
|
@@ -135,13 +133,6 @@ export declare const createAlerterStore: <Level extends string = (typeof default
|
|
|
135
133
|
* them.)
|
|
136
134
|
*/
|
|
137
135
|
message: AlertMessage;
|
|
138
|
-
/**
|
|
139
|
-
* Allows distinguishing between different "types" of alerts, for example,
|
|
140
|
-
* to dispatch both "toasts" vs. "static alert banners" via the same store.
|
|
141
|
-
*
|
|
142
|
-
* May also be used for more basic styling or categorization purposes.
|
|
143
|
-
*/
|
|
144
|
-
type?: Type;
|
|
145
136
|
/**
|
|
146
137
|
* Flag values can be changed during the lifetime of
|
|
147
138
|
* an alert using the `setFlags` function on each `AlertInfo` object.
|
|
@@ -159,7 +150,20 @@ export declare const createAlerterStore: <Level extends string = (typeof default
|
|
|
159
150
|
*/
|
|
160
151
|
duration?: Duration;
|
|
161
152
|
delay?: number;
|
|
162
|
-
}
|
|
153
|
+
} & (Title extends true ? {
|
|
154
|
+
/**
|
|
155
|
+
* Optional title to accompany the alert message.
|
|
156
|
+
*/
|
|
157
|
+
title?: string;
|
|
158
|
+
} : unknown) & (string extends Type ? unknown : {
|
|
159
|
+
/**
|
|
160
|
+
* Allows distinguishing between different "types" of alerts, for example,
|
|
161
|
+
* to dispatch both "toasts" vs. "static alert banners" via the same store.
|
|
162
|
+
*
|
|
163
|
+
* May also be used for more basic styling or categorization purposes.
|
|
164
|
+
*/
|
|
165
|
+
type?: Type;
|
|
166
|
+
})) => void>;
|
|
163
167
|
/**
|
|
164
168
|
* Subscribes to alert events. The provided callback will be called whenever a
|
|
165
169
|
* alert is added or cleared.
|
|
@@ -172,7 +176,17 @@ export declare const createAlerterStore: <Level extends string = (typeof default
|
|
|
172
176
|
*
|
|
173
177
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#createalerterstore
|
|
174
178
|
*/
|
|
175
|
-
subscribe: (callback: (notifications: Array<
|
|
179
|
+
subscribe: (callback: (notifications: Array<{
|
|
180
|
+
level: Level;
|
|
181
|
+
message: AlertMessage;
|
|
182
|
+
flags?: Flag[] | undefined;
|
|
183
|
+
duration?: number;
|
|
184
|
+
id: string;
|
|
185
|
+
} & (Title extends true ? {
|
|
186
|
+
title?: string;
|
|
187
|
+
} : unknown) & (string extends Type ? unknown : {
|
|
188
|
+
type?: Type | undefined;
|
|
189
|
+
}) & {
|
|
176
190
|
/** Dispatcher function that dismisses/hides/removes the callback */
|
|
177
191
|
dismiss: () => void;
|
|
178
192
|
/**
|
package/esm/alertsStore/index.js
CHANGED
|
@@ -59,8 +59,9 @@ export const createAlerterStore = (cfg = {}) => {
|
|
|
59
59
|
: defaultDefaultDuration;
|
|
60
60
|
const _notificationSchema = v.object({
|
|
61
61
|
level: v.picklist(alertLevels),
|
|
62
|
+
title: cfg.title ? v.optional(v.string()) : v.never(),
|
|
62
63
|
message: messageSchema,
|
|
63
|
-
type:
|
|
64
|
+
type: cfg.types && cfg.types.length ? v.optional(v.picklist(cfg.types)) : v.never(),
|
|
64
65
|
flags: v.optional(v.array(cfg.flags ? v.picklist(cfg.flags) : v.string())),
|
|
65
66
|
duration: v.optional(v.number()),
|
|
66
67
|
id: v.string(),
|
package/package.json
CHANGED