@reykjavik/webtools 0.3.11 → 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/CHANGELOG.md CHANGED
@@ -4,14 +4,22 @@
4
4
 
5
5
  - ... <!-- Add new lines here. -->
6
6
 
7
- ## 0.3.11
7
+ ## 0.3.13
8
8
 
9
- _2026-03-16_
9
+ _2026-03-17_
10
+
11
+ - `@reykjavik/webtools/alertsStore`:
12
+ - feat: Add "message-only" shorthand signature to alerter dispatcher methods
13
+
14
+ ## 0.3.12
15
+
16
+ _2026-03-17_
10
17
 
11
- - `@reykjavik/webtools/alertsStore/react`:
12
- - feat: Support rendering `br` and `em` elements in alert messages
18
+ - `@reykjavik/webtools/alertsStore`:
19
+ - feat: Make alert `type` property disabled by default, enabled via config
20
+ - feat: Add `AlerterConfig.title?:boolean` to enable optional alert `title`s
13
21
 
14
- ## 0.3.7 – 0.3.10
22
+ ## 0.3.7 – 0.3.11
15
23
 
16
24
  _2026-03-16_
17
25
 
package/README.md CHANGED
@@ -1032,20 +1032,46 @@ 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
- delay: 500, // Optional delay
1037
+ delay: 500, // Optional delay in milliseconds
1039
1038
  });
1040
- // after 500ms the above alert is added to the store, and all subscribers
1041
- // are notified. The subscriber in `appRoot.ts` will log the following;
1039
+ alerter.info('Simple message!'); // Shorthand syntax
1040
+
1041
+ // On the next event loop tick the "info" alert (with no delay) is emitted, and all
1042
+ // subscribers are notified. The subscriber in `appRoot.ts` will log the following;
1043
+ /*
1044
+ Current alerts: [
1045
+ {
1046
+ id: '_234566-28_', // auto-generated
1047
+ level: 'info',
1048
+ message: 'Simple message!',
1049
+ duration: 5000, // ms
1050
+ dismiss: <Function>,
1051
+ setFalgs: <Function>,
1052
+ }
1053
+ ]
1054
+ Change type: 'add'
1055
+ Affected alert IDs: ['_234566-28_']
1056
+ */
1057
+
1058
+ // Then after 500ms the "success" alert is added to the store, and all subscribers
1059
+ // are notified again. The subscriber in `appRoot.ts` will log the following;
1042
1060
  /*
1043
1061
  Current alerts: [
1044
1062
  {
1045
- id: '_234566-27_', // autugenerated
1063
+ id: '_234566-28_',
1064
+ level: 'info',
1065
+ message: 'Simple message!',
1066
+ duration: 5000, // ms
1067
+ dismiss: <Function>,
1068
+ setFalgs: <Function>,
1069
+ },
1070
+ {
1071
+ id: '_234566-27_',
1046
1072
  level: 'success',
1047
1073
  message: 'All is good',
1048
- duration: 5000, // ms
1074
+ duration: 5000,
1049
1075
  dismiss: <Function>,
1050
1076
  setFalgs: <Function>,
1051
1077
  }
@@ -1086,7 +1112,11 @@ The configuration options are as follows:
1086
1112
  The allowed alert "types", which can be used to, for example, dispatch both
1087
1113
  "toasts" vs. "static alert banners" via the same store.
1088
1114
  This can also be used for more basic styling or categorization purposes.
1089
- Default: no restrictions, any string value is allowed.
1115
+ Default: `[ ]` (No types and the `type` property not allowed).
1116
+
1117
+ - **`title?: boolean`**
1118
+ Whether to allow an optional `title` property on alerts.
1119
+ Default: `false`.
1090
1120
 
1091
1121
  - **`flags?: Array<string>`**
1092
1122
  The allowed alert "flags", which can be changed during the lifetime of an
@@ -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: no restrictions, any string value is allowed.
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,
@@ -123,7 +121,7 @@ export declare const createAlerterStore: <Level extends string = (typeof default
123
121
  *
124
122
  * @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#createalerterstore
125
123
  */
126
- alerter: Record<Level, (payload: {
124
+ alerter: Record<Level, (payload: AlertMessage | ({
127
125
  /**
128
126
  * A simple string containing the alert message.
129
127
  *
@@ -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
- }) => void>;
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<_AlertNotification<Level, Type, Flag> & {
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
  /**
@@ -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: v.optional(cfg.types ? v.picklist(cfg.types) : v.string()),
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(),
@@ -224,7 +225,10 @@ const createAlerterStore = (cfg = {}) => {
224
225
  }, showAt - Date.now());
225
226
  };
226
227
  const _addAlert = (payload, level) => {
227
- const notification = buildNotification(payload, level);
228
+ const _payload = typeof payload === 'string' || Array.isArray(payload)
229
+ ? { message: payload }
230
+ : payload;
231
+ const notification = buildNotification(_payload, level);
228
232
  if (!notification.showAt) {
229
233
  // Notification starts active. Clone the array.
230
234
  alerts.active = [...alerts.active, addMethodsToAlertInfo(notification)];
@@ -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: no restrictions, any string value is allowed.
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,
@@ -123,7 +121,7 @@ export declare const createAlerterStore: <Level extends string = (typeof default
123
121
  *
124
122
  * @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#createalerterstore
125
123
  */
126
- alerter: Record<Level, (payload: {
124
+ alerter: Record<Level, (payload: AlertMessage | ({
127
125
  /**
128
126
  * A simple string containing the alert message.
129
127
  *
@@ -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
- }) => void>;
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<_AlertNotification<Level, Type, Flag> & {
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
  /**
@@ -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: v.optional(cfg.types ? v.picklist(cfg.types) : v.string()),
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(),
@@ -188,7 +189,10 @@ export const createAlerterStore = (cfg = {}) => {
188
189
  }, showAt - Date.now());
189
190
  };
190
191
  const _addAlert = (payload, level) => {
191
- const notification = buildNotification(payload, level);
192
+ const _payload = typeof payload === 'string' || Array.isArray(payload)
193
+ ? { message: payload }
194
+ : payload;
195
+ const notification = buildNotification(_payload, level);
192
196
  if (!notification.showAt) {
193
197
  // Notification starts active. Clone the array.
194
198
  alerts.active = [...alerts.active, addMethodsToAlertInfo(notification)];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reykjavik/webtools",
3
- "version": "0.3.11",
3
+ "version": "0.3.13",
4
4
  "description": "Misc. JS/TS helpers used by Reykjavík City's web dev teams.",
5
5
  "main": "index.js",
6
6
  "repository": "ssh://git@github.com:reykjavikcity/webtools.git",