dssoca 0.5.0 → 0.9.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.
Files changed (56) hide show
  1. package/README.md +39 -13
  2. package/dist/components/Accordion.svelte +297 -0
  3. package/dist/components/Accordion.svelte.d.ts +51 -0
  4. package/dist/components/Badge.svelte +113 -18
  5. package/dist/components/Badge.svelte.d.ts +28 -2
  6. package/dist/components/BottomNav.svelte +254 -0
  7. package/dist/components/BottomNav.svelte.d.ts +32 -0
  8. package/dist/components/Button.svelte +147 -10
  9. package/dist/components/Button.svelte.d.ts +21 -4
  10. package/dist/components/Card.svelte +173 -8
  11. package/dist/components/Card.svelte.d.ts +16 -1
  12. package/dist/components/Container.svelte +55 -0
  13. package/dist/components/Container.svelte.d.ts +16 -0
  14. package/dist/components/EmptyState.svelte +91 -9
  15. package/dist/components/EmptyState.svelte.d.ts +20 -3
  16. package/dist/components/Heading.svelte +83 -0
  17. package/dist/components/Heading.svelte.d.ts +17 -0
  18. package/dist/components/Icon.svelte +199 -24
  19. package/dist/components/Icon.svelte.d.ts +70 -2
  20. package/dist/components/Image.svelte +428 -0
  21. package/dist/components/Image.svelte.d.ts +49 -0
  22. package/dist/components/Input.svelte +173 -39
  23. package/dist/components/Input.svelte.d.ts +22 -0
  24. package/dist/components/Link.svelte +183 -0
  25. package/dist/components/Link.svelte.d.ts +29 -0
  26. package/dist/components/LogStream.svelte +403 -47
  27. package/dist/components/LogStream.svelte.d.ts +35 -7
  28. package/dist/components/Menu.svelte +408 -0
  29. package/dist/components/Menu.svelte.d.ts +66 -0
  30. package/dist/components/MetricTile.svelte +124 -12
  31. package/dist/components/MetricTile.svelte.d.ts +20 -0
  32. package/dist/components/SegmentedControl.svelte +220 -0
  33. package/dist/components/SegmentedControl.svelte.d.ts +37 -0
  34. package/dist/components/ServiceCard.svelte +226 -30
  35. package/dist/components/ServiceCard.svelte.d.ts +13 -1
  36. package/dist/components/Sidebar.svelte +377 -40
  37. package/dist/components/Sidebar.svelte.d.ts +18 -7
  38. package/dist/components/Sparkline.svelte +198 -13
  39. package/dist/components/Sparkline.svelte.d.ts +20 -1
  40. package/dist/components/Spinner.svelte +124 -0
  41. package/dist/components/Spinner.svelte.d.ts +74 -0
  42. package/dist/components/Textarea.svelte +214 -0
  43. package/dist/components/Textarea.svelte.d.ts +38 -0
  44. package/dist/components/Toaster.svelte +209 -12
  45. package/dist/components/Toaster.svelte.d.ts +3 -0
  46. package/dist/components/Topbar.svelte +293 -42
  47. package/dist/components/Topbar.svelte.d.ts +48 -1
  48. package/dist/dssoca.config.d.ts +1 -1
  49. package/dist/dssoca.config.js +10 -0
  50. package/dist/index.d.ts +16 -3
  51. package/dist/index.js +18 -2
  52. package/dist/theme.css +406 -24
  53. package/dist/toast.svelte.d.ts +49 -5
  54. package/dist/toast.svelte.js +165 -9
  55. package/dist/tokens.css +597 -0
  56. package/package.json +25 -4
