@reykjavik/webtools 0.3.13 → 0.3.15
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 +8 -5
- package/README.md +4 -2
- package/alertsStore/index.d.ts +8 -3
- package/alertsStore/index.js +15 -6
- package/esm/alertsStore/index.d.ts +8 -3
- package/esm/alertsStore/index.js +15 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,20 +4,23 @@
|
|
|
4
4
|
|
|
5
5
|
- ... <!-- Add new lines here. -->
|
|
6
6
|
|
|
7
|
-
## 0.3.
|
|
7
|
+
## 0.3.15
|
|
8
8
|
|
|
9
|
-
_2026-03-
|
|
9
|
+
_2026-03-18_
|
|
10
10
|
|
|
11
11
|
- `@reykjavik/webtools/alertsStore`:
|
|
12
|
-
- feat:
|
|
12
|
+
- feat: Support `defaultDuration` object w durations for each alert `level`
|
|
13
|
+
- feat: Bump the default `defaultDuration` to `'MEDIUM'` (more reasonable)
|
|
13
14
|
|
|
14
|
-
## 0.3.12
|
|
15
|
+
## 0.3.12 – 0.3.14
|
|
15
16
|
|
|
16
17
|
_2026-03-17_
|
|
17
18
|
|
|
18
19
|
- `@reykjavik/webtools/alertsStore`:
|
|
19
|
-
- feat: Make alert `type` property disabled by default, enabled via config
|
|
20
20
|
- feat: Add `AlerterConfig.title?:boolean` to enable optional alert `title`s
|
|
21
|
+
- feat: Add "message-only" shorthand signature to alerter dispatcher methods
|
|
22
|
+
- feat: Make alert `type` property disabled by default, enabled via config
|
|
23
|
+
(never used in the wild, yet)
|
|
21
24
|
|
|
22
25
|
## 0.3.7 – 0.3.11
|
|
23
26
|
|
package/README.md
CHANGED
|
@@ -1129,10 +1129,12 @@ The configuration options are as follows:
|
|
|
1129
1129
|
Default:
|
|
1130
1130
|
`{ BLINK: 2_000, SHORT: 4_000, MEDIUM: 8_000, LONG: 16_000, XLONG: 32_000, INDEFINITE: 0 }`.
|
|
1131
1131
|
|
|
1132
|
-
- **`defaultDuration?: string
|
|
1132
|
+
- **`defaultDuration?: string | Record<Level, Duration>`**
|
|
1133
1133
|
The duration to use for alerts if no duration is specified when
|
|
1134
1134
|
dispatching.
|
|
1135
|
-
|
|
1135
|
+
You can also pass an object with different default durations for each alert
|
|
1136
|
+
level, e.g. longer defaults for "errors" than "success" alerts.
|
|
1137
|
+
Default: `MEDIUM` if using the default durations, otherwise the default is
|
|
1136
1138
|
`0` (indefinite)
|
|
1137
1139
|
|
|
1138
1140
|
- **`storage?: Pick<Storage, 'getItem' | 'setItem'>`**
|
package/alertsStore/index.d.ts
CHANGED
|
@@ -85,10 +85,13 @@ export type AlerterConfig<Level extends string = (typeof defaultAlertLevels)[num
|
|
|
85
85
|
* Default duration to use for alerts if no duration is specified when
|
|
86
86
|
* dispatching.
|
|
87
87
|
*
|
|
88
|
-
*
|
|
88
|
+
* You can also pass an object with different default durations for each
|
|
89
|
+
* alert level, e.g. longer defaults for "errors" than "success" alerts.
|
|
90
|
+
*
|
|
91
|
+
* Default: `MEDIUM` if using the default durations, otherwise the default
|
|
89
92
|
* is `0` (indefinite)
|
|
90
93
|
*/
|
|
91
|
-
defaultDuration?: Durations extends Record<infer D, number> ? D : never
|
|
94
|
+
defaultDuration?: (Durations extends Record<infer D, number> ? (D extends string ? D : never) : never) | Record<Level, Durations extends Record<infer D, number> ? (D extends string ? D : never) : never>;
|
|
92
95
|
/**
|
|
93
96
|
* Whether to allow an optional `title` property on alerts.
|
|
94
97
|
*
|
|
@@ -206,7 +209,9 @@ export declare const createAlerterStore: <Level extends string = (typeof default
|
|
|
206
209
|
*
|
|
207
210
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#createalerterstore
|
|
208
211
|
*/
|
|
209
|
-
export type InferAlerterPayload<F extends Record<string, (...args: Array<any>) => void>> = F extends Record<string, (payload: infer P) => void> ? P
|
|
212
|
+
export type InferAlerterPayload<F extends Record<string, (...args: Array<any>) => void>> = F extends Record<string, (payload: infer P) => void> ? Extract<P, {
|
|
213
|
+
message: unknown;
|
|
214
|
+
}> : never;
|
|
210
215
|
/**
|
|
211
216
|
* Utility type for inferring the alert info object shape received by the
|
|
212
217
|
* callbacks of a specific alerter `subscribe` function.
|
package/alertsStore/index.js
CHANGED
|
@@ -62,7 +62,7 @@ const messageSchema = v.union([
|
|
|
62
62
|
])),
|
|
63
63
|
]);
|
|
64
64
|
// ---------------------------------------------------------------------------
|
|
65
|
-
const
|
|
65
|
+
const DEFAULT_KEY = 'app~alerts';
|
|
66
66
|
const defaultAlertLevels = ['info', 'warning', 'success', 'error'];
|
|
67
67
|
const defaultDurations = {
|
|
68
68
|
BLINK: 2000,
|
|
@@ -72,7 +72,7 @@ const defaultDurations = {
|
|
|
72
72
|
XLONG: 32000,
|
|
73
73
|
INDEFINITE: 0,
|
|
74
74
|
};
|
|
75
|
-
const
|
|
75
|
+
const DEFAULT_DEFAULT_DURATION = 'MEDIUM';
|
|
76
76
|
const storeKeys = {};
|
|
77
77
|
/**
|
|
78
78
|
* Factory function that creates an alerter store singleton with optional
|
|
@@ -81,8 +81,9 @@ const storeKeys = {};
|
|
|
81
81
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#createalerterstore
|
|
82
82
|
*/
|
|
83
83
|
/*#__NO_SIDE_EFFECTS__*/
|
|
84
|
+
// eslint-disable-next-line complexity
|
|
84
85
|
const createAlerterStore = (cfg = {}) => {
|
|
85
|
-
const STORE_KEY = cfg.key ||
|
|
86
|
+
const STORE_KEY = cfg.key || DEFAULT_KEY;
|
|
86
87
|
if (storeKeys[STORE_KEY]) {
|
|
87
88
|
throw new Error(`An alerter store with key "${STORE_KEY}" already exists.`);
|
|
88
89
|
}
|
|
@@ -90,9 +91,14 @@ const createAlerterStore = (cfg = {}) => {
|
|
|
90
91
|
const storgae = cfg.storage || (typeof sessionStorage !== 'undefined' ? sessionStorage : undefined);
|
|
91
92
|
const alertLevels = cfg.levels || defaultAlertLevels;
|
|
92
93
|
const durations = cfg.durations || defaultDurations;
|
|
93
|
-
const
|
|
94
|
+
const defaultDurationsByLevel = cfg.defaultDuration && typeof cfg.defaultDuration !== 'string'
|
|
94
95
|
? cfg.defaultDuration
|
|
95
|
-
:
|
|
96
|
+
: undefined;
|
|
97
|
+
const defaultDuration = !cfg.durations
|
|
98
|
+
? DEFAULT_DEFAULT_DURATION
|
|
99
|
+
: typeof cfg.defaultDuration === 'string'
|
|
100
|
+
? cfg.defaultDuration
|
|
101
|
+
: undefined;
|
|
96
102
|
const _notificationSchema = v.object({
|
|
97
103
|
level: v.picklist(alertLevels),
|
|
98
104
|
title: cfg.title ? v.optional(v.string()) : v.never(),
|
|
@@ -177,7 +183,10 @@ const createAlerterStore = (cfg = {}) => {
|
|
|
177
183
|
const buildNotification = (_payload, level) => {
|
|
178
184
|
// Strip away duration and delay (not part of the notification object)
|
|
179
185
|
const { duration, delay, ...payload } = _payload;
|
|
180
|
-
const durationMs = durations[
|
|
186
|
+
const durationMs = durations[duration ||
|
|
187
|
+
(defaultDurationsByLevel &&
|
|
188
|
+
defaultDurationsByLevel[level]) ||
|
|
189
|
+
(defaultDuration || '')];
|
|
181
190
|
return {
|
|
182
191
|
...payload,
|
|
183
192
|
level,
|
|
@@ -85,10 +85,13 @@ export type AlerterConfig<Level extends string = (typeof defaultAlertLevels)[num
|
|
|
85
85
|
* Default duration to use for alerts if no duration is specified when
|
|
86
86
|
* dispatching.
|
|
87
87
|
*
|
|
88
|
-
*
|
|
88
|
+
* You can also pass an object with different default durations for each
|
|
89
|
+
* alert level, e.g. longer defaults for "errors" than "success" alerts.
|
|
90
|
+
*
|
|
91
|
+
* Default: `MEDIUM` if using the default durations, otherwise the default
|
|
89
92
|
* is `0` (indefinite)
|
|
90
93
|
*/
|
|
91
|
-
defaultDuration?: Durations extends Record<infer D, number> ? D : never
|
|
94
|
+
defaultDuration?: (Durations extends Record<infer D, number> ? (D extends string ? D : never) : never) | Record<Level, Durations extends Record<infer D, number> ? (D extends string ? D : never) : never>;
|
|
92
95
|
/**
|
|
93
96
|
* Whether to allow an optional `title` property on alerts.
|
|
94
97
|
*
|
|
@@ -206,7 +209,9 @@ export declare const createAlerterStore: <Level extends string = (typeof default
|
|
|
206
209
|
*
|
|
207
210
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#createalerterstore
|
|
208
211
|
*/
|
|
209
|
-
export type InferAlerterPayload<F extends Record<string, (...args: Array<any>) => void>> = F extends Record<string, (payload: infer P) => void> ? P
|
|
212
|
+
export type InferAlerterPayload<F extends Record<string, (...args: Array<any>) => void>> = F extends Record<string, (payload: infer P) => void> ? Extract<P, {
|
|
213
|
+
message: unknown;
|
|
214
|
+
}> : never;
|
|
210
215
|
/**
|
|
211
216
|
* Utility type for inferring the alert info object shape received by the
|
|
212
217
|
* callbacks of a specific alerter `subscribe` function.
|
package/esm/alertsStore/index.js
CHANGED
|
@@ -26,7 +26,7 @@ const messageSchema = v.union([
|
|
|
26
26
|
])),
|
|
27
27
|
]);
|
|
28
28
|
// ---------------------------------------------------------------------------
|
|
29
|
-
const
|
|
29
|
+
const DEFAULT_KEY = 'app~alerts';
|
|
30
30
|
const defaultAlertLevels = ['info', 'warning', 'success', 'error'];
|
|
31
31
|
const defaultDurations = {
|
|
32
32
|
BLINK: 2000,
|
|
@@ -36,7 +36,7 @@ const defaultDurations = {
|
|
|
36
36
|
XLONG: 32000,
|
|
37
37
|
INDEFINITE: 0,
|
|
38
38
|
};
|
|
39
|
-
const
|
|
39
|
+
const DEFAULT_DEFAULT_DURATION = 'MEDIUM';
|
|
40
40
|
const storeKeys = {};
|
|
41
41
|
/**
|
|
42
42
|
* Factory function that creates an alerter store singleton with optional
|
|
@@ -45,8 +45,9 @@ const storeKeys = {};
|
|
|
45
45
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#createalerterstore
|
|
46
46
|
*/
|
|
47
47
|
/*#__NO_SIDE_EFFECTS__*/
|
|
48
|
+
// eslint-disable-next-line complexity
|
|
48
49
|
export const createAlerterStore = (cfg = {}) => {
|
|
49
|
-
const STORE_KEY = cfg.key ||
|
|
50
|
+
const STORE_KEY = cfg.key || DEFAULT_KEY;
|
|
50
51
|
if (storeKeys[STORE_KEY]) {
|
|
51
52
|
throw new Error(`An alerter store with key "${STORE_KEY}" already exists.`);
|
|
52
53
|
}
|
|
@@ -54,9 +55,14 @@ export const createAlerterStore = (cfg = {}) => {
|
|
|
54
55
|
const storgae = cfg.storage || (typeof sessionStorage !== 'undefined' ? sessionStorage : undefined);
|
|
55
56
|
const alertLevels = cfg.levels || defaultAlertLevels;
|
|
56
57
|
const durations = cfg.durations || defaultDurations;
|
|
57
|
-
const
|
|
58
|
+
const defaultDurationsByLevel = cfg.defaultDuration && typeof cfg.defaultDuration !== 'string'
|
|
58
59
|
? cfg.defaultDuration
|
|
59
|
-
:
|
|
60
|
+
: undefined;
|
|
61
|
+
const defaultDuration = !cfg.durations
|
|
62
|
+
? DEFAULT_DEFAULT_DURATION
|
|
63
|
+
: typeof cfg.defaultDuration === 'string'
|
|
64
|
+
? cfg.defaultDuration
|
|
65
|
+
: undefined;
|
|
60
66
|
const _notificationSchema = v.object({
|
|
61
67
|
level: v.picklist(alertLevels),
|
|
62
68
|
title: cfg.title ? v.optional(v.string()) : v.never(),
|
|
@@ -141,7 +147,10 @@ export const createAlerterStore = (cfg = {}) => {
|
|
|
141
147
|
const buildNotification = (_payload, level) => {
|
|
142
148
|
// Strip away duration and delay (not part of the notification object)
|
|
143
149
|
const { duration, delay, ...payload } = _payload;
|
|
144
|
-
const durationMs = durations[
|
|
150
|
+
const durationMs = durations[duration ||
|
|
151
|
+
(defaultDurationsByLevel &&
|
|
152
|
+
defaultDurationsByLevel[level]) ||
|
|
153
|
+
(defaultDuration || '')];
|
|
145
154
|
return {
|
|
146
155
|
...payload,
|
|
147
156
|
level,
|
package/package.json
CHANGED