@txstate-mws/svelte-components 1.6.4 → 1.6.6

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.
@@ -44,8 +44,8 @@ export function glue(el, { target, align = 'auto', cover = false, gap = 0, adjus
44
44
  requestAnimationFrame(() => {
45
45
  el.style.top = `${rect.top + (cover ? 0 : targetHeight) + gap}px`;
46
46
  el.style.left = `${rect.left}px`;
47
- el.style.bottom = '';
48
- el.style.right = '';
47
+ el.style.removeProperty('bottom');
48
+ el.style.removeProperty('right');
49
49
  adjustParentHeight();
50
50
  });
51
51
  valign = 'bottom';
@@ -54,8 +54,8 @@ export function glue(el, { target, align = 'auto', cover = false, gap = 0, adjus
54
54
  else if (autoalign === 'bottomright') {
55
55
  requestAnimationFrame(() => {
56
56
  el.style.top = `${rect.top + (cover ? 0 : targetHeight) + gap}px`;
57
- el.style.left = '';
58
- el.style.bottom = '';
57
+ el.style.removeProperty('left');
58
+ el.style.removeProperty('bottom');
59
59
  el.style.right = `${rect.right}px`;
60
60
  adjustParentHeight();
61
61
  });
@@ -64,10 +64,10 @@ export function glue(el, { target, align = 'auto', cover = false, gap = 0, adjus
64
64
  }
65
65
  else if (autoalign === 'topleft') {
66
66
  requestAnimationFrame(() => {
67
- el.style.top = '';
67
+ el.style.removeProperty('top');
68
68
  el.style.left = `${rect.left}px`;
69
69
  el.style.bottom = `${rect.bottom + (cover ? 0 : targetHeight) + gap}px`;
70
- el.style.right = '';
70
+ el.style.removeProperty('right');
71
71
  adjustParentHeight();
72
72
  });
73
73
  valign = 'top';
@@ -75,8 +75,8 @@ export function glue(el, { target, align = 'auto', cover = false, gap = 0, adjus
75
75
  }
76
76
  else if (autoalign === 'topright') {
77
77
  requestAnimationFrame(() => {
78
- el.style.top = '';
79
- el.style.left = '';
78
+ el.style.removeProperty('top');
79
+ el.style.removeProperty('left');
80
80
  el.style.bottom = `${rect.bottom + (cover ? 0 : targetHeight) + gap}px`;
81
81
  el.style.right = `${rect.right}px`;
82
82
  adjustParentHeight();
@@ -130,9 +130,9 @@ function isFixedContainer(el) {
130
130
  return true; // A filter value other than none
131
131
  if (['layout', 'paint', 'strict', 'content'].includes(css.getPropertyValue('contain')))
132
132
  return true; // A contain value of layout, paint, strict or content (e.g. contain: paint;)
133
- if (css.getPropertyValue('container-type') !== 'normal')
133
+ if ('container-type' in css && css.getPropertyValue('container-type') !== 'normal')
134
134
  return true; // A container-type value other than normal
135
- if (css.getPropertyValue('backdrop-filter') !== 'none')
135
+ if ('backdrop-filter' in css && css.getPropertyValue('backdrop-filter') !== 'none')
136
136
  return true; // A backdrop-filter other than none (e.g. backdrop-filter: blur(10px);)
137
137
  return false;
138
138
  }
@@ -5,7 +5,7 @@ export interface Toast {
5
5
  type?: 'error' | 'warning' | 'info' | 'success';
6
6
  /**
7
7
  * how long the message should appear on screen in milliseconds
8
- * default 15 seconds
8
+ * default 8 seconds for errors and warnings, 5 seconds for success and info
9
9
  * use Number.MAX_SAFE_INTEGER for permanent
10
10
  */
11
11
  ttlMs?: number;
@@ -15,10 +15,15 @@ export interface ToastStorage extends Required<Toast> {
15
15
  id: string;
16
16
  /** when the toast was created, so we know when it expires */
17
17
  stamp: Date;
18
+ /** True if auto-expiration has been suspended (e.g. user is hovering mouse over the toast) */
19
+ suspended: boolean;
18
20
  }
19
21
  export declare class ToastStore extends Store<ToastStorage[]> {
22
+ timers: Record<string, number>;
20
23
  add(msg: string, type?: Toast['type'], ttlMs?: number): void;
21
24
  close(id: string): void;
25
+ suspend(id: string): void;
26
+ resume(id: string): void;
22
27
  clean(): void;
23
28
  }
24
29
  export declare const toasts: ToastStore;
@@ -1,23 +1,34 @@
1
1
  import { Store } from '@txstate-mws/svelte-store';
2
2
  import { randomid } from 'txstate-utils';
3
3
  export class ToastStore extends Store {
4
+ timers = {};
4
5
  add(msg, type, ttlMs) {
6
+ const resolvedType = type ?? 'error';
7
+ const id = randomid();
5
8
  const stored = {
6
- id: randomid(),
9
+ id,
7
10
  stamp: new Date(),
8
11
  message: msg,
9
- type: type ?? 'error',
10
- ttlMs: ttlMs ?? 15000
12
+ type: resolvedType,
13
+ suspended: false,
14
+ ttlMs: ttlMs ?? (['error', 'warning'].includes(resolvedType) ? 8000 : 5000)
11
15
  };
12
16
  this.update(v => [...v.filter(t => t.message !== stored.message), stored]);
13
- setTimeout(() => { this.clean(); }, stored.ttlMs);
17
+ this.timers[id] = setTimeout(() => { this.clean(); }, stored.ttlMs);
14
18
  }
15
19
  close(id) {
16
20
  this.update(v => v.filter(t => t.id !== id));
17
21
  }
22
+ suspend(id) {
23
+ this.update(v => v.map(t => t.id !== id ? t : { ...t, suspended: true }));
24
+ }
25
+ resume(id) {
26
+ this.update(v => v.map(t => t.id !== id ? t : { ...t, suspended: false }));
27
+ this.clean();
28
+ }
18
29
  clean() {
19
30
  const now = new Date().getTime();
20
- this.update(v => v.filter(t => now - t.stamp.getTime() < t.ttlMs));
31
+ this.update(v => v.filter(t => t.suspended || (now - t.stamp.getTime() < t.ttlMs)));
21
32
  }
22
33
  }
23
34
  export const toasts = new ToastStore([]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@txstate-mws/svelte-components",
3
- "version": "1.6.4",
3
+ "version": "1.6.6",
4
4
  "description": "Svelte components that are generically useful.",
5
5
  "scripts": {
6
6
  "prepublishOnly": "svelte-package",