@@ -1,32 +1,188 @@
1
- const DEFAULT_TIMEOUT = 4000;
1
+ /** Default auto-dismiss per kind. Errors linger; loading is sticky. */
2
+ const DEFAULT_TIMEOUT = {
3
+ success: 4000,
4
+ info: 4000,
5
+ error: 7000,
6
+ loading: 0, // sticky until updated/dismissed
7
+ };
8
+ /** Toasts carrying an action default to sticky so the action stays reachable. */
9
+ const ACTION_TIMEOUT = 0;
10
+ /** Treat <= 0 or non-finite as sticky (never auto-dismiss). */
11
+ function isSticky(timeout) {
12
+ return !(timeout > 0) || !Number.isFinite(timeout);
13
+ }
14
+ const hasWindow = typeof window !== 'undefined';
15
+ /**
16
+ * Per-toast auto-dismiss controller. Tracks remaining time so the timer can be
17
+ * paused (on hover/focus) and resumed without losing or resetting the budget.
18
+ */
19
+ class ToastTimer {
20
+ #fire;
21
+ #remaining;
22
+ #startedAt = 0;
23
+ #handle = null;
24
+ constructor(timeout, fire) {
25
+ this.#fire = fire;
26
+ this.#remaining = timeout;
27
+ this.resume();
28
+ }
29
+ get sticky() {
30
+ return isSticky(this.#remaining);
31
+ }
32
+ resume() {
33
+ if (this.#handle !== null || this.sticky || !hasWindow)
34
+ return;
35
+ this.#startedAt = Date.now();
36
+ this.#handle = setTimeout(this.#fire, this.#remaining);
37
+ }
38
+ pause() {
39
+ if (this.#handle === null)
40
+ return;
41
+ clearTimeout(this.#handle);
42
+ this.#handle = null;
43
+ this.#remaining -= Date.now() - this.#startedAt;
44
+ }
45
+ /** Re-arm with a fresh budget (used by `update`). */
46
+ reset(timeout) {
47
+ this.cancel();
48
+ this.#remaining = timeout;
49
+ this.resume();
50
+ }
51
+ cancel() {
52
+ if (this.#handle !== null)
53
+ clearTimeout(this.#handle);
54
+ this.#handle = null;
55
+ }
56
+ }
2
57
  /**
3
58
  * Module-singleton toast store (Svelte 5 runes). One instance is shared by
4
59
  * every consumer of the package, so `toast.success(...)` from anywhere shows
5
60
  * in the single <Toaster /> mounted at the app root.
61
+ *
62
+ * Visible toasts are capped at `max`; overflow waits in a private queue and is
63
+ * promoted (FIFO) whenever a visible slot frees up on dismiss.
6
64
  */
7
65
  class ToastStore {
66
+ /** The currently VISIBLE toasts (capped at `max`). */
8
67
  items = $state([]);
68
+ /** Visible-stack cap; extra pushes queue until a slot frees. */
69
+ max = $state(3);
9
70
  #seq = 0;
10
- push(kind, message, timeout = DEFAULT_TIMEOUT) {
71
+ #queue = [];
72
+ #timers = new Map();
73
+ #resolveTimeout(kind, opts) {
74
+ if (opts?.timeout !== undefined)
75
+ return opts.timeout;
76
+ if (opts?.action)
77
+ return ACTION_TIMEOUT;
78
+ return DEFAULT_TIMEOUT[kind];
79
+ }
80
+ push(kind, message, opts) {
81
+ // Back-compat: the old signature accepted a bare `timeout` number.
82
+ const o = typeof opts === 'number' ? { timeout: opts } : opts;
11
83
  const id = ++this.#seq;
12
- this.items.push({ id, kind, message });
13
- if (timeout > 0 && typeof window !== 'undefined') {
14
- setTimeout(() => this.dismiss(id), timeout);
84
+ const toast = {
85
+ id,
86
+ kind,
87
+ message,
88
+ timeout: this.#resolveTimeout(kind, o),
89
+ action: o?.action,
90
+ };
91
+ if (this.items.length < this.max) {
92
+ this.#show(toast);
93
+ }
94
+ else {
95
+ this.#queue.push(toast);
15
96
  }
16
97
  return id;
17
98
  }
99
+ #show(toast) {
100
+ this.items.push(toast);
101
+ this.#arm(toast);
102
+ }
103
+ #arm(toast) {
104
+ this.#timers.get(toast.id)?.cancel();
105
+ if (isSticky(toast.timeout)) {
106
+ this.#timers.delete(toast.id);
107
+ return;
108
+ }
109
+ this.#timers.set(toast.id, new ToastTimer(toast.timeout, () => this.dismiss(toast.id)));
110
+ }
111
+ /** Patch a live (or queued) toast in place; re-arms its timer. Returns success. */
112
+ update(id, patch) {
113
+ const live = this.items.find((t) => t.id === id);
114
+ const target = live ?? this.#queue.find((t) => t.id === id);
115
+ if (!target)
116
+ return false;
117
+ if (patch.kind !== undefined)
118
+ target.kind = patch.kind;
119
+ if (patch.message !== undefined)
120
+ target.message = patch.message;
121
+ if ('action' in patch)
122
+ target.action = patch.action;
123
+ if (patch.timeout !== undefined)
124
+ target.timeout = patch.timeout;
125
+ else if (patch.kind !== undefined)
126
+ target.timeout = DEFAULT_TIMEOUT[patch.kind];
127
+ if (live)
128
+ this.#arm(live);
129
+ return true;
130
+ }
131
+ /** Pause a visible toast's auto-dismiss timer (hover/focus). */
132
+ pause(id) {
133
+ this.#timers.get(id)?.pause();
134
+ }
135
+ /** Resume a paused timer (pointer/focus leave). */
136
+ resume(id) {
137
+ this.#timers.get(id)?.resume();
138
+ }
18
139
  dismiss(id) {
140
+ this.#timers.get(id)?.cancel();
141
+ this.#timers.delete(id);
19
142
  const i = this.items.findIndex((t) => t.id === id);
20
- if (i !== -1)
143
+ if (i !== -1) {
21
144
  this.items.splice(i, 1);
145
+ this.#promote();
146
+ return;
147
+ }
148
+ // Might still be waiting in the queue.
149
+ const qi = this.#queue.findIndex((t) => t.id === id);
150
+ if (qi !== -1)
151
+ this.#queue.splice(qi, 1);
152
+ }
153
+ /** Promote the next queued toast into a freed visible slot. */
154
+ #promote() {
155
+ while (this.items.length < this.max && this.#queue.length > 0) {
156
+ this.#show(this.#queue.shift());
157
+ }
22
158
  }
23
159
  clear() {
160
+ for (const t of this.#timers.values())
161
+ t.cancel();
162
+ this.#timers.clear();
163
+ this.#queue = [];
24
164
  this.items = [];
25
165
  }
26
166
  }
27
167
  export const toasts = new ToastStore();
28
168
  export const toast = {
29
- success: (message, timeout) => toasts.push('success', message, timeout),
30
- error: (message, timeout) => toasts.push('error', message, timeout),
31
- info: (message, timeout) => toasts.push('info', message, timeout)
169
+ success: (message, opts) => toasts.push('success', message, opts),
170
+ error: (message, opts) => toasts.push('error', message, opts),
171
+ info: (message, opts) => toasts.push('info', message, opts),
172
+ loading: (message, opts) => toasts.push('loading', message, opts),
173
+ /**
174
+ * Push a sticky `loading` toast, then update it to success/error when the
175
+ * promise settles. Returns the same promise so callers can keep chaining.
176
+ */
177
+ promise(p, messages) {
178
+ const id = toasts.push('loading', messages.loading, { timeout: 0 });
179
+ p.then((value) => {
180
+ const msg = typeof messages.success === 'function' ? messages.success(value) : messages.success;
181
+ toasts.update(id, { kind: 'success', message: msg });
182
+ }, (err) => {
183
+ const msg = typeof messages.error === 'function' ? messages.error(err) : messages.error;
184
+ toasts.update(id, { kind: 'error', message: msg });
185
+ });
186
+ return p;
187
+ },
32
188
  };