@marianmeres/stuic 1.38.0 → 1.39.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.
@@ -39,7 +39,7 @@ export interface AlertConfirmPromptOptions extends Record<string, any> {
39
39
  }>;
40
40
  forceAsHtml?: boolean;
41
41
  }
42
- export declare const createAlertConfirmPromptStore: () => {
42
+ export declare const createAlertConfirmPromptStore: (defaults?: Partial<AlertConfirmPromptOptions>) => {
43
43
  subscribe: (cb: import("@marianmeres/store").Subscribe<AlertConfirmPromptOptions[]>) => import("@marianmeres/store").Unsubscribe;
44
44
  get: () => AlertConfirmPromptOptions[];
45
45
  push: (o: Partial<AlertConfirmPromptOptions>) => void;
@@ -1,5 +1,6 @@
1
1
  import { createStore } from '@marianmeres/store';
2
2
  import { createClog } from '@marianmeres/clog';
3
+ import { dset as mergeDeep } from 'dset/merge';
3
4
  const clog = createClog('alert-confirm-prompt');
4
5
  // export class AlertConfirmPromptType {
5
6
  // static readonly ALERT: 'alert';
@@ -14,36 +15,42 @@ export var AlertConfirmPromptType;
14
15
  })(AlertConfirmPromptType || (AlertConfirmPromptType = {}));
15
16
  const isFn = (v) => typeof v === 'function';
16
17
  const ucf = (s) => `${s}`[0].toUpperCase() + `${s}`.slice(1);
17
- export const createAlertConfirmPromptStore = () => {
18
+ export const createAlertConfirmPromptStore = (defaults) => {
18
19
  // fifo
19
20
  const _stack = createStore([]);
20
- // defaults
21
- const labelOk = 'OK';
22
- const labelCancel = 'Cancel';
23
- // optional 3rd button label
24
- const labelCustom = undefined;
25
21
  const push = (o) => {
22
+ defaults ??= {};
23
+ o ??= {};
24
+ defaults = {
25
+ ...{
26
+ labelOk: 'OK',
27
+ labelCancel: 'Cancel',
28
+ iconFn: true,
29
+ title: ucf(o.type),
30
+ },
31
+ ...defaults,
32
+ };
26
33
  if (!isFn(o.onOk))
27
34
  o.onOk = shift;
28
35
  if (!isFn(o.onCancel))
29
36
  o.onCancel = shift;
30
37
  if (!isFn(o.onEscape))
31
38
  o.onEscape = shift;
32
- if (o.labelOk === undefined)
33
- o.labelOk = labelOk;
34
- if (o.labelCancel === undefined)
35
- o.labelCancel = labelCancel;
36
- if (o.title === undefined)
37
- o.title = ucf(o.type);
39
+ if (!isFn(o.onCustom))
40
+ o.onCustom = () => undefined;
41
+ o.labelOk ??= defaults.labelOk;
42
+ o.labelCancel ??= defaults.labelCancel;
43
+ o.title ??= defaults.title;
44
+ o.iconFn ??= defaults.iconFn;
45
+ o.forceAsHtml ??= defaults.forceAsHtml;
38
46
  // variant defaults to info
39
47
  if (!['info', 'success', 'warn', 'error'].includes(o?.variant)) {
40
48
  o.variant = 'info';
41
49
  }
42
- if (o.iconFn === undefined)
43
- o.iconFn = true; // will use default
44
- // 3rd label may stay undefined
45
- if (!isFn(o.onCustom))
46
- o.onCustom = () => undefined;
50
+ if (defaults.class) {
51
+ o.class ??= {};
52
+ o.class = { ...defaults.class, ...o.class };
53
+ }
47
54
  //
48
55
  _stack.update((old) => [...old, o]);
49
56
  };
@@ -36,7 +36,15 @@ export interface NotiticationsCreateStoreOptions {
36
36
  defaultTtl: number;
37
37
  sortOrder?: NotificationsSortOrder;
38
38
  defaultIcons?: Record<NotificationType, () => string> | boolean;
39
- forceAsHtml: boolean | undefined;
39
+ forceAsHtml?: boolean | undefined;
40
+ class?: Partial<{
41
+ box: string;
42
+ count: string;
43
+ icon: string;
44
+ content: string;
45
+ button: string;
46
+ x: string;
47
+ }>;
40
48
  logger: (...v: any) => void;
41
49
  }
42
50
  export declare const NOTIFICATION_EVENT: {
@@ -61,6 +69,14 @@ export declare const createNotificationsStore: (initial?: NotificationCreatePara
61
69
  sortOrder?: NotificationsSortOrder | undefined;
62
70
  defaultIcons?: boolean | Record<string, () => string> | undefined;
63
71
  forceAsHtml?: boolean | undefined;
72
+ class?: Partial<{
73
+ box: string;
74
+ count: string;
75
+ icon: string;
76
+ content: string;
77
+ button: string;
78
+ x: string;
79
+ }> | undefined;
64
80
  logger?: ((...v: any) => void) | undefined;
65
81
  };
66
82
  EVENT: {
@@ -68,6 +68,10 @@ export const createNotificationsStore = (initial = [], opts = {}) => {
68
68
  notif.created = new Date(notif.created || Date.now());
69
69
  notif.count ??= 1;
70
70
  notif.forceAsHtml ??= opts.forceAsHtml;
71
+ if (opts.class) {
72
+ notif.class ??= {};
73
+ notif.class = { ...opts.class, ...notif.class };
74
+ }
71
75
  //
72
76
  if (notif.ttl === undefined)
73
77
  notif.ttl = opts.defaultTtl;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marianmeres/stuic",
3
- "version": "1.38.0",
3
+ "version": "1.39.0",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run package && node ./scripts/date.js",
@@ -66,7 +66,9 @@
66
66
  "@marianmeres/store": "^1.5.0",
67
67
  "@marianmeres/switch-store": "^1.3.1",
68
68
  "@marianmeres/ticker": "^1.5.0",
69
+ "dset": "^3.1.3",
69
70
  "esm-env": "^1.0.0",
71
+ "klona": "^2.0.6",
70
72
  "tailwind-merge": "^2.1.0"
71
73
  }
72
74
  }