@runwisp/ui 1.5.0 → 1.7.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.
- package/package.json +5 -7
- package/src/lib/actions/focusTrap.ts +3 -3
- package/src/lib/actions/fold-to-fit.test.ts +36 -0
- package/src/lib/actions/fold-to-fit.ts +89 -0
- package/src/lib/actions/modal-dialog.test.ts +47 -0
- package/src/lib/actions/modal-dialog.ts +48 -0
- package/src/lib/components/AccordionItem.svelte +16 -5
- package/src/lib/components/Badge.svelte +4 -25
- package/src/lib/components/Button.svelte +2 -9
- package/src/lib/components/CodeBlock.svelte +7 -6
- package/src/lib/components/DataGrid.svelte +5 -5
- package/src/lib/components/Drawer.svelte +22 -30
- package/src/lib/components/DurationInput.svelte +6 -25
- package/src/lib/components/FilterBar.svelte +3 -7
- package/src/lib/components/FilterPill.svelte +2 -2
- package/src/lib/components/FormField.svelte +1 -1
- package/src/lib/components/Link.svelte +9 -4
- package/src/lib/components/LogConsole.svelte +101 -424
- package/src/lib/components/Modal.svelte +7 -30
- package/src/lib/components/SearchInput.svelte +1 -1
- package/src/lib/components/Select.svelte +3 -2
- package/src/lib/components/Sparkline.svelte +2 -2
- package/src/lib/components/Spinner.svelte +10 -5
- package/src/lib/components/StatusDot.svelte +1 -1
- package/src/lib/components/StatusIndicator.svelte +37 -104
- package/src/lib/components/Tabs.svelte +15 -1
- package/src/lib/components/Tooltip.svelte +1 -1
- package/src/lib/components/dashboard/RunActions.svelte +156 -0
- package/src/lib/components/dashboard/RunConsoleFrame.svelte +319 -0
- package/src/lib/components/dashboard/RunDetailPanel.svelte +137 -725
- package/src/lib/components/dashboard/RunFacts.svelte +119 -0
- package/src/lib/components/dashboard/RunFilterChips.svelte +52 -0
- package/src/lib/components/dashboard/RunFilterPopover.svelte +9 -10
- package/src/lib/components/dashboard/RunHeaderLine.svelte +295 -0
- package/src/lib/components/dashboard/RunListSkeleton.svelte +43 -0
- package/src/lib/components/dashboard/RunRow.svelte +202 -0
- package/src/lib/components/dashboard/RunsList.svelte +267 -545
- package/src/lib/components/dashboard/bulk-selection.svelte.test.ts +42 -0
- package/src/lib/components/dashboard/bulk-selection.svelte.ts +50 -0
- package/src/lib/components/dashboard/cron-format.test.ts +10 -1
- package/src/lib/components/dashboard/cron-format.ts +7 -3
- package/src/lib/components/dashboard/run-filters.test.ts +62 -2
- package/src/lib/components/dashboard/run-filters.ts +104 -99
- package/src/lib/components/dashboard/run-helpers.test.ts +131 -12
- package/src/lib/components/dashboard/run-helpers.ts +150 -44
- package/src/lib/components/dashboard/status-config.ts +18 -0
- package/src/lib/components/dashboard/types.ts +6 -0
- package/src/lib/components/data-grid-selection.ts +2 -9
- package/src/lib/components/filter-spec.ts +3 -3
- package/src/lib/index.ts +13 -2
- package/src/lib/log-console/AnsiLine.svelte +12 -0
- package/src/lib/log-console/FrameHistoryBlock.svelte +57 -0
- package/src/lib/log-console/LogCache.svelte.ts +1 -1
- package/src/lib/log-console/LogConsoleFooter.svelte +88 -0
- package/src/lib/log-console/ansi.ts +1 -1
- package/src/lib/log-console/frame-history.svelte.test.ts +47 -0
- package/src/lib/log-console/frame-history.svelte.ts +71 -0
- package/src/lib/log-console/wrap-layout.svelte.test.ts +92 -0
- package/src/lib/log-console/wrap-layout.svelte.ts +188 -0
- package/src/lib/theme-tokens.css +21 -21
- package/src/lib/theme.css +13 -13
- package/src/lib/utils/format.test.ts +125 -3
- package/src/lib/utils/format.ts +101 -8
- package/src/lib/utils/toast.svelte.ts +2 -3
- package/src/lib/utils/typing-target.ts +10 -0
- package/src/stories/Accordion.stories.svelte +60 -1
- package/src/stories/CodeBlock.stories.svelte +13 -0
- package/src/stories/Link.stories.svelte +25 -1
- package/src/stories/LogConsole.stories.svelte +2 -2
- package/src/stories/Tabs.stories.svelte +17 -0
package/src/lib/theme-tokens.css
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* SPDX-FileCopyrightText: PoppyCake, s.r.o. */
|
|
2
2
|
/* SPDX-License-Identifier: Apache-2.0 */
|
|
3
3
|
|
|
4
|
-
/* RunWisp Design Tokens
|
|
4
|
+
/* RunWisp Design Tokens, plain CSS, no Tailwind directives.
|
|
5
5
|
*
|
|
6
6
|
* Single source of truth for the OKLch palette and the semantic `--rw-*`
|
|
7
7
|
* tokens that drive all apps:
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* The union selector covers both. Light mode is the default.
|
|
20
20
|
*
|
|
21
21
|
* Webfonts are @imported here (not in theme.css) so every consumer that reads
|
|
22
|
-
* these tokens also gets the faces they name
|
|
22
|
+
* these tokens also gets the faces they name, apps/docs imports this file
|
|
23
23
|
* alone. Both families ship in the binary; nothing is fetched from a CDN.
|
|
24
24
|
*/
|
|
25
25
|
|
|
@@ -30,13 +30,13 @@
|
|
|
30
30
|
@import "@fontsource-variable/geist-mono/index.css";
|
|
31
31
|
|
|
32
32
|
:root {
|
|
33
|
-
/* Typography
|
|
33
|
+
/* Typography, body sans for prose, mono for all chrome and identifiers.
|
|
34
34
|
* Geist Mono is variable (100–900), so heading weight 800 is a real cut. */
|
|
35
35
|
--rw-font-sans: "TASA Orbiter", system-ui, -apple-system, sans-serif;
|
|
36
36
|
--rw-font-mono:
|
|
37
37
|
"Geist Mono Variable", "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
38
38
|
|
|
39
|
-
/* Primary
|
|
39
|
+
/* Primary, Wisp Teal (brand = #0E7C86, the artifact's deep teal). Deeper
|
|
40
40
|
* and less cyan than Aurora (running/info) so the two stay distinct. */
|
|
41
41
|
--rw-color-wisp-50: oklch(0.97 0.02 205);
|
|
42
42
|
--rw-color-wisp-100: oklch(0.95 0.035 205);
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
--rw-color-wisp-900: oklch(0.3 0.048 208);
|
|
51
51
|
--rw-color-wisp-950: oklch(0.2 0.034 210);
|
|
52
52
|
|
|
53
|
-
/* Accent
|
|
53
|
+
/* Accent, Aurora Teal (running status = #13A0A8, a cyan-leaning teal) */
|
|
54
54
|
--rw-color-aurora-50: oklch(0.97 0.02 192);
|
|
55
55
|
--rw-color-aurora-100: oklch(0.94 0.045 192);
|
|
56
56
|
--rw-color-aurora-200: oklch(0.88 0.075 190);
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
--rw-color-aurora-800: oklch(0.35 0.07 192);
|
|
63
63
|
--rw-color-aurora-900: oklch(0.28 0.055 192);
|
|
64
64
|
|
|
65
|
-
/* Mist
|
|
65
|
+
/* Mist, teal-gray neutrals (the runbook's #F3F6F6 / #E0E7E7 /
|
|
66
66
|
* #14262A / #0C1719 family). No purple tint; hue ~195-205, low chroma,
|
|
67
67
|
* so bg-mist-* utilities agree with the new teal-black surfaces. The light
|
|
68
68
|
* end stays near-neutral to match the desaturated canvas. */
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
--rw-color-mist-900: oklch(0.266 0.025 204); /* ≈ #16292B */
|
|
79
79
|
--rw-color-mist-950: oklch(0.195 0.016 208); /* ≈ #0C1719 */
|
|
80
80
|
|
|
81
|
-
/* Success
|
|
81
|
+
/* Success, Field Green (success status = #1F9D57, a true grass green) */
|
|
82
82
|
--rw-color-success-50: oklch(0.97 0.02 150);
|
|
83
83
|
--rw-color-success-100: oklch(0.94 0.04 150);
|
|
84
84
|
--rw-color-success-200: oklch(0.88 0.07 150);
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
--rw-color-success-600: oklch(0.5 0.13 150);
|
|
89
89
|
--rw-color-success-700: oklch(0.42 0.11 150);
|
|
90
90
|
|
|
91
|
-
/* Danger
|
|
91
|
+
/* Danger, Signal Red (failed status = #D6453D, a warm tomato red) */
|
|
92
92
|
--rw-color-danger-50: oklch(0.97 0.016 27);
|
|
93
93
|
--rw-color-danger-100: oklch(0.94 0.03 27);
|
|
94
94
|
--rw-color-danger-200: oklch(0.88 0.06 27);
|
|
@@ -98,7 +98,7 @@
|
|
|
98
98
|
--rw-color-danger-600: oklch(0.5 0.17 27);
|
|
99
99
|
--rw-color-danger-700: oklch(0.42 0.145 27);
|
|
100
100
|
|
|
101
|
-
/* Warning
|
|
101
|
+
/* Warning, Ember Amber (stopped status = #D98324, a warm orange-amber) */
|
|
102
102
|
--rw-color-warning-50: oklch(0.97 0.03 78);
|
|
103
103
|
--rw-color-warning-100: oklch(0.94 0.07 74);
|
|
104
104
|
--rw-color-warning-200: oklch(0.9 0.11 72);
|
|
@@ -108,7 +108,7 @@
|
|
|
108
108
|
--rw-color-warning-600: oklch(0.6 0.14 62);
|
|
109
109
|
--rw-color-warning-700: oklch(0.52 0.12 60);
|
|
110
110
|
|
|
111
|
-
/* ANSI console palette
|
|
111
|
+
/* ANSI console palette, 16-color map for the log console, tuned for
|
|
112
112
|
* its always-dark surface (no .dark override needed). Hues follow the
|
|
113
113
|
* semantic scales: red→danger, green→success, yellow→warning,
|
|
114
114
|
* blue→wisp, cyan→aurora, grays→mist. */
|
|
@@ -129,11 +129,11 @@
|
|
|
129
129
|
--rw-ansi-bright-cyan: var(--rw-color-aurora-300);
|
|
130
130
|
--rw-ansi-bright-white: var(--rw-color-mist-50);
|
|
131
131
|
|
|
132
|
-
/* Fixed-dark sibling palettes
|
|
132
|
+
/* Fixed-dark sibling palettes, the `--rw-con-*` log console (a "black box"
|
|
133
133
|
* device) and the `--rw-term-*`/`--rw-syn-*` website terminal surfaces both
|
|
134
134
|
* keep their own dark palette in BOTH themes; they never flip light/dark. */
|
|
135
135
|
|
|
136
|
-
/* Console device surface
|
|
136
|
+
/* Console device surface, the log console instrument.
|
|
137
137
|
* Exact values from the approved execution-detail design. */
|
|
138
138
|
--rw-con-bg: #0e141b; /* body / gutter backing */
|
|
139
139
|
--rw-con-panel: #11181f; /* toolbar + footer chrome */
|
|
@@ -141,7 +141,7 @@
|
|
|
141
141
|
--rw-con-dim: #6c7d8c; /* footer + muted readouts */
|
|
142
142
|
--rw-con-gutter: #3c4a58; /* line numbers + sentinel rule */
|
|
143
143
|
|
|
144
|
-
/* Terminal surface
|
|
144
|
+
/* Terminal surface, always dark in both themes (website --term-* set) */
|
|
145
145
|
--rw-term: #0a1116;
|
|
146
146
|
--rw-term-2: #0d151b;
|
|
147
147
|
--rw-term-line: #1d2932;
|
|
@@ -161,7 +161,7 @@
|
|
|
161
161
|
--rw-syn-punc: #9aa7b0;
|
|
162
162
|
--rw-syn-fn: #2fd4dd;
|
|
163
163
|
|
|
164
|
-
/* Elevation
|
|
164
|
+
/* Elevation, light-mode drop shadows; flipped to `none` in dark so the
|
|
165
165
|
* UI reads as borders-only there. */
|
|
166
166
|
--rw-shadow-xs: 0 1px 2px rgba(16, 41, 43, 0.04);
|
|
167
167
|
--rw-shadow-sm: 0 1px 2px rgba(16, 41, 43, 0.04), 0 12px 28px -20px rgba(16, 41, 43, 0.22);
|
|
@@ -169,7 +169,7 @@
|
|
|
169
169
|
--rw-shadow-lg: 0 1px 2px rgba(16, 41, 43, 0.06), 0 30px 60px -28px rgba(16, 41, 43, 0.45);
|
|
170
170
|
--rw-shadow-xl: 0 1px 2px rgba(16, 41, 43, 0.06), 0 40px 80px -30px rgba(16, 41, 43, 0.5);
|
|
171
171
|
|
|
172
|
-
/* Light-mode semantic tokens (default)
|
|
172
|
+
/* Light-mode semantic tokens (default), runbook palette (exact hex).
|
|
173
173
|
*
|
|
174
174
|
* The canvas carries only a whisper of the brand teal. The website can
|
|
175
175
|
* afford a minty `--ground` because dark panes and terminals cover most
|
|
@@ -223,7 +223,7 @@
|
|
|
223
223
|
--rw-warning-soft: rgba(196, 120, 26, 0.1);
|
|
224
224
|
--rw-warning-soft-text: #c4781a;
|
|
225
225
|
--rw-warning-soft-border: rgba(196, 120, 26, 0.25);
|
|
226
|
-
/* Info
|
|
226
|
+
/* Info, matches primary teal */
|
|
227
227
|
--rw-info: #15a0a8;
|
|
228
228
|
--rw-info-hover: #0e7c86;
|
|
229
229
|
--rw-on-info: #ffffff;
|
|
@@ -235,7 +235,7 @@
|
|
|
235
235
|
--rw-glass-blur: blur(12px);
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
-
/* Dark-mode semantic tokens
|
|
238
|
+
/* Dark-mode semantic tokens, `.dark` class for Svelte apps, `[data-theme="dark"]`
|
|
239
239
|
* attribute for Starlight. Both selectors apply the same token set. */
|
|
240
240
|
:root.dark,
|
|
241
241
|
:root[data-theme="dark"] {
|
|
@@ -254,7 +254,7 @@
|
|
|
254
254
|
--rw-outline-faint: #1d2932;
|
|
255
255
|
--rw-ring: #2fd4dd;
|
|
256
256
|
--rw-backdrop: rgba(4, 10, 12, 0.7);
|
|
257
|
-
/* Primary
|
|
257
|
+
/* Primary, bright teal in dark, matches info */
|
|
258
258
|
--rw-primary: #2fd4dd;
|
|
259
259
|
--rw-primary-hover: #5fe3ea;
|
|
260
260
|
--rw-primary-active: #5fe3ea;
|
|
@@ -284,7 +284,7 @@
|
|
|
284
284
|
--rw-warning-soft: rgba(224, 165, 46, 0.14);
|
|
285
285
|
--rw-warning-soft-text: #e0a52e;
|
|
286
286
|
--rw-warning-soft-border: rgba(224, 165, 46, 0.28);
|
|
287
|
-
/* Info
|
|
287
|
+
/* Info, bright teal in dark */
|
|
288
288
|
--rw-info: #2fd4dd;
|
|
289
289
|
--rw-info-hover: #5fe3ea;
|
|
290
290
|
--rw-on-info: #04181a;
|
|
@@ -293,7 +293,7 @@
|
|
|
293
293
|
--rw-info-soft-border: rgba(47, 212, 221, 0.28);
|
|
294
294
|
/* Glass */
|
|
295
295
|
--rw-glass: rgba(8, 15, 17, 0.9);
|
|
296
|
-
/* Elevation
|
|
296
|
+
/* Elevation, borders-only in dark, no drop shadow */
|
|
297
297
|
--rw-shadow-xs: none;
|
|
298
298
|
--rw-shadow-sm: none;
|
|
299
299
|
--rw-shadow-md: none;
|
|
@@ -301,7 +301,7 @@
|
|
|
301
301
|
--rw-shadow-xl: none;
|
|
302
302
|
}
|
|
303
303
|
|
|
304
|
-
/* Platform polish
|
|
304
|
+
/* Platform polish, focus ring, text selection, scrollbar. Lifted from
|
|
305
305
|
* theme.css so apps/docs (no Tailwind) gets the same treatment as the
|
|
306
306
|
* Svelte apps. */
|
|
307
307
|
|
package/src/lib/theme.css
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* Copyright (c) PoppyCake, s.r.o. SPDX-License-Identifier: Apache-2.0 */
|
|
2
2
|
|
|
3
|
-
/* RunWisp Design System
|
|
3
|
+
/* RunWisp Design System, Tailwind v4 entrypoint.
|
|
4
4
|
*
|
|
5
5
|
* Raw OKLch palette + semantic tokens live in ./theme-tokens.css (plain CSS),
|
|
6
6
|
* so apps/docs (Starlight, no Tailwind pipeline) can consume the same source.
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
* side for good; below it the operator can fold the first two away. */
|
|
24
24
|
--breakpoint-3xl: 100rem;
|
|
25
25
|
|
|
26
|
-
/* Palette aliases
|
|
26
|
+
/* Palette aliases, Tailwind utilities (bg-wisp-500, text-mist-900, …)
|
|
27
27
|
* resolve through to --rw-color-* declared in theme-tokens.css. */
|
|
28
28
|
--color-wisp-50: var(--rw-color-wisp-50);
|
|
29
29
|
--color-wisp-100: var(--rw-color-wisp-100);
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
--color-warning-600: var(--rw-color-warning-600);
|
|
88
88
|
--color-warning-700: var(--rw-color-warning-700);
|
|
89
89
|
|
|
90
|
-
/* Typography
|
|
90
|
+
/* Typography, stacks and @font-face live in theme-tokens.css so the
|
|
91
91
|
* non-Tailwind consumers (apps/docs) share one definition. */
|
|
92
92
|
--font-sans: var(--rw-font-sans);
|
|
93
93
|
--font-mono: var(--rw-font-mono);
|
|
@@ -126,18 +126,18 @@
|
|
|
126
126
|
--spacing-20: 5rem;
|
|
127
127
|
--spacing-24: 6rem;
|
|
128
128
|
|
|
129
|
-
/* Border radius
|
|
129
|
+
/* Border radius, runbook scale (small radii are signature). lg/xl/2xl/3xl
|
|
130
130
|
* remain for legacy call sites but should not be used going forward. */
|
|
131
131
|
--radius-none: 0;
|
|
132
|
-
--radius-sm: 0.1875rem; /* 3px
|
|
133
|
-
--radius-md: 0.25rem; /* 4px
|
|
132
|
+
--radius-sm: 0.1875rem; /* 3px, controls */
|
|
133
|
+
--radius-md: 0.25rem; /* 4px, panels / cards */
|
|
134
134
|
--radius-lg: 0.5rem;
|
|
135
135
|
--radius-xl: 0.75rem;
|
|
136
136
|
--radius-2xl: 1rem;
|
|
137
137
|
--radius-3xl: 1.5rem;
|
|
138
138
|
--radius-full: 9999px;
|
|
139
139
|
|
|
140
|
-
/* Shadows
|
|
140
|
+
/* Shadows, mapped to the flip tokens in theme-tokens.css so every
|
|
141
141
|
* shadow-* utility resolves to `none` in dark (borders-only look). */
|
|
142
142
|
--shadow-xs: var(--rw-shadow-xs);
|
|
143
143
|
--shadow-sm: var(--rw-shadow-sm);
|
|
@@ -146,7 +146,7 @@
|
|
|
146
146
|
--shadow-xl: var(--rw-shadow-xl);
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
-
/* Semantic Design Tokens
|
|
149
|
+
/* Semantic Design Tokens, Tailwind utility aliases.
|
|
150
150
|
* Components use `bg-surface`, `text-primary`, etc.; the values live in
|
|
151
151
|
* theme-tokens.css under the --rw-* namespace and flip on light/dark. */
|
|
152
152
|
|
|
@@ -206,7 +206,7 @@
|
|
|
206
206
|
--color-warning-soft-border: var(--rw-warning-soft-border);
|
|
207
207
|
--color-info-soft-border: var(--rw-info-soft-border);
|
|
208
208
|
|
|
209
|
-
/* Terminal surface
|
|
209
|
+
/* Terminal surface, fixed dark in both themes */
|
|
210
210
|
--color-term: var(--rw-term);
|
|
211
211
|
--color-term-2: var(--rw-term-2);
|
|
212
212
|
--color-term-line: var(--rw-term-line);
|
|
@@ -228,8 +228,8 @@
|
|
|
228
228
|
|
|
229
229
|
/* Motion. Deliberately minimal: hover, focus and state changes are
|
|
230
230
|
* instant, so there is no scale of durations to pick from. The few things
|
|
231
|
-
* that still move
|
|
232
|
-
* height, a progress bar's width
|
|
231
|
+
* that still move, a drawer sliding, a toggle knob, an accordion's
|
|
232
|
+
* height, a progress bar's width, set their own timing inline. */
|
|
233
233
|
--ease-out: cubic-bezier(0, 0, 0.2, 1);
|
|
234
234
|
}
|
|
235
235
|
|
|
@@ -255,7 +255,7 @@ body {
|
|
|
255
255
|
color: var(--rw-on-surface);
|
|
256
256
|
}
|
|
257
257
|
|
|
258
|
-
/* Headings are mono chrome
|
|
258
|
+
/* Headings are mono chrome, the runbook voice. Unlayered, so it beats the
|
|
259
259
|
weight/leading/tracking utilities on a raw <h1>-<h3>: every heading reads the
|
|
260
260
|
same. The Heading component opts out (data-rw-heading) and carries this look
|
|
261
261
|
in its own classes, so its props are the source of truth. :is()/:where()
|
|
@@ -295,7 +295,7 @@ body {
|
|
|
295
295
|
backdrop-filter: var(--rw-glass-blur);
|
|
296
296
|
}
|
|
297
297
|
|
|
298
|
-
/* Legacy aliases
|
|
298
|
+
/* Legacy aliases, prefer .rw-bg-glass which adapts to light/dark */
|
|
299
299
|
.rw-bg-glass-dark {
|
|
300
300
|
background: var(--rw-glass);
|
|
301
301
|
backdrop-filter: var(--rw-glass-blur);
|
|
@@ -8,6 +8,9 @@ import {
|
|
|
8
8
|
formatClockTime,
|
|
9
9
|
formatDayMonth,
|
|
10
10
|
formatDuration,
|
|
11
|
+
formatDurationExact,
|
|
12
|
+
parseDuration,
|
|
13
|
+
formatRelativeCompact,
|
|
11
14
|
formatRelativeTime,
|
|
12
15
|
formatRelativeTimeWithAbsolute,
|
|
13
16
|
formatTimeHM,
|
|
@@ -86,7 +89,7 @@ describe("formatRelativeTimeWithAbsolute", () => {
|
|
|
86
89
|
it("uses time-only format (HH:MM) for dates within the same day", () => {
|
|
87
90
|
const recent = new Date(Date.now() - 30 * 60_000).toISOString();
|
|
88
91
|
const r = formatRelativeTimeWithAbsolute(recent);
|
|
89
|
-
// Same-day branch produces `relative (HH:MM)
|
|
92
|
+
// Same-day branch produces `relative (HH:MM)`, assert on the colon
|
|
90
93
|
// that only appears inside the time format.
|
|
91
94
|
expect(r).toMatch(/\(\d{1,2}:\d{2}\)$/);
|
|
92
95
|
});
|
|
@@ -122,22 +125,95 @@ describe("formatRelativeTimeWithAbsolute", () => {
|
|
|
122
125
|
});
|
|
123
126
|
|
|
124
127
|
describe("formatRelativeTime", () => {
|
|
128
|
+
const now = new Date("2024-01-10T12:00:00Z");
|
|
129
|
+
const at = (seconds: number): Date => new Date(now.getTime() + seconds * 1000);
|
|
130
|
+
|
|
125
131
|
it("advances as the supplied now advances", () => {
|
|
126
132
|
const date = new Date("2024-01-01T12:00:00Z");
|
|
127
133
|
expect(formatRelativeTime(date, new Date("2024-01-01T14:00:00Z"))).toBe("2 hours ago");
|
|
128
134
|
expect(formatRelativeTime(date, new Date("2024-01-01T15:00:00Z"))).toBe("3 hours ago");
|
|
129
135
|
});
|
|
136
|
+
|
|
137
|
+
it("always shows a number by default", () => {
|
|
138
|
+
expect(formatRelativeTime(at(0), now)).toBe("in 0 seconds");
|
|
139
|
+
expect(formatRelativeTime(at(-86_400), now)).toBe("1 day ago");
|
|
140
|
+
expect(formatRelativeTime(at(86_400), now)).toBe("in 1 day");
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it.each([
|
|
144
|
+
[0, "now"],
|
|
145
|
+
[-16, "16 seconds ago"],
|
|
146
|
+
[16, "in 16 seconds"],
|
|
147
|
+
[-60, "1 minute ago"],
|
|
148
|
+
[-5 * 60, "5 minutes ago"],
|
|
149
|
+
[-3600, "1 hour ago"],
|
|
150
|
+
[2 * 3600, "in 2 hours"],
|
|
151
|
+
[-86_400, "yesterday"],
|
|
152
|
+
[86_400, "tomorrow"],
|
|
153
|
+
[-3 * 86_400, "3 days ago"],
|
|
154
|
+
])("numeric auto: %is from now reads %s", (seconds, expected) => {
|
|
155
|
+
expect(formatRelativeTime(at(seconds), now, { numeric: "auto" })).toBe(expected);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("accepts a timestamp, an ISO string or a Date", () => {
|
|
159
|
+
const date = at(-120);
|
|
160
|
+
expect(formatRelativeTime(date.getTime(), now)).toBe("2 minutes ago");
|
|
161
|
+
expect(formatRelativeTime(date.toISOString(), now)).toBe("2 minutes ago");
|
|
162
|
+
expect(formatRelativeTime(date, now)).toBe("2 minutes ago");
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("throws on an invalid date", () => {
|
|
166
|
+
expect(() => formatRelativeTime("not a date", now)).toThrow(RangeError);
|
|
167
|
+
expect(() => formatRelativeTime("not a date", now, { numeric: "auto" })).toThrow(
|
|
168
|
+
RangeError,
|
|
169
|
+
);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
describe("formatRelativeCompact", () => {
|
|
174
|
+
const now = new Date("2024-01-10T12:00:00Z");
|
|
175
|
+
const ago = (seconds: number): number => now.getTime() - seconds * 1000;
|
|
176
|
+
|
|
177
|
+
it.each([
|
|
178
|
+
[0, "0s"],
|
|
179
|
+
[16.9, "16s"],
|
|
180
|
+
[59, "59s"],
|
|
181
|
+
[60, "1m"],
|
|
182
|
+
[3 * 60 + 59, "3m"],
|
|
183
|
+
[59 * 60, "59m"],
|
|
184
|
+
[3600, "1h"],
|
|
185
|
+
[23 * 3600 + 3599, "23h"],
|
|
186
|
+
[86_400, "1d"],
|
|
187
|
+
[45 * 86_400, "45d"],
|
|
188
|
+
[400 * 86_400, "400d"],
|
|
189
|
+
])("%is ago reads %s", (seconds, expected) => {
|
|
190
|
+
expect(formatRelativeCompact(ago(seconds), now)).toBe(expected);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it("clamps a future date to 0s", () => {
|
|
194
|
+
expect(formatRelativeCompact(ago(-90), now)).toBe("0s");
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it("accepts an ISO string or a Date", () => {
|
|
198
|
+
expect(formatRelativeCompact(new Date(ago(180)).toISOString(), now)).toBe("3m");
|
|
199
|
+
expect(formatRelativeCompact(new Date(ago(180)), now)).toBe("3m");
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("does not guard an invalid date", () => {
|
|
203
|
+
// Same as the station helper it replaces; callers pass server timestamps.
|
|
204
|
+
expect(formatRelativeCompact("not a date", now)).toBe("NaNd");
|
|
205
|
+
});
|
|
130
206
|
});
|
|
131
207
|
|
|
132
208
|
describe("formatClockTime", () => {
|
|
133
209
|
it("renders three numeric groups (hours, minutes, seconds)", () => {
|
|
134
|
-
// 24-hour h:m:s
|
|
210
|
+
// 24-hour h:m:s, the seconds component is what sets it apart from formatTimeHM.
|
|
135
211
|
expect(numericGroups(formatClockTime("2026-06-22T17:15:02Z"))).toBe(3);
|
|
136
212
|
});
|
|
137
213
|
});
|
|
138
214
|
|
|
139
215
|
describe("formatTimeHM", () => {
|
|
140
|
-
it("renders two numeric groups (hours, minutes)
|
|
216
|
+
it("renders two numeric groups (hours, minutes), no seconds", () => {
|
|
141
217
|
expect(numericGroups(formatTimeHM("2026-06-22T17:15:02Z"))).toBe(2);
|
|
142
218
|
});
|
|
143
219
|
});
|
|
@@ -156,3 +232,49 @@ describe("formatDayMonth", () => {
|
|
|
156
232
|
expect(r).not.toContain("2026");
|
|
157
233
|
});
|
|
158
234
|
});
|
|
235
|
+
|
|
236
|
+
describe("parseDuration", () => {
|
|
237
|
+
it("reads the placeholder's own format", () => {
|
|
238
|
+
expect(parseDuration("5m 30s")).toBe(330_000);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it("reads compact, fractional and sub-second forms", () => {
|
|
242
|
+
expect(parseDuration("1h30m")).toBe(5_400_000);
|
|
243
|
+
expect(parseDuration("1.5h")).toBe(5_400_000);
|
|
244
|
+
expect(parseDuration("250ms")).toBe(250);
|
|
245
|
+
expect(parseDuration("2d")).toBe(172_800_000);
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it("reads what the ms package did", () => {
|
|
249
|
+
expect(parseDuration("500")).toBe(500);
|
|
250
|
+
expect(parseDuration("1w")).toBe(604_800_000);
|
|
251
|
+
expect(parseDuration("1y")).toBe(31_557_600_000);
|
|
252
|
+
expect(parseDuration("2 hours")).toBe(7_200_000);
|
|
253
|
+
expect(parseDuration("30 sec")).toBe(30_000);
|
|
254
|
+
expect(parseDuration("5 minutes")).toBe(300_000);
|
|
255
|
+
expect(parseDuration("5M")).toBe(300_000);
|
|
256
|
+
expect(parseDuration(".5h")).toBe(1_800_000);
|
|
257
|
+
expect(parseDuration(" 1 Hour 30 mins ")).toBe(5_400_000);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it("rejects text that isn't number+unit throughout", () => {
|
|
261
|
+
expect(parseDuration("")).toBeNull();
|
|
262
|
+
expect(parseDuration("5x")).toBeNull();
|
|
263
|
+
expect(parseDuration("5m abc")).toBeNull();
|
|
264
|
+
expect(parseDuration("5 30s")).toBeNull();
|
|
265
|
+
expect(parseDuration("1.5.5")).toBeNull();
|
|
266
|
+
expect(parseDuration("9".repeat(101))).toBeNull();
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
describe("formatDurationExact", () => {
|
|
271
|
+
it("keeps every non-zero unit instead of rounding", () => {
|
|
272
|
+
expect(formatDurationExact(330_000)).toBe("5m 30s");
|
|
273
|
+
expect(formatDurationExact(3_930_000)).toBe("1h 5m 30s");
|
|
274
|
+
expect(formatDurationExact(0)).toBe("0ms");
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it("round-trips through parseDuration", () => {
|
|
278
|
+
expect(parseDuration(formatDurationExact(90_061_001))).toBe(90_061_001);
|
|
279
|
+
});
|
|
280
|
+
});
|
package/src/lib/utils/format.ts
CHANGED
|
@@ -13,18 +13,48 @@ const RELATIVE_DIVISIONS: [amount: number, unit: Intl.RelativeTimeFormatUnit][]
|
|
|
13
13
|
[Number.POSITIVE_INFINITY, "years"],
|
|
14
14
|
];
|
|
15
15
|
|
|
16
|
-
const relativeTime =
|
|
16
|
+
const relativeTime = {
|
|
17
|
+
always: new Intl.RelativeTimeFormat(undefined, { numeric: "always" }),
|
|
18
|
+
auto: new Intl.RelativeTimeFormat(undefined, { numeric: "auto" }),
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export interface RelativeTimeOptions {
|
|
22
|
+
/** `"auto"` words the near units: "now", "yesterday", "tomorrow", "last week". Default `"always"`. */
|
|
23
|
+
numeric?: Intl.RelativeTimeFormatNumeric;
|
|
24
|
+
}
|
|
17
25
|
|
|
18
26
|
/** "N units ago" / "in N units" for `date` relative to `now`. */
|
|
19
|
-
export function formatRelativeTime(
|
|
27
|
+
export function formatRelativeTime(
|
|
28
|
+
date: string | number | Date,
|
|
29
|
+
now: Date = new Date(),
|
|
30
|
+
{ numeric = "always" }: RelativeTimeOptions = {},
|
|
31
|
+
): string {
|
|
32
|
+
const format = relativeTime[numeric];
|
|
20
33
|
let delta = (new Date(date).getTime() - now.getTime()) / 1000;
|
|
21
34
|
for (const [amount, unit] of RELATIVE_DIVISIONS) {
|
|
22
35
|
if (Math.abs(delta) < amount) {
|
|
23
|
-
return
|
|
36
|
+
return format.format(Math.round(delta), unit);
|
|
24
37
|
}
|
|
25
38
|
delta /= amount;
|
|
26
39
|
}
|
|
27
|
-
return
|
|
40
|
+
return format.format(Math.round(delta), "years");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Compact age of a past `date` for dense rows and live labels: "45s", "5m",
|
|
45
|
+
* "3h", "2d". Each unit floors; a future date reads "0s".
|
|
46
|
+
*/
|
|
47
|
+
export function formatRelativeCompact(
|
|
48
|
+
date: string | number | Date,
|
|
49
|
+
now: Date = new Date(),
|
|
50
|
+
): string {
|
|
51
|
+
const seconds = Math.max(0, Math.floor((now.getTime() - new Date(date).getTime()) / 1000));
|
|
52
|
+
if (seconds < 60) return `${String(seconds)}s`;
|
|
53
|
+
const minutes = Math.floor(seconds / 60);
|
|
54
|
+
if (minutes < 60) return `${String(minutes)}m`;
|
|
55
|
+
const hours = Math.floor(minutes / 60);
|
|
56
|
+
if (hours < 24) return `${String(hours)}h`;
|
|
57
|
+
return `${String(Math.floor(hours / 24))}d`;
|
|
28
58
|
}
|
|
29
59
|
|
|
30
60
|
/** A locale date/time formatter for one fixed option set, built once. */
|
|
@@ -41,7 +71,7 @@ export const formatDateTime = dateFormatter({
|
|
|
41
71
|
minute: "2-digit",
|
|
42
72
|
});
|
|
43
73
|
|
|
44
|
-
/** Wall-clock time of day, seconds included, 24-hour
|
|
74
|
+
/** Wall-clock time of day, seconds included, 24-hour, e.g. "17:15:02". */
|
|
45
75
|
export const formatClockTime = dateFormatter({
|
|
46
76
|
hour: "2-digit",
|
|
47
77
|
minute: "2-digit",
|
|
@@ -49,17 +79,17 @@ export const formatClockTime = dateFormatter({
|
|
|
49
79
|
hour12: false,
|
|
50
80
|
});
|
|
51
81
|
|
|
52
|
-
/** Calendar date without the time
|
|
82
|
+
/** Calendar date without the time, e.g. "22 Jun 2026". */
|
|
53
83
|
export const formatCalendarDate = dateFormatter({
|
|
54
84
|
year: "numeric",
|
|
55
85
|
month: "short",
|
|
56
86
|
day: "numeric",
|
|
57
87
|
});
|
|
58
88
|
|
|
59
|
-
/** Time of day, no seconds, 24-hour
|
|
89
|
+
/** Time of day, no seconds, 24-hour, e.g. "17:15". */
|
|
60
90
|
export const formatTimeHM = dateFormatter({ hour: "2-digit", minute: "2-digit", hour12: false });
|
|
61
91
|
|
|
62
|
-
/** Day and month, no year
|
|
92
|
+
/** Day and month, no year, e.g. "22 Jun". */
|
|
63
93
|
export const formatDayMonth = dateFormatter({ month: "short", day: "numeric" });
|
|
64
94
|
|
|
65
95
|
export const formatFullDateTime = dateFormatter({
|
|
@@ -108,3 +138,66 @@ export function formatDuration(ms: number): string {
|
|
|
108
138
|
const remM = m % 60;
|
|
109
139
|
return remM > 0 ? String(h) + "h " + String(remM) + "m" : String(h) + "h";
|
|
110
140
|
}
|
|
141
|
+
|
|
142
|
+
// Largest first, so formatDurationExact can peel units off greedily.
|
|
143
|
+
const DURATION_UNITS: [unit: string, ms: number][] = [
|
|
144
|
+
["d", 86_400_000],
|
|
145
|
+
["h", 3_600_000],
|
|
146
|
+
["m", 60_000],
|
|
147
|
+
["s", 1000],
|
|
148
|
+
["ms", 1],
|
|
149
|
+
];
|
|
150
|
+
|
|
151
|
+
// Every unit name parseDuration takes, in ms. The `ms` package's set.
|
|
152
|
+
const UNIT_ALIASES: [ms: number, names: string[]][] = [
|
|
153
|
+
[1, ["ms", "msec", "msecs", "millisecond", "milliseconds"]],
|
|
154
|
+
[1000, ["s", "sec", "secs", "second", "seconds"]],
|
|
155
|
+
[60_000, ["m", "min", "mins", "minute", "minutes"]],
|
|
156
|
+
[3_600_000, ["h", "hr", "hrs", "hour", "hours"]],
|
|
157
|
+
[86_400_000, ["d", "day", "days"]],
|
|
158
|
+
[604_800_000, ["w", "week", "weeks"]],
|
|
159
|
+
[31_557_600_000, ["y", "yr", "yrs", "year", "years"]],
|
|
160
|
+
];
|
|
161
|
+
const UNIT_MS = new Map(UNIT_ALIASES.flatMap(([size, names]) => names.map((n) => [n, size])));
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* parseDuration reads a duration into milliseconds. It takes what the `ms`
|
|
165
|
+
* package does ("500" as milliseconds, ".5h", "2 hours", "30 sec", "1w", "1y",
|
|
166
|
+
* any case) plus compound forms: "5m 30s", "1h30m". Returns null when any part
|
|
167
|
+
* isn't a number with a unit (only a lone number may go without one).
|
|
168
|
+
*/
|
|
169
|
+
export function parseDuration(text: string): number | null {
|
|
170
|
+
const s = text.trim().toLowerCase();
|
|
171
|
+
// Bounded like `ms`, which also keeps the number pattern's backtracking cheap.
|
|
172
|
+
if (!s || s.length > 100) return null;
|
|
173
|
+
const segment = /(-?\d*\.?\d+)\s*([a-z]*)\s*/y;
|
|
174
|
+
let total = 0;
|
|
175
|
+
let segments = 0;
|
|
176
|
+
let bare = false;
|
|
177
|
+
while (segment.lastIndex < s.length) {
|
|
178
|
+
const match = segment.exec(s);
|
|
179
|
+
if (!match) return null;
|
|
180
|
+
const [, amount = "", unit = ""] = match;
|
|
181
|
+
const size = unit ? UNIT_MS.get(unit) : 1;
|
|
182
|
+
if (size === undefined) return null;
|
|
183
|
+
bare ||= !unit;
|
|
184
|
+
total += Number(amount) * size;
|
|
185
|
+
segments++;
|
|
186
|
+
}
|
|
187
|
+
if (bare && segments > 1) return null;
|
|
188
|
+
return Math.round(total);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** formatDurationExact renders milliseconds as "1h 5m 30s", keeping every non-zero unit. */
|
|
192
|
+
export function formatDurationExact(ms: number): string {
|
|
193
|
+
const parts: string[] = [];
|
|
194
|
+
let rest = Math.round(ms);
|
|
195
|
+
for (const [unit, size] of DURATION_UNITS) {
|
|
196
|
+
const amount = Math.floor(rest / size);
|
|
197
|
+
if (amount > 0) {
|
|
198
|
+
parts.push(String(amount) + unit);
|
|
199
|
+
rest -= amount * size;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return parts.length > 0 ? parts.join(" ") : "0ms";
|
|
203
|
+
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: PoppyCake, s.r.o.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { generateUlid } from "@runwisp/common";
|
|
5
|
-
|
|
6
4
|
type ToastType = "success" | "error" | "warning" | "info";
|
|
7
5
|
|
|
8
6
|
interface ToastAction {
|
|
@@ -28,6 +26,7 @@ const DEFAULT_DURATION = 5000;
|
|
|
28
26
|
class ToastStore {
|
|
29
27
|
items = $state<Toast[]>([]);
|
|
30
28
|
private readonly timers = new Map<string, ReturnType<typeof setTimeout>>();
|
|
29
|
+
private nextId = 0;
|
|
31
30
|
|
|
32
31
|
add(type: ToastType, message: string, opts: ToastOptions = {}): string {
|
|
33
32
|
const duration = opts.duration ?? DEFAULT_DURATION;
|
|
@@ -37,7 +36,7 @@ class ToastStore {
|
|
|
37
36
|
return existing.id;
|
|
38
37
|
}
|
|
39
38
|
|
|
40
|
-
const id =
|
|
39
|
+
const id = `toast-${String(++this.nextId)}`;
|
|
41
40
|
const next: Toast = { id, type, message, duration };
|
|
42
41
|
if (opts.action) next.action = opts.action;
|
|
43
42
|
this.items = [...this.items, next];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: PoppyCake, s.r.o.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/** True when a keyboard event came from a field the user is typing into. */
|
|
5
|
+
export function isTypingTarget(target: EventTarget | null): boolean {
|
|
6
|
+
return (
|
|
7
|
+
target instanceof HTMLElement &&
|
|
8
|
+
(target.tagName === "INPUT" || target.tagName === "TEXTAREA" || target.isContentEditable)
|
|
9
|
+
);
|
|
10
|
+
}
|