@reykjavik/webtools 0.3.10 → 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 +7 -6
- package/README.md +7 -4
- package/alertsStore/index.d.ts +37 -21
- package/alertsStore/index.js +7 -2
- package/alertsStore/react.js +3 -0
- package/esm/alertsStore/index.d.ts +37 -21
- package/esm/alertsStore/index.js +7 -2
- package/esm/alertsStore/react.js +3 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,19 +4,20 @@
|
|
|
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
|
-
-
|
|
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
|
|
|
18
19
|
- feat: Add `@reykjavik/webtools/alertsStore` for toasts and other global UI
|
|
19
|
-
feedback messages along with helpers
|
|
20
|
+
feedback messages along with `@reykjavik/webtools/alertsStore/react` helpers
|
|
20
21
|
|
|
21
22
|
## 0.3.6
|
|
22
23
|
|
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
|
|
@@ -1167,8 +1170,8 @@ import { Toast } from '../components/Toast';
|
|
|
1167
1170
|
`renderAlertMessage(message: AlertInfo['message'], onLinkClick?: (e: MouseEvent) => void, linkComponent?: renderAlertMessage.LinkRenderer): ReactNode`
|
|
1168
1171
|
|
|
1169
1172
|
Helper to render an alerter alert message, which can be a simple string or a
|
|
1170
|
-
more complex array of strings and objects representing links
|
|
1171
|
-
text formatting.
|
|
1173
|
+
more complex array of strings and objects representing links, `br` elements
|
|
1174
|
+
and rich (`strong`/`em`) text formatting.
|
|
1172
1175
|
|
|
1173
1176
|
You can optionally pass an additional `onLinkClick` handler as a second
|
|
1174
1177
|
parameter. (For example the alert's `dismiss` dispatcher.)
|
package/alertsStore/index.d.ts
CHANGED
|
@@ -7,18 +7,12 @@ declare const messageSchema: v.UnionSchema<[v.StringSchema<undefined>, v.ArraySc
|
|
|
7
7
|
readonly hrefLang: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
8
8
|
readonly lang: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
9
9
|
}, undefined>, v.ObjectSchema<{
|
|
10
|
-
readonly tag: v.LiteralSchema<"
|
|
10
|
+
readonly tag: v.LiteralSchema<"br", undefined>;
|
|
11
|
+
}, undefined>, v.ObjectSchema<{
|
|
12
|
+
readonly tag: v.PicklistSchema<["strong", "em"], undefined>;
|
|
11
13
|
readonly text: v.StringSchema<undefined>;
|
|
12
14
|
}, undefined>], undefined>, undefined>], undefined>;
|
|
13
15
|
export type AlertMessage = v.InferOutput<typeof messageSchema>;
|
|
14
|
-
type _AlertNotification<Level, Type, Flag> = {
|
|
15
|
-
level: Level;
|
|
16
|
-
message: AlertMessage;
|
|
17
|
-
type?: Type;
|
|
18
|
-
flags?: Array<Flag>;
|
|
19
|
-
duration?: number;
|
|
20
|
-
id: string;
|
|
21
|
-
};
|
|
22
16
|
declare const defaultAlertLevels: readonly ["info", "warning", "success", "error"];
|
|
23
17
|
declare const defaultDurations: {
|
|
24
18
|
BLINK: number;
|
|
@@ -34,7 +28,7 @@ declare const defaultDurations: {
|
|
|
34
28
|
*
|
|
35
29
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#type-alerterconfig
|
|
36
30
|
*/
|
|
37
|
-
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>> = {
|
|
38
32
|
/**
|
|
39
33
|
* Identifier for the alerts store, used to create the key to persist alerts
|
|
40
34
|
* in `sessionStorage` (or other provided storage).
|
|
@@ -58,7 +52,7 @@ export type AlerterConfig<Level extends string = (typeof defaultAlertLevels)[num
|
|
|
58
52
|
*
|
|
59
53
|
* This can also be used for more basic styling or categorization purposes.
|
|
60
54
|
*
|
|
61
|
-
* Default:
|
|
55
|
+
* Default: `[ ]` (No types and the `type` property not allowed).
|
|
62
56
|
*/
|
|
63
57
|
types?: Array<Type>;
|
|
64
58
|
/**
|
|
@@ -95,6 +89,12 @@ export type AlerterConfig<Level extends string = (typeof defaultAlertLevels)[num
|
|
|
95
89
|
* is `0` (indefinite)
|
|
96
90
|
*/
|
|
97
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;
|
|
98
98
|
/**
|
|
99
99
|
* Optional custom storage object to use instead of `sessionStorage` (the
|
|
100
100
|
* default) for persisting alerts across page reloads, etc.
|
|
@@ -110,7 +110,7 @@ export type AlerterConfig<Level extends string = (typeof defaultAlertLevels)[num
|
|
|
110
110
|
*
|
|
111
111
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#createalerterstore
|
|
112
112
|
*/
|
|
113
|
-
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>) => {
|
|
114
114
|
/**
|
|
115
115
|
* Singleton object with methods for showing alerts of different levels.
|
|
116
116
|
* Pass a payload object to the method of the level you want to dispatch,
|
|
@@ -133,13 +133,6 @@ export declare const createAlerterStore: <Level extends string = (typeof default
|
|
|
133
133
|
* them.)
|
|
134
134
|
*/
|
|
135
135
|
message: AlertMessage;
|
|
136
|
-
/**
|
|
137
|
-
* Allows distinguishing between different "types" of alerts, for example,
|
|
138
|
-
* to dispatch both "toasts" vs. "static alert banners" via the same store.
|
|
139
|
-
*
|
|
140
|
-
* May also be used for more basic styling or categorization purposes.
|
|
141
|
-
*/
|
|
142
|
-
type?: Type;
|
|
143
136
|
/**
|
|
144
137
|
* Flag values can be changed during the lifetime of
|
|
145
138
|
* an alert using the `setFlags` function on each `AlertInfo` object.
|
|
@@ -157,7 +150,20 @@ export declare const createAlerterStore: <Level extends string = (typeof default
|
|
|
157
150
|
*/
|
|
158
151
|
duration?: Duration;
|
|
159
152
|
delay?: number;
|
|
160
|
-
}
|
|
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>;
|
|
161
167
|
/**
|
|
162
168
|
* Subscribes to alert events. The provided callback will be called whenever a
|
|
163
169
|
* alert is added or cleared.
|
|
@@ -170,7 +176,17 @@ export declare const createAlerterStore: <Level extends string = (typeof default
|
|
|
170
176
|
*
|
|
171
177
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#createalerterstore
|
|
172
178
|
*/
|
|
173
|
-
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
|
+
}) & {
|
|
174
190
|
/** Dispatcher function that dismisses/hides/removes the callback */
|
|
175
191
|
dismiss: () => void;
|
|
176
192
|
/**
|
package/alertsStore/index.js
CHANGED
|
@@ -50,9 +50,13 @@ const messageSchema = v.union([
|
|
|
50
50
|
hrefLang: v.optional(v.string()),
|
|
51
51
|
lang: v.optional(v.string()),
|
|
52
52
|
}),
|
|
53
|
+
// line break elements
|
|
54
|
+
v.object({
|
|
55
|
+
tag: v.literal('br'),
|
|
56
|
+
}),
|
|
53
57
|
// strong/bold elements
|
|
54
58
|
v.object({
|
|
55
|
-
tag: v.
|
|
59
|
+
tag: v.picklist(['strong', 'em']),
|
|
56
60
|
text: v.string(),
|
|
57
61
|
}),
|
|
58
62
|
])),
|
|
@@ -91,8 +95,9 @@ const createAlerterStore = (cfg = {}) => {
|
|
|
91
95
|
: defaultDefaultDuration;
|
|
92
96
|
const _notificationSchema = v.object({
|
|
93
97
|
level: v.picklist(alertLevels),
|
|
98
|
+
title: cfg.title ? v.optional(v.string()) : v.never(),
|
|
94
99
|
message: messageSchema,
|
|
95
|
-
type:
|
|
100
|
+
type: cfg.types && cfg.types.length ? v.optional(v.picklist(cfg.types)) : v.never(),
|
|
96
101
|
flags: v.optional(v.array(cfg.flags ? v.picklist(cfg.flags) : v.string())),
|
|
97
102
|
duration: v.optional(v.number()),
|
|
98
103
|
id: v.string(),
|
package/alertsStore/react.js
CHANGED
|
@@ -81,6 +81,9 @@ const renderAlertMessage = (message, onLinkClick, linkComponent) => {
|
|
|
81
81
|
react_1.default.createElement(Link, { key: i, ...linkProps, onClick: onLinkClick && ((e) => onLinkClick(e)) }, text),
|
|
82
82
|
];
|
|
83
83
|
}
|
|
84
|
+
if (part.tag === 'br') {
|
|
85
|
+
return react_1.default.createElement("br", { key: i });
|
|
86
|
+
}
|
|
84
87
|
return [' ', react_1.default.createElement(part.tag, { key: i }, part.text)];
|
|
85
88
|
});
|
|
86
89
|
};
|
|
@@ -7,18 +7,12 @@ declare const messageSchema: v.UnionSchema<[v.StringSchema<undefined>, v.ArraySc
|
|
|
7
7
|
readonly hrefLang: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
8
8
|
readonly lang: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
9
9
|
}, undefined>, v.ObjectSchema<{
|
|
10
|
-
readonly tag: v.LiteralSchema<"
|
|
10
|
+
readonly tag: v.LiteralSchema<"br", undefined>;
|
|
11
|
+
}, undefined>, v.ObjectSchema<{
|
|
12
|
+
readonly tag: v.PicklistSchema<["strong", "em"], undefined>;
|
|
11
13
|
readonly text: v.StringSchema<undefined>;
|
|
12
14
|
}, undefined>], undefined>, undefined>], undefined>;
|
|
13
15
|
export type AlertMessage = v.InferOutput<typeof messageSchema>;
|
|
14
|
-
type _AlertNotification<Level, Type, Flag> = {
|
|
15
|
-
level: Level;
|
|
16
|
-
message: AlertMessage;
|
|
17
|
-
type?: Type;
|
|
18
|
-
flags?: Array<Flag>;
|
|
19
|
-
duration?: number;
|
|
20
|
-
id: string;
|
|
21
|
-
};
|
|
22
16
|
declare const defaultAlertLevels: readonly ["info", "warning", "success", "error"];
|
|
23
17
|
declare const defaultDurations: {
|
|
24
18
|
BLINK: number;
|
|
@@ -34,7 +28,7 @@ declare const defaultDurations: {
|
|
|
34
28
|
*
|
|
35
29
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#type-alerterconfig
|
|
36
30
|
*/
|
|
37
|
-
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>> = {
|
|
38
32
|
/**
|
|
39
33
|
* Identifier for the alerts store, used to create the key to persist alerts
|
|
40
34
|
* in `sessionStorage` (or other provided storage).
|
|
@@ -58,7 +52,7 @@ export type AlerterConfig<Level extends string = (typeof defaultAlertLevels)[num
|
|
|
58
52
|
*
|
|
59
53
|
* This can also be used for more basic styling or categorization purposes.
|
|
60
54
|
*
|
|
61
|
-
* Default:
|
|
55
|
+
* Default: `[ ]` (No types and the `type` property not allowed).
|
|
62
56
|
*/
|
|
63
57
|
types?: Array<Type>;
|
|
64
58
|
/**
|
|
@@ -95,6 +89,12 @@ export type AlerterConfig<Level extends string = (typeof defaultAlertLevels)[num
|
|
|
95
89
|
* is `0` (indefinite)
|
|
96
90
|
*/
|
|
97
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;
|
|
98
98
|
/**
|
|
99
99
|
* Optional custom storage object to use instead of `sessionStorage` (the
|
|
100
100
|
* default) for persisting alerts across page reloads, etc.
|
|
@@ -110,7 +110,7 @@ export type AlerterConfig<Level extends string = (typeof defaultAlertLevels)[num
|
|
|
110
110
|
*
|
|
111
111
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#createalerterstore
|
|
112
112
|
*/
|
|
113
|
-
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>) => {
|
|
114
114
|
/**
|
|
115
115
|
* Singleton object with methods for showing alerts of different levels.
|
|
116
116
|
* Pass a payload object to the method of the level you want to dispatch,
|
|
@@ -133,13 +133,6 @@ export declare const createAlerterStore: <Level extends string = (typeof default
|
|
|
133
133
|
* them.)
|
|
134
134
|
*/
|
|
135
135
|
message: AlertMessage;
|
|
136
|
-
/**
|
|
137
|
-
* Allows distinguishing between different "types" of alerts, for example,
|
|
138
|
-
* to dispatch both "toasts" vs. "static alert banners" via the same store.
|
|
139
|
-
*
|
|
140
|
-
* May also be used for more basic styling or categorization purposes.
|
|
141
|
-
*/
|
|
142
|
-
type?: Type;
|
|
143
136
|
/**
|
|
144
137
|
* Flag values can be changed during the lifetime of
|
|
145
138
|
* an alert using the `setFlags` function on each `AlertInfo` object.
|
|
@@ -157,7 +150,20 @@ export declare const createAlerterStore: <Level extends string = (typeof default
|
|
|
157
150
|
*/
|
|
158
151
|
duration?: Duration;
|
|
159
152
|
delay?: number;
|
|
160
|
-
}
|
|
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>;
|
|
161
167
|
/**
|
|
162
168
|
* Subscribes to alert events. The provided callback will be called whenever a
|
|
163
169
|
* alert is added or cleared.
|
|
@@ -170,7 +176,17 @@ export declare const createAlerterStore: <Level extends string = (typeof default
|
|
|
170
176
|
*
|
|
171
177
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#createalerterstore
|
|
172
178
|
*/
|
|
173
|
-
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
|
+
}) & {
|
|
174
190
|
/** Dispatcher function that dismisses/hides/removes the callback */
|
|
175
191
|
dismiss: () => void;
|
|
176
192
|
/**
|
package/esm/alertsStore/index.js
CHANGED
|
@@ -14,9 +14,13 @@ const messageSchema = v.union([
|
|
|
14
14
|
hrefLang: v.optional(v.string()),
|
|
15
15
|
lang: v.optional(v.string()),
|
|
16
16
|
}),
|
|
17
|
+
// line break elements
|
|
18
|
+
v.object({
|
|
19
|
+
tag: v.literal('br'),
|
|
20
|
+
}),
|
|
17
21
|
// strong/bold elements
|
|
18
22
|
v.object({
|
|
19
|
-
tag: v.
|
|
23
|
+
tag: v.picklist(['strong', 'em']),
|
|
20
24
|
text: v.string(),
|
|
21
25
|
}),
|
|
22
26
|
])),
|
|
@@ -55,8 +59,9 @@ export const createAlerterStore = (cfg = {}) => {
|
|
|
55
59
|
: defaultDefaultDuration;
|
|
56
60
|
const _notificationSchema = v.object({
|
|
57
61
|
level: v.picklist(alertLevels),
|
|
62
|
+
title: cfg.title ? v.optional(v.string()) : v.never(),
|
|
58
63
|
message: messageSchema,
|
|
59
|
-
type:
|
|
64
|
+
type: cfg.types && cfg.types.length ? v.optional(v.picklist(cfg.types)) : v.never(),
|
|
60
65
|
flags: v.optional(v.array(cfg.flags ? v.picklist(cfg.flags) : v.string())),
|
|
61
66
|
duration: v.optional(v.number()),
|
|
62
67
|
id: v.string(),
|
package/esm/alertsStore/react.js
CHANGED
|
@@ -44,6 +44,9 @@ export const renderAlertMessage = (message, onLinkClick, linkComponent) => {
|
|
|
44
44
|
React.createElement(Link, { key: i, ...linkProps, onClick: onLinkClick && ((e) => onLinkClick(e)) }, text),
|
|
45
45
|
];
|
|
46
46
|
}
|
|
47
|
+
if (part.tag === 'br') {
|
|
48
|
+
return React.createElement("br", { key: i });
|
|
49
|
+
}
|
|
47
50
|
return [' ', React.createElement(part.tag, { key: i }, part.text)];
|
|
48
51
|
});
|
|
49
52
|
};
|
package/package.json
CHANGED