@zovaris/sephiro 0.14.0 → 1.0.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/dist/{Chart-CDJ3a_FJ.js → Chart-C3wQzNKf.js} +41 -22
- package/dist/Chart-C3wQzNKf.js.map +1 -0
- package/dist/{Table-BxURefYb.js → Table-Db4HQGlm.js} +129 -30
- package/dist/Table-Db4HQGlm.js.map +1 -0
- package/dist/Toast-CGHWMJFI.js +328 -0
- package/dist/Toast-CGHWMJFI.js.map +1 -0
- package/dist/activity-heatmap.d.ts +68 -0
- package/dist/activity-heatmap.d.ts.map +1 -0
- package/dist/activity-heatmap.js +239 -0
- package/dist/activity-heatmap.js.map +1 -0
- package/dist/alert-dialog.d.ts +25 -0
- package/dist/alert-dialog.d.ts.map +1 -0
- package/dist/alert-dialog.js +44 -0
- package/dist/alert-dialog.js.map +1 -0
- package/dist/budget-summary.d.ts +44 -0
- package/dist/budget-summary.d.ts.map +1 -0
- package/dist/budget-summary.js +137 -0
- package/dist/budget-summary.js.map +1 -0
- package/dist/carousel.js +8 -5
- package/dist/carousel.js.map +1 -1
- package/dist/change-timeline.d.ts +43 -0
- package/dist/change-timeline.d.ts.map +1 -0
- package/dist/change-timeline.js +395 -0
- package/dist/change-timeline.js.map +1 -0
- package/dist/chart.d.ts +3 -1
- package/dist/chart.d.ts.map +1 -1
- package/dist/chart.js +1 -1
- package/dist/chat-scroller.js +4 -0
- package/dist/chat-scroller.js.map +1 -1
- package/dist/checkbox-group.d.ts +28 -0
- package/dist/checkbox-group.d.ts.map +1 -0
- package/dist/checkbox-group.js +87 -0
- package/dist/checkbox-group.js.map +1 -0
- package/dist/combobox.js +1 -1
- package/dist/combobox.js.map +1 -1
- package/dist/components.css +7743 -2734
- package/dist/context-menu.js +1 -1
- package/dist/context-menu.js.map +1 -1
- package/dist/context-meter.d.ts +23 -0
- package/dist/context-meter.d.ts.map +1 -0
- package/dist/context-meter.js +65 -0
- package/dist/context-meter.js.map +1 -0
- package/dist/conversation-list.d.ts +25 -0
- package/dist/conversation-list.d.ts.map +1 -0
- package/dist/conversation-list.js +99 -0
- package/dist/conversation-list.js.map +1 -0
- package/dist/copy-button.d.ts +53 -0
- package/dist/copy-button.d.ts.map +1 -0
- package/dist/copy-button.js +102 -0
- package/dist/copy-button.js.map +1 -0
- package/dist/css/activity-heatmap.css +2 -0
- package/dist/css/alert-dialog.css +8 -0
- package/dist/css/attachment.css +5 -4
- package/dist/css/badge.css +1 -1
- package/dist/css/breadcrumb.css +5 -4
- package/dist/css/budget-summary.css +74 -0
- package/dist/css/button.css +1 -1
- package/dist/css/card.css +1 -1
- package/dist/css/carousel.css +17 -10
- package/dist/css/change-timeline.css +85 -0
- package/dist/css/chart.css +5 -4
- package/dist/css/chat-input.css +5 -4
- package/dist/css/checkbox-group.css +3 -0
- package/dist/css/checkbox.css +1 -1
- package/dist/css/combobox.css +1 -73
- package/dist/css/command-palette.css +10 -9
- package/dist/css/context-meter.css +2 -0
- package/dist/css/conversation-list.css +14 -0
- package/dist/css/copy-button.css +16 -0
- package/dist/css/date-field.css +69 -0
- package/dist/css/date-time-field.css +68 -0
- package/dist/css/decay-chart.css +12 -0
- package/dist/css/dialog.css +1 -1
- package/dist/css/donut-chart.css +12 -0
- package/dist/css/dot-matrix-chart.css +12 -0
- package/dist/css/drag-to-confirm.css +45 -0
- package/dist/css/drawer.css +1 -1
- package/dist/css/empty-state.css +4 -3
- package/dist/css/event-sparkline.css +74 -0
- package/dist/css/field.css +1 -1
- package/dist/css/follow-up-suggestions.css +1 -0
- package/dist/css/gauge.css +12 -0
- package/dist/css/hover-card.css +1 -1
- package/dist/css/icon-button.css +1 -1
- package/dist/css/image-preview.css +2 -0
- package/dist/css/link.css +14 -0
- package/dist/css/menu.css +1 -73
- package/dist/css/message-actions.css +20 -0
- package/dist/css/meter.css +10 -0
- package/dist/css/metric-card.css +77 -0
- package/dist/css/middle-truncate.css +20 -0
- package/dist/css/model-picker.css +44 -0
- package/dist/css/notice.css +1 -1
- package/dist/css/otp-input.css +1 -1
- package/dist/css/overflow-list.css +1 -73
- package/dist/css/pagination.css +1 -1
- package/dist/css/password-field.css +13 -0
- package/dist/css/plan-card.css +4 -3
- package/dist/css/popconfirm.css +44 -0
- package/dist/css/popover.css +1 -1
- package/dist/css/question-card.css +4 -3
- package/dist/css/radial-progress.css +1 -0
- package/dist/css/range-slider.css +1 -0
- package/dist/css/reasoning-steps.css +5 -4
- package/dist/css/run-matrix.css +13 -0
- package/dist/css/schedule-list.css +74 -0
- package/dist/css/score-band-chart.css +85 -0
- package/dist/css/search-field.css +13 -0
- package/dist/css/select.css +5 -4
- package/dist/css/shortcut-sheet.css +3 -0
- package/dist/css/sidebar.css +2 -4
- package/dist/css/slider.css +1 -1
- package/dist/css/sources-panel.css +2 -0
- package/dist/css/sparkline.css +74 -0
- package/dist/css/spinner.css +27 -1
- package/dist/css/split-button.css +45 -0
- package/dist/css/table.css +3 -1
- package/dist/css/tag-input.css +1 -0
- package/dist/css/task-list.css +5 -4
- package/dist/css/terminal.css +15 -0
- package/dist/css/theme-asterism.css +1 -1
- package/dist/css/theme-curie.css +1 -1
- package/dist/css/theme-dark.css +1 -1
- package/dist/css/theme-default.css +1 -1
- package/dist/css/theme-fizza.css +1 -1
- package/dist/css/theme-light.css +1 -1
- package/dist/css/theme-pulso.css +1 -1
- package/dist/css/time-field.css +1 -0
- package/dist/css/timeline.css +5 -4
- package/dist/css/toast.css +2 -1
- package/dist/css/tooltip.css +1 -1
- package/dist/css/tree-view.css +1 -0
- package/dist/css/virtual-list.css +1 -0
- package/dist/curve-9YxRv2_K.js +77 -0
- package/dist/curve-9YxRv2_K.js.map +1 -0
- package/dist/date-field.d.ts +21 -0
- package/dist/date-field.d.ts.map +1 -0
- package/dist/date-field.js +93 -0
- package/dist/date-field.js.map +1 -0
- package/dist/date-time-field.d.ts +27 -0
- package/dist/date-time-field.d.ts.map +1 -0
- package/dist/date-time-field.js +66 -0
- package/dist/date-time-field.js.map +1 -0
- package/dist/decay-chart.d.ts +108 -0
- package/dist/decay-chart.d.ts.map +1 -0
- package/dist/decay-chart.js +277 -0
- package/dist/decay-chart.js.map +1 -0
- package/dist/dialog.d.ts +5 -1
- package/dist/dialog.d.ts.map +1 -1
- package/dist/dialog.js +3 -3
- package/dist/dialog.js.map +1 -1
- package/dist/donut-chart.d.ts +26 -0
- package/dist/donut-chart.d.ts.map +1 -0
- package/dist/donut-chart.js +126 -0
- package/dist/donut-chart.js.map +1 -0
- package/dist/dot-matrix-chart.d.ts +42 -0
- package/dist/dot-matrix-chart.d.ts.map +1 -0
- package/dist/dot-matrix-chart.js +237 -0
- package/dist/dot-matrix-chart.js.map +1 -0
- package/dist/drag-to-confirm.d.ts +25 -0
- package/dist/drag-to-confirm.d.ts.map +1 -0
- package/dist/drag-to-confirm.js +203 -0
- package/dist/drag-to-confirm.js.map +1 -0
- package/dist/drawer.d.ts +3 -1
- package/dist/drawer.d.ts.map +1 -1
- package/dist/drawer.js +74 -2
- package/dist/drawer.js.map +1 -1
- package/dist/event-sparkline.d.ts +37 -0
- package/dist/event-sparkline.d.ts.map +1 -0
- package/dist/event-sparkline.js +159 -0
- package/dist/event-sparkline.js.map +1 -0
- package/dist/field.js +4 -4
- package/dist/field.js.map +1 -1
- package/dist/follow-up-suggestions.d.ts +19 -0
- package/dist/follow-up-suggestions.d.ts.map +1 -0
- package/dist/follow-up-suggestions.js +50 -0
- package/dist/follow-up-suggestions.js.map +1 -0
- package/dist/gauge.d.ts +34 -0
- package/dist/gauge.d.ts.map +1 -0
- package/dist/gauge.js +179 -0
- package/dist/gauge.js.map +1 -0
- package/dist/hover-card.js +1 -1
- package/dist/hover-card.js.map +1 -1
- package/dist/image-preview.d.ts +19 -0
- package/dist/image-preview.d.ts.map +1 -0
- package/dist/image-preview.js +52 -0
- package/dist/image-preview.js.map +1 -0
- package/dist/{index-Dw2Vi3H2.d.ts → index-CdTFUcZD.d.ts} +11 -2
- package/dist/index-CdTFUcZD.d.ts.map +1 -0
- package/dist/index-DRXUXEa8.d.ts +80 -0
- package/dist/index-DRXUXEa8.d.ts.map +1 -0
- package/dist/index.css +7778 -2762
- package/dist/index.d.ts +43 -3
- package/dist/index.js +44 -4
- package/dist/link.d.ts +15 -0
- package/dist/link.d.ts.map +1 -0
- package/dist/link.js +30 -0
- package/dist/link.js.map +1 -0
- package/dist/menu.js +1 -1
- package/dist/menu.js.map +1 -1
- package/dist/message-actions.d.ts +28 -0
- package/dist/message-actions.d.ts.map +1 -0
- package/dist/message-actions.js +115 -0
- package/dist/message-actions.js.map +1 -0
- package/dist/meter.d.ts +21 -0
- package/dist/meter.d.ts.map +1 -0
- package/dist/meter.js +42 -0
- package/dist/meter.js.map +1 -0
- package/dist/metric-card.d.ts +29 -0
- package/dist/metric-card.d.ts.map +1 -0
- package/dist/metric-card.js +68 -0
- package/dist/metric-card.js.map +1 -0
- package/dist/middle-truncate.d.ts +29 -0
- package/dist/middle-truncate.d.ts.map +1 -0
- package/dist/middle-truncate.js +52 -0
- package/dist/middle-truncate.js.map +1 -0
- package/dist/model-picker.d.ts +25 -0
- package/dist/model-picker.d.ts.map +1 -0
- package/dist/model-picker.js +101 -0
- package/dist/model-picker.js.map +1 -0
- package/dist/password-field.d.ts +18 -0
- package/dist/password-field.d.ts.map +1 -0
- package/dist/password-field.js +73 -0
- package/dist/password-field.js.map +1 -0
- package/dist/popconfirm.d.ts +22 -0
- package/dist/popconfirm.d.ts.map +1 -0
- package/dist/popconfirm.js +64 -0
- package/dist/popconfirm.js.map +1 -0
- package/dist/popover.js +1 -1
- package/dist/popover.js.map +1 -1
- package/dist/radial-progress.d.ts +13 -0
- package/dist/radial-progress.d.ts.map +1 -0
- package/dist/radial-progress.js +50 -0
- package/dist/radial-progress.js.map +1 -0
- package/dist/range-slider.d.ts +24 -0
- package/dist/range-slider.d.ts.map +1 -0
- package/dist/range-slider.js +84 -0
- package/dist/range-slider.js.map +1 -0
- package/dist/run-matrix.d.ts +32 -0
- package/dist/run-matrix.d.ts.map +1 -0
- package/dist/run-matrix.js +244 -0
- package/dist/run-matrix.js.map +1 -0
- package/dist/schedule-list.d.ts +29 -0
- package/dist/schedule-list.d.ts.map +1 -0
- package/dist/schedule-list.js +72 -0
- package/dist/schedule-list.js.map +1 -0
- package/dist/score-band-chart.d.ts +41 -0
- package/dist/score-band-chart.d.ts.map +1 -0
- package/dist/score-band-chart.js +159 -0
- package/dist/score-band-chart.js.map +1 -0
- package/dist/search-field.d.ts +20 -0
- package/dist/search-field.d.ts.map +1 -0
- package/dist/search-field.js +95 -0
- package/dist/search-field.js.map +1 -0
- package/dist/select.d.ts +4 -1
- package/dist/select.d.ts.map +1 -1
- package/dist/select.js +4 -2
- package/dist/select.js.map +1 -1
- package/dist/shortcut-sheet.d.ts +27 -0
- package/dist/shortcut-sheet.d.ts.map +1 -0
- package/dist/shortcut-sheet.js +43 -0
- package/dist/shortcut-sheet.js.map +1 -0
- package/dist/sources-panel.d.ts +14 -0
- package/dist/sources-panel.d.ts.map +1 -0
- package/dist/sources-panel.js +93 -0
- package/dist/sources-panel.js.map +1 -0
- package/dist/sparkline.d.ts +21 -0
- package/dist/sparkline.d.ts.map +1 -0
- package/dist/sparkline.js +64 -0
- package/dist/sparkline.js.map +1 -0
- package/dist/spinner.d.ts +2 -1
- package/dist/spinner.d.ts.map +1 -1
- package/dist/spinner.js +3 -3
- package/dist/spinner.js.map +1 -1
- package/dist/split-button.d.ts +27 -0
- package/dist/split-button.d.ts.map +1 -0
- package/dist/split-button.js +51 -0
- package/dist/split-button.js.map +1 -0
- package/dist/table.d.ts +1 -1
- package/dist/table.js +1 -1
- package/dist/tag-input.d.ts +17 -0
- package/dist/tag-input.d.ts.map +1 -0
- package/dist/tag-input.js +85 -0
- package/dist/tag-input.js.map +1 -0
- package/dist/terminal.d.ts +37 -0
- package/dist/terminal.d.ts.map +1 -0
- package/dist/terminal.js +86 -0
- package/dist/terminal.js.map +1 -0
- package/dist/themes.css +47 -28
- package/dist/time-field.d.ts +46 -0
- package/dist/time-field.d.ts.map +1 -0
- package/dist/time-field.js +227 -0
- package/dist/time-field.js.map +1 -0
- package/dist/toast.d.ts +2 -24
- package/dist/toast.js +2 -76
- package/dist/virtual-list.d.ts +17 -0
- package/dist/virtual-list.d.ts.map +1 -0
- package/dist/virtual-list.js +79 -0
- package/dist/virtual-list.js.map +1 -0
- package/package.json +161 -1
- package/dist/Chart-CDJ3a_FJ.js.map +0 -1
- package/dist/Table-BxURefYb.js.map +0 -1
- package/dist/index-Dw2Vi3H2.d.ts.map +0 -1
- package/dist/toast.d.ts.map +0 -1
- package/dist/toast.js.map +0 -1
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import { t as cn } from "./cn-M4U2-Tak.js";
|
|
2
|
+
import { t as node } from "./node-Dr67KnBr.js";
|
|
3
|
+
import { Spinner } from "./spinner.js";
|
|
4
|
+
import { useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore } from "react";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import { CheckIcon, InfoIcon, WarningIcon, XIcon } from "@phosphor-icons/react";
|
|
7
|
+
import { createPortal } from "react-dom";
|
|
8
|
+
import { Toaster, toast } from "sonner";
|
|
9
|
+
//#region src/molecules/Toast/spring.tsx
|
|
10
|
+
const DEFAULT_DURATION = 5e3;
|
|
11
|
+
const EXIT_MS = 180;
|
|
12
|
+
/**
|
|
13
|
+
* One toast owns the screen, so a new call morphs the live record instead of
|
|
14
|
+
* adding a second card. A new call *replaces* the content: a field it does not
|
|
15
|
+
* send is gone, not inherited from whatever toast came before. Only `update`
|
|
16
|
+
* patches, keeping the fields it leaves out.
|
|
17
|
+
*/
|
|
18
|
+
function mergeSpringToast(current, patch, seq, mode = "replace") {
|
|
19
|
+
const previous = mode === "patch" ? current : null;
|
|
20
|
+
const tone = patch.tone ?? previous?.tone ?? "neutral";
|
|
21
|
+
const title = patch.title ?? previous?.title ?? "";
|
|
22
|
+
const description = patch.description !== void 0 ? patch.description : previous?.description;
|
|
23
|
+
const action = patch.action === null ? void 0 : patch.action ?? previous?.action;
|
|
24
|
+
const progress = patch.progress === null ? void 0 : patch.progress ?? previous?.progress;
|
|
25
|
+
const meta = patch.meta !== void 0 ? patch.meta : previous?.meta;
|
|
26
|
+
const duration = patch.duration ?? previous?.duration ?? DEFAULT_DURATION;
|
|
27
|
+
const repeat = current !== null && title === current.title && tone === current.tone && description === current.description && action === current.action && progress === current.progress;
|
|
28
|
+
return {
|
|
29
|
+
id: mode === "patch" ? current?.id ?? patch.id ?? `sph-spring-toast-${seq}` : patch.id ?? `sph-spring-toast-${seq}`,
|
|
30
|
+
title,
|
|
31
|
+
description,
|
|
32
|
+
tone,
|
|
33
|
+
action,
|
|
34
|
+
progress,
|
|
35
|
+
meta,
|
|
36
|
+
duration,
|
|
37
|
+
count: repeat ? current.count + 1 : 1,
|
|
38
|
+
seq
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/** Errors, loading and toasts with an action wait for the reader. */
|
|
42
|
+
function springDuration(record) {
|
|
43
|
+
if (record.tone === "error" || record.tone === "loading" || record.action) return 0;
|
|
44
|
+
return record.duration;
|
|
45
|
+
}
|
|
46
|
+
let live = null;
|
|
47
|
+
let seq = 0;
|
|
48
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
49
|
+
const emit = () => {
|
|
50
|
+
for (const listener of listeners) listener();
|
|
51
|
+
};
|
|
52
|
+
const subscribe = (listener) => {
|
|
53
|
+
listeners.add(listener);
|
|
54
|
+
return () => {
|
|
55
|
+
listeners.delete(listener);
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
const snapshot = () => live;
|
|
59
|
+
const serverSnapshot = () => null;
|
|
60
|
+
function show(title, options = {}) {
|
|
61
|
+
seq += 1;
|
|
62
|
+
live = mergeSpringToast(live, {
|
|
63
|
+
...options,
|
|
64
|
+
title
|
|
65
|
+
}, seq, "replace");
|
|
66
|
+
emit();
|
|
67
|
+
return live.id;
|
|
68
|
+
}
|
|
69
|
+
const springToast = Object.assign(show, {
|
|
70
|
+
success: (title, options) => show(title, {
|
|
71
|
+
...options,
|
|
72
|
+
tone: "success"
|
|
73
|
+
}),
|
|
74
|
+
error: (title, options) => show(title, {
|
|
75
|
+
...options,
|
|
76
|
+
tone: "error"
|
|
77
|
+
}),
|
|
78
|
+
warning: (title, options) => show(title, {
|
|
79
|
+
...options,
|
|
80
|
+
tone: "warning"
|
|
81
|
+
}),
|
|
82
|
+
info: (title, options) => show(title, {
|
|
83
|
+
...options,
|
|
84
|
+
tone: "neutral"
|
|
85
|
+
}),
|
|
86
|
+
loading: (title, options) => show(title, {
|
|
87
|
+
...options,
|
|
88
|
+
tone: "loading"
|
|
89
|
+
}),
|
|
90
|
+
update(id, patch) {
|
|
91
|
+
if (!live || live.id !== id) return;
|
|
92
|
+
seq += 1;
|
|
93
|
+
live = mergeSpringToast(live, patch, seq, "patch");
|
|
94
|
+
emit();
|
|
95
|
+
},
|
|
96
|
+
dismiss(id) {
|
|
97
|
+
if (!live || id !== void 0 && live.id !== id) return;
|
|
98
|
+
live = null;
|
|
99
|
+
emit();
|
|
100
|
+
},
|
|
101
|
+
async promise(promise, messages) {
|
|
102
|
+
const id = show(messages.loading, { tone: "loading" });
|
|
103
|
+
try {
|
|
104
|
+
const value = await promise;
|
|
105
|
+
springToast.update(id, {
|
|
106
|
+
tone: "success",
|
|
107
|
+
title: typeof messages.success === "function" ? messages.success(value) : messages.success
|
|
108
|
+
});
|
|
109
|
+
return value;
|
|
110
|
+
} catch (error) {
|
|
111
|
+
springToast.update(id, {
|
|
112
|
+
tone: "error",
|
|
113
|
+
title: typeof messages.error === "function" ? messages.error(error) : messages.error
|
|
114
|
+
});
|
|
115
|
+
throw error;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
const icons = {
|
|
120
|
+
neutral: /* @__PURE__ */ jsx(InfoIcon, { size: 16 }),
|
|
121
|
+
success: /* @__PURE__ */ jsx(CheckIcon, { size: 16 }),
|
|
122
|
+
warning: /* @__PURE__ */ jsx(WarningIcon, { size: 16 }),
|
|
123
|
+
error: /* @__PURE__ */ jsx(XIcon, { size: 16 }),
|
|
124
|
+
loading: /* @__PURE__ */ jsx(Spinner, {})
|
|
125
|
+
};
|
|
126
|
+
function SpringToaster({ position = "top-center", offset = 24, label = "Notifications", className }) {
|
|
127
|
+
const record = useSyncExternalStore(subscribe, snapshot, serverSnapshot);
|
|
128
|
+
const [portaled, setPortaled] = useState(false);
|
|
129
|
+
const [exiting, setExiting] = useState(null);
|
|
130
|
+
const [paused, setPaused] = useState(false);
|
|
131
|
+
const last = useRef(null);
|
|
132
|
+
const card = useRef(null);
|
|
133
|
+
const height = useRef(0);
|
|
134
|
+
useEffect(() => setPortaled(true), []);
|
|
135
|
+
useEffect(() => {
|
|
136
|
+
if (record) {
|
|
137
|
+
last.current = record;
|
|
138
|
+
setExiting(null);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const previous = last.current;
|
|
142
|
+
if (!previous) return;
|
|
143
|
+
setExiting(previous);
|
|
144
|
+
const timer = window.setTimeout(() => {
|
|
145
|
+
last.current = null;
|
|
146
|
+
setExiting(null);
|
|
147
|
+
}, EXIT_MS);
|
|
148
|
+
return () => window.clearTimeout(timer);
|
|
149
|
+
}, [record]);
|
|
150
|
+
const active = record ?? exiting;
|
|
151
|
+
const closing = record === null && exiting !== null;
|
|
152
|
+
useLayoutEffect(() => {
|
|
153
|
+
const element = card.current;
|
|
154
|
+
if (!element || closing) return;
|
|
155
|
+
const next = element.offsetHeight;
|
|
156
|
+
if (height.current && Math.abs(height.current - next) > 1) {
|
|
157
|
+
element.style.height = `${height.current}px`;
|
|
158
|
+
element.getBoundingClientRect();
|
|
159
|
+
element.style.height = `${next}px`;
|
|
160
|
+
window.setTimeout(() => {
|
|
161
|
+
element.style.height = "";
|
|
162
|
+
}, 260);
|
|
163
|
+
}
|
|
164
|
+
height.current = next;
|
|
165
|
+
}, [
|
|
166
|
+
active?.seq,
|
|
167
|
+
active?.count,
|
|
168
|
+
closing
|
|
169
|
+
]);
|
|
170
|
+
useEffect(() => {
|
|
171
|
+
if (!record || paused) return;
|
|
172
|
+
const ms = springDuration(record);
|
|
173
|
+
if (!ms) return;
|
|
174
|
+
const timer = window.setTimeout(() => springToast.dismiss(record.id), ms);
|
|
175
|
+
return () => window.clearTimeout(timer);
|
|
176
|
+
}, [record, paused]);
|
|
177
|
+
useEffect(() => {
|
|
178
|
+
if (!record) return;
|
|
179
|
+
const onKeyDown = (event) => {
|
|
180
|
+
if (event.key === "Escape") springToast.dismiss();
|
|
181
|
+
};
|
|
182
|
+
document.addEventListener("keydown", onKeyDown);
|
|
183
|
+
return () => document.removeEventListener("keydown", onKeyDown);
|
|
184
|
+
}, [record]);
|
|
185
|
+
if (!portaled || !active) return null;
|
|
186
|
+
const action = active.action;
|
|
187
|
+
return createPortal(/* @__PURE__ */ jsx("section", {
|
|
188
|
+
className: cn("sph-spring-toast-region", className),
|
|
189
|
+
"data-position": position,
|
|
190
|
+
"aria-label": label,
|
|
191
|
+
style: {
|
|
192
|
+
top: position.startsWith("top") ? offset : void 0,
|
|
193
|
+
bottom: position.startsWith("bottom") ? offset : void 0
|
|
194
|
+
},
|
|
195
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
196
|
+
ref: card,
|
|
197
|
+
className: "sph-spring-toast",
|
|
198
|
+
"data-tone": active.tone,
|
|
199
|
+
"data-closing": closing || void 0,
|
|
200
|
+
role: active.tone === "error" ? "alert" : "status",
|
|
201
|
+
"aria-atomic": "true",
|
|
202
|
+
tabIndex: -1,
|
|
203
|
+
onPointerEnter: () => setPaused(true),
|
|
204
|
+
onPointerLeave: () => setPaused(false),
|
|
205
|
+
onFocus: () => setPaused(true),
|
|
206
|
+
onBlur: () => setPaused(false),
|
|
207
|
+
children: [
|
|
208
|
+
/* @__PURE__ */ jsx("span", {
|
|
209
|
+
className: "sph-spring-toast__icon",
|
|
210
|
+
"aria-hidden": "true",
|
|
211
|
+
children: node(icons[active.tone])
|
|
212
|
+
}),
|
|
213
|
+
/* @__PURE__ */ jsxs("span", {
|
|
214
|
+
className: "sph-spring-toast__body",
|
|
215
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
216
|
+
className: "sph-spring-toast__title",
|
|
217
|
+
children: [node(active.title), active.count > 1 && /* @__PURE__ */ jsxs("span", {
|
|
218
|
+
className: "sph-spring-toast__count",
|
|
219
|
+
children: ["×", active.count]
|
|
220
|
+
})]
|
|
221
|
+
}), active.description !== void 0 && /* @__PURE__ */ jsx("span", {
|
|
222
|
+
className: "sph-spring-toast__description",
|
|
223
|
+
children: node(active.description)
|
|
224
|
+
})]
|
|
225
|
+
}),
|
|
226
|
+
action && /* @__PURE__ */ jsx("button", {
|
|
227
|
+
type: "button",
|
|
228
|
+
className: "sph-spring-toast__action",
|
|
229
|
+
onClick: () => {
|
|
230
|
+
const patch = action.onClick?.();
|
|
231
|
+
if (patch) springToast.update(active.id, patch);
|
|
232
|
+
else springToast.dismiss(active.id);
|
|
233
|
+
},
|
|
234
|
+
children: node(action.label)
|
|
235
|
+
}),
|
|
236
|
+
/* @__PURE__ */ jsx("button", {
|
|
237
|
+
type: "button",
|
|
238
|
+
className: "sph-spring-toast__close",
|
|
239
|
+
"aria-label": "Dismiss notification",
|
|
240
|
+
onClick: () => springToast.dismiss(active.id),
|
|
241
|
+
children: /* @__PURE__ */ jsx(XIcon, {
|
|
242
|
+
size: 12,
|
|
243
|
+
"aria-hidden": "true"
|
|
244
|
+
})
|
|
245
|
+
}),
|
|
246
|
+
active.progress !== void 0 && /* @__PURE__ */ jsx("span", {
|
|
247
|
+
className: "sph-spring-toast__progress",
|
|
248
|
+
"aria-hidden": "true",
|
|
249
|
+
style: { transform: `scaleX(${Math.min(1, Math.max(0, active.progress))})` }
|
|
250
|
+
})
|
|
251
|
+
]
|
|
252
|
+
})
|
|
253
|
+
}), document.body);
|
|
254
|
+
}
|
|
255
|
+
//#endregion
|
|
256
|
+
//#region src/molecules/Toast/index.tsx
|
|
257
|
+
const toastIcons = {
|
|
258
|
+
success: /* @__PURE__ */ jsx("span", {
|
|
259
|
+
className: "sph-toast__status-icon",
|
|
260
|
+
children: /* @__PURE__ */ jsx(CheckIcon, { size: 20 })
|
|
261
|
+
}),
|
|
262
|
+
info: /* @__PURE__ */ jsx("span", {
|
|
263
|
+
className: "sph-toast__status-icon",
|
|
264
|
+
children: /* @__PURE__ */ jsx(InfoIcon, { size: 20 })
|
|
265
|
+
}),
|
|
266
|
+
warning: /* @__PURE__ */ jsx("span", {
|
|
267
|
+
className: "sph-toast__status-icon",
|
|
268
|
+
children: /* @__PURE__ */ jsx(WarningIcon, { size: 20 })
|
|
269
|
+
}),
|
|
270
|
+
error: /* @__PURE__ */ jsx("span", {
|
|
271
|
+
className: "sph-toast__status-icon",
|
|
272
|
+
children: /* @__PURE__ */ jsx(XIcon, { size: 20 })
|
|
273
|
+
})
|
|
274
|
+
};
|
|
275
|
+
function Toast({ open = true, id, title, description, variant = "neutral", action, duration, closeButton = true, className }) {
|
|
276
|
+
useEffect(() => {
|
|
277
|
+
if (!open) return;
|
|
278
|
+
const options = {
|
|
279
|
+
id,
|
|
280
|
+
action,
|
|
281
|
+
closeButton,
|
|
282
|
+
description: node(description),
|
|
283
|
+
duration,
|
|
284
|
+
className: cn("sph-toast", className),
|
|
285
|
+
unstyled: true
|
|
286
|
+
};
|
|
287
|
+
const toastId = variant === "success" ? toast.success(node(title), options) : variant === "warning" ? toast.warning(node(title), options) : variant === "danger" ? toast.error(node(title), options) : toast(node(title), options);
|
|
288
|
+
return () => {
|
|
289
|
+
toast.dismiss(toastId);
|
|
290
|
+
};
|
|
291
|
+
}, [
|
|
292
|
+
open,
|
|
293
|
+
id,
|
|
294
|
+
action,
|
|
295
|
+
closeButton,
|
|
296
|
+
duration,
|
|
297
|
+
title,
|
|
298
|
+
description,
|
|
299
|
+
variant
|
|
300
|
+
]);
|
|
301
|
+
return null;
|
|
302
|
+
}
|
|
303
|
+
function ToastViewport({ label = "Notifications", className, toastOptions, theme = "system", position = "top-right", closeButton = true, expand = false, ...props }) {
|
|
304
|
+
const [portaled, setPortaled] = useState(false);
|
|
305
|
+
useEffect(() => setPortaled(true), []);
|
|
306
|
+
const toaster = /* @__PURE__ */ jsx(Toaster, {
|
|
307
|
+
...node(props),
|
|
308
|
+
theme,
|
|
309
|
+
position,
|
|
310
|
+
closeButton,
|
|
311
|
+
icons: toastIcons,
|
|
312
|
+
containerAriaLabel: label,
|
|
313
|
+
expand,
|
|
314
|
+
className: cn("sph-toast-viewport", className),
|
|
315
|
+
toastOptions: {
|
|
316
|
+
...toastOptions,
|
|
317
|
+
closeButton: toastOptions?.closeButton ?? closeButton,
|
|
318
|
+
closeButtonAriaLabel: toastOptions?.closeButtonAriaLabel ?? "Dismiss notification",
|
|
319
|
+
className: cn("sph-toast", toastOptions?.className),
|
|
320
|
+
unstyled: true
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
return portaled ? createPortal(toaster, document.body) : toaster;
|
|
324
|
+
}
|
|
325
|
+
//#endregion
|
|
326
|
+
export { springToast as a, SpringToaster as i, ToastViewport as n, toast as r, Toast as t };
|
|
327
|
+
|
|
328
|
+
//# sourceMappingURL=Toast-CGHWMJFI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Toast-CGHWMJFI.js","names":["SonnerToaster"],"sources":["../src/molecules/Toast/spring.tsx","../src/molecules/Toast/index.tsx"],"sourcesContent":["import { CheckIcon, InfoIcon, WarningIcon, XIcon } from \"@phosphor-icons/react\";\nimport { Spinner } from \"@/atoms/Spinner/index.js\";\nimport { cn } from \"@/lib/cn.js\";\nimport { node, type Renderable } from \"@/lib/node.js\";\nimport {\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n useSyncExternalStore,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\n\nconst DEFAULT_DURATION = 5000;\nconst EXIT_MS = 180;\n\nexport type SpringToastPosition =\n | \"top-left\"\n | \"top-center\"\n | \"top-right\"\n | \"bottom-left\"\n | \"bottom-center\"\n | \"bottom-right\";\n\nexport type SpringToastTone =\n | \"neutral\"\n | \"success\"\n | \"warning\"\n | \"error\"\n | \"loading\";\n\nexport type SpringToastAction = {\n label: Renderable;\n /** Return a patch to morph the toast in place instead of closing it. */\n onClick?: () => SpringToastPatch | void;\n};\n\nexport type SpringToastPatch = {\n title?: Renderable;\n description?: Renderable;\n tone?: SpringToastTone;\n action?: SpringToastAction | null;\n progress?: number | null;\n meta?: Renderable;\n duration?: number;\n};\n\nexport type SpringToastOptions = SpringToastPatch & { id?: string };\n\nexport type SpringToastRecord = {\n id: string;\n title: Renderable;\n description?: Renderable;\n tone: SpringToastTone;\n action?: SpringToastAction;\n progress?: number;\n meta?: Renderable;\n duration: number;\n count: number;\n seq: number;\n};\n\n/**\n * One toast owns the screen, so a new call morphs the live record instead of\n * adding a second card. A new call *replaces* the content: a field it does not\n * send is gone, not inherited from whatever toast came before. Only `update`\n * patches, keeping the fields it leaves out.\n */\nexport function mergeSpringToast(\n current: SpringToastRecord | null,\n patch: SpringToastOptions,\n seq: number,\n mode: \"replace\" | \"patch\" = \"replace\",\n): SpringToastRecord {\n const previous = mode === \"patch\" ? current : null;\n const tone = patch.tone ?? previous?.tone ?? \"neutral\";\n const title = patch.title ?? previous?.title ?? \"\";\n const description =\n patch.description !== undefined ? patch.description : previous?.description;\n const action =\n patch.action === null ? undefined : (patch.action ?? previous?.action);\n const progress =\n patch.progress === null\n ? undefined\n : (patch.progress ?? previous?.progress);\n const meta = patch.meta !== undefined ? patch.meta : previous?.meta;\n const duration = patch.duration ?? previous?.duration ?? DEFAULT_DURATION;\n\n const repeat =\n current !== null &&\n title === current.title &&\n tone === current.tone &&\n description === current.description &&\n action === current.action &&\n progress === current.progress;\n\n return {\n // A new call owns a new id, so a delayed update from an older caller is\n // ignored instead of rewriting whatever toast is on screen by then. Only a\n // patch (or an explicit id) targets the card that is already live.\n id:\n mode === \"patch\"\n ? (current?.id ?? patch.id ?? `sph-spring-toast-${seq}`)\n : (patch.id ?? `sph-spring-toast-${seq}`),\n title,\n description,\n tone,\n action,\n progress,\n meta,\n duration,\n count: repeat ? current.count + 1 : 1,\n seq,\n };\n}\n\n/** Errors, loading and toasts with an action wait for the reader. */\nexport function springDuration(\n record: Pick<SpringToastRecord, \"tone\" | \"action\" | \"duration\">,\n): number {\n if (record.tone === \"error\" || record.tone === \"loading\" || record.action)\n return 0;\n return record.duration;\n}\n\nlet live: SpringToastRecord | null = null;\nlet seq = 0;\nconst listeners = new Set<() => void>();\nconst emit = () => {\n for (const listener of listeners) listener();\n};\nconst subscribe = (listener: () => void) => {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n};\nconst snapshot = () => live;\nconst serverSnapshot = () => null;\n\nfunction show(title: Renderable, options: SpringToastOptions = {}): string {\n seq += 1;\n live = mergeSpringToast(live, { ...options, title }, seq, \"replace\");\n emit();\n return live.id;\n}\n\nexport const springToast = Object.assign(show, {\n success: (title: Renderable, options?: SpringToastOptions) =>\n show(title, { ...options, tone: \"success\" }),\n error: (title: Renderable, options?: SpringToastOptions) =>\n show(title, { ...options, tone: \"error\" }),\n warning: (title: Renderable, options?: SpringToastOptions) =>\n show(title, { ...options, tone: \"warning\" }),\n info: (title: Renderable, options?: SpringToastOptions) =>\n show(title, { ...options, tone: \"neutral\" }),\n loading: (title: Renderable, options?: SpringToastOptions) =>\n show(title, { ...options, tone: \"loading\" }),\n update(id: string, patch: SpringToastPatch) {\n if (!live || live.id !== id) return;\n seq += 1;\n live = mergeSpringToast(live, patch, seq, \"patch\");\n emit();\n },\n dismiss(id?: string) {\n if (!live || (id !== undefined && live.id !== id)) return;\n live = null;\n emit();\n },\n async promise<T>(\n promise: Promise<T>,\n messages: {\n loading: Renderable;\n success: Renderable | ((value: T) => Renderable);\n error: Renderable | ((error: unknown) => Renderable);\n },\n ): Promise<T> {\n const id = show(messages.loading, { tone: \"loading\" });\n try {\n const value = await promise;\n springToast.update(id, {\n tone: \"success\",\n title:\n typeof messages.success === \"function\"\n ? messages.success(value)\n : messages.success,\n });\n return value;\n } catch (error) {\n springToast.update(id, {\n tone: \"error\",\n title:\n typeof messages.error === \"function\"\n ? messages.error(error)\n : messages.error,\n });\n throw error;\n }\n },\n});\n\nconst icons: Record<SpringToastTone, Renderable> = {\n neutral: <InfoIcon size={16} />,\n success: <CheckIcon size={16} />,\n warning: <WarningIcon size={16} />,\n error: <XIcon size={16} />,\n loading: <Spinner />,\n};\n\nexport type SpringToasterProps = {\n position?: SpringToastPosition;\n /** Distance from the viewport edge; raise it to clear a sticky header. */\n offset?: number;\n label?: string;\n className?: string;\n};\n\nexport function SpringToaster({\n position = \"top-center\",\n offset = 24,\n label = \"Notifications\",\n className,\n}: SpringToasterProps) {\n const record = useSyncExternalStore(subscribe, snapshot, serverSnapshot);\n const [portaled, setPortaled] = useState(false);\n const [exiting, setExiting] = useState<SpringToastRecord | null>(null);\n const [paused, setPaused] = useState(false);\n const last = useRef<SpringToastRecord | null>(null);\n const card = useRef<HTMLDivElement>(null);\n const height = useRef(0);\n\n useEffect(() => setPortaled(true), []);\n\n // Keep the closed card on screen long enough to play its exit.\n useEffect(() => {\n if (record) {\n last.current = record;\n setExiting(null);\n return;\n }\n const previous = last.current;\n if (!previous) return;\n setExiting(previous);\n const timer = window.setTimeout(() => {\n last.current = null;\n setExiting(null);\n }, EXIT_MS);\n return () => window.clearTimeout(timer);\n }, [record]);\n\n const active = record ?? exiting;\n const closing = record === null && exiting !== null;\n\n // Morph the card between records: start from the old height, land on the new\n // one, then hand control back to auto so the next change can measure again.\n useLayoutEffect(() => {\n const element = card.current;\n if (!element || closing) return;\n const next = element.offsetHeight;\n if (height.current && Math.abs(height.current - next) > 1) {\n element.style.height = `${height.current}px`;\n element.getBoundingClientRect();\n element.style.height = `${next}px`;\n window.setTimeout(() => {\n element.style.height = \"\";\n }, 260);\n }\n height.current = next;\n }, [active?.seq, active?.count, closing]);\n\n useEffect(() => {\n if (!record || paused) return;\n const ms = springDuration(record);\n if (!ms) return;\n const timer = window.setTimeout(() => springToast.dismiss(record.id), ms);\n return () => window.clearTimeout(timer);\n }, [record, paused]);\n\n useEffect(() => {\n if (!record) return;\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") springToast.dismiss();\n };\n document.addEventListener(\"keydown\", onKeyDown);\n return () => document.removeEventListener(\"keydown\", onKeyDown);\n }, [record]);\n\n if (!portaled || !active) return null;\n\n const action = active.action;\n\n return createPortal(\n <section\n className={cn(\"sph-spring-toast-region\", className)}\n data-position={position}\n aria-label={label}\n style={{\n top: position.startsWith(\"top\") ? offset : undefined,\n bottom: position.startsWith(\"bottom\") ? offset : undefined,\n }}\n >\n <div\n ref={card}\n className=\"sph-spring-toast\"\n data-tone={active.tone}\n data-closing={closing || undefined}\n role={active.tone === \"error\" ? \"alert\" : \"status\"}\n aria-atomic=\"true\"\n tabIndex={-1}\n onPointerEnter={() => setPaused(true)}\n onPointerLeave={() => setPaused(false)}\n onFocus={() => setPaused(true)}\n onBlur={() => setPaused(false)}\n >\n <span className=\"sph-spring-toast__icon\" aria-hidden=\"true\">\n {node(icons[active.tone])}\n </span>\n <span className=\"sph-spring-toast__body\">\n <span className=\"sph-spring-toast__title\">\n {node(active.title)}\n {active.count > 1 && (\n <span className=\"sph-spring-toast__count\">×{active.count}</span>\n )}\n </span>\n {active.description !== undefined && (\n <span className=\"sph-spring-toast__description\">\n {node(active.description)}\n </span>\n )}\n </span>\n {action && (\n <button\n type=\"button\"\n className=\"sph-spring-toast__action\"\n onClick={() => {\n const patch = action.onClick?.();\n if (patch) springToast.update(active.id, patch);\n else springToast.dismiss(active.id);\n }}\n >\n {node(action.label)}\n </button>\n )}\n <button\n type=\"button\"\n className=\"sph-spring-toast__close\"\n aria-label=\"Dismiss notification\"\n onClick={() => springToast.dismiss(active.id)}\n >\n <XIcon size={12} aria-hidden=\"true\" />\n </button>\n {active.progress !== undefined && (\n <span\n className=\"sph-spring-toast__progress\"\n aria-hidden=\"true\"\n style={{\n transform: `scaleX(${Math.min(1, Math.max(0, active.progress))})`,\n }}\n />\n )}\n </div>\n </section>,\n document.body,\n );\n}\n","import { CheckIcon, InfoIcon, WarningIcon, XIcon } from \"@phosphor-icons/react\";\nimport { cn } from \"@/lib/cn.js\";\nimport { useEffect, useState } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport {\n type ExternalToast,\n Toaster as SonnerToaster,\n type ToasterProps as SonnerToasterProps,\n toast,\n} from \"sonner\";\nimport { node, type Renderable } from \"@/lib/node.js\";\n\nexport type { ExternalToast } from \"sonner\";\nexport { toast };\nexport {\n SpringToaster,\n type SpringToasterProps,\n springToast,\n type SpringToastAction,\n type SpringToastOptions,\n type SpringToastPatch,\n type SpringToastPosition,\n type SpringToastRecord,\n type SpringToastTone,\n} from \"./spring\";\n\nconst toastIcons = {\n success: (\n <span className=\"sph-toast__status-icon\">\n <CheckIcon size={20} />\n </span>\n ),\n info: (\n <span className=\"sph-toast__status-icon\">\n <InfoIcon size={20} />\n </span>\n ),\n warning: (\n <span className=\"sph-toast__status-icon\">\n <WarningIcon size={20} />\n </span>\n ),\n error: (\n <span className=\"sph-toast__status-icon\">\n <XIcon size={20} />\n </span>\n ),\n};\n\nexport type ToastProps = {\n open?: boolean;\n id?: string | number;\n title: Renderable;\n description?: Renderable;\n variant?: \"neutral\" | \"success\" | \"warning\" | \"danger\";\n action?: ExternalToast[\"action\"];\n duration?: number;\n closeButton?: boolean;\n className?: string;\n};\n\nexport function Toast({\n open = true,\n id,\n title,\n description,\n variant = \"neutral\",\n action,\n duration,\n closeButton = true,\n className,\n}: ToastProps) {\n useEffect(() => {\n if (!open) return;\n const options: ExternalToast = {\n id,\n action,\n closeButton,\n description: node(description),\n duration,\n className: cn(\"sph-toast\", className),\n unstyled: true,\n };\n const toastId =\n variant === \"success\"\n ? toast.success(node(title), options)\n : variant === \"warning\"\n ? toast.warning(node(title), options)\n : variant === \"danger\"\n ? toast.error(node(title), options)\n : toast(node(title), options);\n\n return () => {\n toast.dismiss(toastId);\n };\n }, [open, id, action, closeButton, duration, title, description, variant]);\n\n return null;\n}\n\nexport type ToastViewportProps = Omit<\n SonnerToasterProps,\n \"className\" | \"containerAriaLabel\" | \"icons\" | \"toastOptions\"\n> & {\n label?: string;\n className?: string;\n toastOptions?: SonnerToasterProps[\"toastOptions\"];\n};\n\nexport function ToastViewport({\n label = \"Notifications\",\n className,\n toastOptions,\n theme = \"system\",\n position = \"top-right\",\n closeButton = true,\n expand = false,\n ...props\n}: ToastViewportProps) {\n const [portaled, setPortaled] = useState(false);\n useEffect(() => setPortaled(true), []);\n\n const toaster = (\n <SonnerToaster\n {...node(props)}\n theme={theme}\n position={position}\n closeButton={closeButton}\n icons={toastIcons}\n containerAriaLabel={label}\n expand={expand}\n className={cn(\"sph-toast-viewport\", className)}\n toastOptions={{\n ...toastOptions,\n closeButton: toastOptions?.closeButton ?? closeButton,\n closeButtonAriaLabel:\n toastOptions?.closeButtonAriaLabel ?? \"Dismiss notification\",\n className: cn(\"sph-toast\", toastOptions?.className),\n unstyled: true,\n }}\n />\n );\n\n // Sonner mounts where it is rendered, so an ancestor with `isolation` or a\n // transform traps it in that stacking context and the toast paints under a\n // sticky header however high its z-index is. Portal it to the document.\n return portaled ? createPortal(toaster, document.body) : toaster;\n}\n"],"mappings":";;;;;;;;;AAaA,MAAM,mBAAmB;AACzB,MAAM,UAAU;;;;;;;AAsDhB,SAAgB,iBACd,SACA,OACA,KACA,OAA4B,WACT;CACnB,MAAM,WAAW,SAAS,UAAU,UAAU;CAC9C,MAAM,OAAO,MAAM,QAAQ,UAAU,QAAQ;CAC7C,MAAM,QAAQ,MAAM,SAAS,UAAU,SAAS;CAChD,MAAM,cACJ,MAAM,gBAAgB,KAAA,IAAY,MAAM,cAAc,UAAU;CAClE,MAAM,SACJ,MAAM,WAAW,OAAO,KAAA,IAAa,MAAM,UAAU,UAAU;CACjE,MAAM,WACJ,MA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KAAK,GAAG,OAAO,IAClC,YAAY,YACV,MAAM,QAAQ,KAAK,KAAK,GAAG,OAAO,IAClC,YAAY,WACV,MAAM,MAAM,KAAK,KAAK,GAAG,OAAO,IAChC,MAAM,KAAK,KAAK,GAAG,OAAO;EAEpC,aAAa;GACX,MAAM,QAAQ,OAAO;EACvB;CACF,GAAG;EAAC;EAAM;EAAI;EAAQ;EAAa;EAAU;EAAO;EAAa;CAAO,CAAC;CAEzE,OAAO;AACT;AAWA,SAAgB,cAAc,EAC5B,QAAQ,iBACR,WACA,cACA,QAAQ,UACR,WAAW,aACX,cAAc,MACd,SAAS,OACT,GAAG,SACkB;CACrB,MAAM,CAAC,UAAU,eAAe,SAAS,KAAK;CAC9C,gBAAgB,YAAY,IAAI,GAAG,CAAC,CAAC;CAErC,MAAM,UACJ,oBAACA,SAAD;EACE,GAAI,KAAK,KAAK;EACP;EACG;EACG;EACb,OAAO;EACP,oBAAoB;EACZ;EACR,WAAW,GAAG,sBAAsB,SAAS;EAC7C,cAAc;GACZ,GAAG;GACH,aAAa,cAAc,eAAe;GAC1C,sBACE,cAAc,wBAAwB;GACxC,WAAW,GAAG,aAAa,cAAc,SAAS;GAClD,UAAU;EACZ;CACD,CAAA;CAMH,OAAO,WAAW,aAAa,SAAS,SAAS,IAAI,IAAI;AAC3D"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { HTMLAttributes } from "react";
|
|
2
|
+
//#region src/organisms/ActivityHeatmap/index.d.ts
|
|
3
|
+
export type HeatmapDay = {
|
|
4
|
+
/** Day as `YYYY-MM-DD`. */
|
|
5
|
+
date: string;
|
|
6
|
+
/** How many events that day holds. */
|
|
7
|
+
count: number;
|
|
8
|
+
};
|
|
9
|
+
export type HeatmapLevel = 0 | 1 | 2 | 3 | 4;
|
|
10
|
+
export type HeatmapCell = {
|
|
11
|
+
date: string;
|
|
12
|
+
count: number;
|
|
13
|
+
level: HeatmapLevel;
|
|
14
|
+
/** Days after the end of the range keep the grid square and stay out of reach. */
|
|
15
|
+
future: boolean;
|
|
16
|
+
};
|
|
17
|
+
export type HeatmapMonthLabel = {
|
|
18
|
+
label: string;
|
|
19
|
+
column: number;
|
|
20
|
+
span: number;
|
|
21
|
+
};
|
|
22
|
+
export type HeatmapModel = {
|
|
23
|
+
/** Seven weekday rows, oldest week first in each. */
|
|
24
|
+
rows: HeatmapCell[][];
|
|
25
|
+
weeks: number;
|
|
26
|
+
first: string;
|
|
27
|
+
last: string;
|
|
28
|
+
total: number;
|
|
29
|
+
max: number;
|
|
30
|
+
monthLabels: HeatmapMonthLabel[];
|
|
31
|
+
};
|
|
32
|
+
export declare function heatmapMs(iso: string): number;
|
|
33
|
+
export declare function heatmapIso(ms: number): string;
|
|
34
|
+
/** Shifts a `YYYY-MM-DD` day by a number of days. */
|
|
35
|
+
export declare function shiftDay(iso: string, delta: number): string;
|
|
36
|
+
/** Day of week as `0` Sunday through `6` Saturday. */
|
|
37
|
+
export declare function weekdayOf(iso: string): number;
|
|
38
|
+
/** Buckets a count into one of five steps; zero is its own step. */
|
|
39
|
+
export declare function levelFor(count: number, max: number): HeatmapLevel;
|
|
40
|
+
export declare function buildHeatmap(days: HeatmapDay[], options?: {
|
|
41
|
+
weeks?: number;
|
|
42
|
+
end?: string;
|
|
43
|
+
max?: number;
|
|
44
|
+
}): HeatmapModel;
|
|
45
|
+
export type ActivityHeatmapProps = Omit<HTMLAttributes<HTMLDivElement>, "children" | "onSelect"> & {
|
|
46
|
+
/** One entry per day that has activity; days without an entry read as zero. */
|
|
47
|
+
days: HeatmapDay[];
|
|
48
|
+
/** Columns of weeks to draw. Default 26. */
|
|
49
|
+
weeks?: number;
|
|
50
|
+
/** Last day of the range as `YYYY-MM-DD`. Defaults to the latest day given. */
|
|
51
|
+
end?: string;
|
|
52
|
+
/** Fixes the top of the scale so two heatmaps compare. Defaults to the data max. */
|
|
53
|
+
max?: number;
|
|
54
|
+
/** Accessible name of the grid. */
|
|
55
|
+
label?: string;
|
|
56
|
+
/** Shows the Less / More legend. Default true. */
|
|
57
|
+
legend?: boolean;
|
|
58
|
+
/** Called with the day when a cell is clicked or activated with Enter or Space. */
|
|
59
|
+
onSelect?: (day: HeatmapDay) => void;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* A year of activity as a grid of days: weekdays down, weeks across. Intensity
|
|
63
|
+
* buckets the counts into four steps above zero, and the whole grid is one tab
|
|
64
|
+
* stop that the arrow keys walk day by day.
|
|
65
|
+
*/
|
|
66
|
+
export declare function ActivityHeatmap({ days, weeks, end, max, label, legend, onSelect, className, ...props }: ActivityHeatmapProps): import("react").JSX.Element;
|
|
67
|
+
//#endregion
|
|
68
|
+
//# sourceMappingURL=activity-heatmap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"activity-heatmap.d.ts","names":[],"sources":["../src/organisms/ActivityHeatmap/index.tsx"],"mappings":";;YAMY;;EAEV;;EAEA;;YAGU;YAEA;EACV;EACA;EACA,OAAO;;EAEP;;YAGU;EACV;EACA;EACA;;YAGU;;EAEV,MAAM;EACN;EACA;EACA;EACA;EACA;EACA,aAAa;;wBAqBC,UAAU;wBAKV,WAAW;;wBAKX,SAAS,aAAa;;wBAKtB,UAAU;;wBAKV,SAAS,eAAe,cAAc;wBAMtC,aACd,MAAM,cACN;EAAW;EAAgB;EAAc;IACxC;YAoES,uBAAuB,KACjC,eAAe;;EAIf,MAAM;;EAEN;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA,YAAY,KAAK;;;;;;;wBAQH,kBACd,MACA,OACA,KACA,KACA,OACA,QACA,UACA,cACG,SACF,uCAAoB,IAAA"}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { t as cn } from "./cn-M4U2-Tak.js";
|
|
2
|
+
import { t as node } from "./node-Dr67KnBr.js";
|
|
3
|
+
import { n as TooltipGroup, t as Tooltip } from "./Tooltip-Clb5PoSN.js";
|
|
4
|
+
import { useMemo, useRef, useState } from "react";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
//#region src/organisms/ActivityHeatmap/index.tsx
|
|
7
|
+
const DAY_MS = 864e5;
|
|
8
|
+
const MONTH_LABELS = [
|
|
9
|
+
"Jan",
|
|
10
|
+
"Feb",
|
|
11
|
+
"Mar",
|
|
12
|
+
"Apr",
|
|
13
|
+
"May",
|
|
14
|
+
"Jun",
|
|
15
|
+
"Jul",
|
|
16
|
+
"Aug",
|
|
17
|
+
"Sep",
|
|
18
|
+
"Oct",
|
|
19
|
+
"Nov",
|
|
20
|
+
"Dec"
|
|
21
|
+
];
|
|
22
|
+
const WEEKDAY_LABELS = [
|
|
23
|
+
"Sun",
|
|
24
|
+
"Mon",
|
|
25
|
+
"Tue",
|
|
26
|
+
"Wed",
|
|
27
|
+
"Thu",
|
|
28
|
+
"Fri",
|
|
29
|
+
"Sat"
|
|
30
|
+
];
|
|
31
|
+
const WEEK_STARTS_ON = 1;
|
|
32
|
+
function heatmapMs(iso) {
|
|
33
|
+
const [year, month, day] = iso.split("-").map(Number);
|
|
34
|
+
return Date.UTC(year, month - 1, day);
|
|
35
|
+
}
|
|
36
|
+
function heatmapIso(ms) {
|
|
37
|
+
return new Date(ms).toISOString().slice(0, 10);
|
|
38
|
+
}
|
|
39
|
+
/** Shifts a `YYYY-MM-DD` day by a number of days. */
|
|
40
|
+
function shiftDay(iso, delta) {
|
|
41
|
+
return heatmapIso(heatmapMs(iso) + delta * DAY_MS);
|
|
42
|
+
}
|
|
43
|
+
/** Day of week as `0` Sunday through `6` Saturday. */
|
|
44
|
+
function weekdayOf(iso) {
|
|
45
|
+
return new Date(heatmapMs(iso)).getUTCDay();
|
|
46
|
+
}
|
|
47
|
+
/** Buckets a count into one of five steps; zero is its own step. */
|
|
48
|
+
function levelFor(count, max) {
|
|
49
|
+
if (count <= 0) return 0;
|
|
50
|
+
if (max <= 0) return 1;
|
|
51
|
+
return Math.min(4, Math.max(1, Math.ceil(count / max * 4)));
|
|
52
|
+
}
|
|
53
|
+
function buildHeatmap(days, options = {}) {
|
|
54
|
+
const weeks = Math.max(1, options.weeks ?? 26);
|
|
55
|
+
const counts = /* @__PURE__ */ new Map();
|
|
56
|
+
for (const day of days) counts.set(day.date, day.count);
|
|
57
|
+
const known = days.map((day) => day.date).sort();
|
|
58
|
+
const last = options.end ?? known[known.length - 1] ?? heatmapIso(Date.now());
|
|
59
|
+
const max = Math.max(1, options.max ?? Math.max(0, ...counts.values()));
|
|
60
|
+
const columnStart = (iso) => shiftDay(iso, -((weekdayOf(iso) - WEEK_STARTS_ON + 7) % 7));
|
|
61
|
+
const first = shiftDay(columnStart(last), -(weeks - 1) * 7);
|
|
62
|
+
const rows = Array.from({ length: 7 }, () => []);
|
|
63
|
+
const starts = [];
|
|
64
|
+
for (let column = 0; column < weeks; column += 1) {
|
|
65
|
+
const start = shiftDay(first, column * 7);
|
|
66
|
+
starts.push(start);
|
|
67
|
+
for (let row = 0; row < 7; row += 1) {
|
|
68
|
+
const date = shiftDay(start, row);
|
|
69
|
+
const count = counts.get(date) ?? 0;
|
|
70
|
+
rows[row].push({
|
|
71
|
+
date,
|
|
72
|
+
count,
|
|
73
|
+
level: levelFor(count, max),
|
|
74
|
+
future: date > last
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const monthLabels = [];
|
|
79
|
+
starts.forEach((start, column) => {
|
|
80
|
+
const month = Number(start.slice(5, 7)) - 1;
|
|
81
|
+
const previous = column > 0 ? Number(starts[column - 1].slice(5, 7)) - 1 : -1;
|
|
82
|
+
if (column === 0 || month !== previous) monthLabels.push({
|
|
83
|
+
label: MONTH_LABELS[month],
|
|
84
|
+
column,
|
|
85
|
+
span: 0
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
monthLabels.forEach((label, index) => {
|
|
89
|
+
const next = monthLabels[index + 1]?.column ?? weeks;
|
|
90
|
+
label.span = Math.max(1, next - label.column);
|
|
91
|
+
});
|
|
92
|
+
return {
|
|
93
|
+
rows,
|
|
94
|
+
weeks,
|
|
95
|
+
first,
|
|
96
|
+
last,
|
|
97
|
+
total: rows.flat().filter((cell) => !cell.future).reduce((sum, cell) => sum + cell.count, 0),
|
|
98
|
+
max,
|
|
99
|
+
monthLabels: monthLabels.filter((label, index) => label.span >= 2 || index === 0)
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function cellLabel(cell) {
|
|
103
|
+
const [year, month, day] = cell.date.split("-").map(Number);
|
|
104
|
+
const events = `${cell.count} ${cell.count === 1 ? "event" : "events"}`;
|
|
105
|
+
return `${WEEKDAY_LABELS[weekdayOf(cell.date)]}, ${day} ${MONTH_LABELS[month - 1]} ${year}: ${events}`;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* A year of activity as a grid of days: weekdays down, weeks across. Intensity
|
|
109
|
+
* buckets the counts into four steps above zero, and the whole grid is one tab
|
|
110
|
+
* stop that the arrow keys walk day by day.
|
|
111
|
+
*/
|
|
112
|
+
function ActivityHeatmap({ days, weeks = 26, end, max, label = "Activity by day", legend = true, onSelect, className, ...props }) {
|
|
113
|
+
const model = useMemo(() => buildHeatmap(days, {
|
|
114
|
+
weeks,
|
|
115
|
+
end,
|
|
116
|
+
max
|
|
117
|
+
}), [
|
|
118
|
+
days,
|
|
119
|
+
weeks,
|
|
120
|
+
end,
|
|
121
|
+
max
|
|
122
|
+
]);
|
|
123
|
+
const [active, setActive] = useState(null);
|
|
124
|
+
const cells = useRef(/* @__PURE__ */ new Map());
|
|
125
|
+
const focusDate = active ?? model.last;
|
|
126
|
+
const clamp = (iso) => iso < model.first ? model.first : iso > model.last ? model.last : iso;
|
|
127
|
+
const move = (date) => {
|
|
128
|
+
setActive(date);
|
|
129
|
+
cells.current.get(date)?.focus({ preventScroll: true });
|
|
130
|
+
};
|
|
131
|
+
const handleKeyDown = (event, date) => {
|
|
132
|
+
const weekday = (weekdayOf(date) - WEEK_STARTS_ON + 7) % 7;
|
|
133
|
+
const delta = {
|
|
134
|
+
ArrowLeft: -7,
|
|
135
|
+
ArrowRight: 7,
|
|
136
|
+
ArrowUp: -1,
|
|
137
|
+
ArrowDown: 1,
|
|
138
|
+
Home: -weekday,
|
|
139
|
+
End: 6 - weekday,
|
|
140
|
+
PageUp: -28,
|
|
141
|
+
PageDown: 28
|
|
142
|
+
}[event.key];
|
|
143
|
+
if (delta === void 0) return;
|
|
144
|
+
event.preventDefault();
|
|
145
|
+
move(clamp(shiftDay(date, delta)));
|
|
146
|
+
};
|
|
147
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
148
|
+
className: cn("sph-heatmap", className),
|
|
149
|
+
...node(props),
|
|
150
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
151
|
+
className: "sph-heatmap__scroll",
|
|
152
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
153
|
+
className: "sph-heatmap__months",
|
|
154
|
+
"aria-hidden": "true",
|
|
155
|
+
style: node({ "--sph-heatmap-weeks": String(model.weeks) }),
|
|
156
|
+
children: model.monthLabels.map((month) => /* @__PURE__ */ jsx("span", {
|
|
157
|
+
className: "sph-heatmap__month",
|
|
158
|
+
style: { gridColumn: `${month.column + 2} / span ${month.span}` },
|
|
159
|
+
children: month.label
|
|
160
|
+
}, `${month.label}-${month.column}`))
|
|
161
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
162
|
+
className: "sph-heatmap__body",
|
|
163
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
164
|
+
className: "sph-heatmap__weekdays",
|
|
165
|
+
"aria-hidden": "true",
|
|
166
|
+
children: model.rows.map((_, row) => {
|
|
167
|
+
const weekday = (WEEK_STARTS_ON + row) % 7;
|
|
168
|
+
return /* @__PURE__ */ jsx("span", {
|
|
169
|
+
className: "sph-heatmap__weekday",
|
|
170
|
+
children: weekday % 2 === 1 ? WEEKDAY_LABELS[weekday] : ""
|
|
171
|
+
}, row);
|
|
172
|
+
})
|
|
173
|
+
}), /* @__PURE__ */ jsx(TooltipGroup, { children: /* @__PURE__ */ jsx("div", {
|
|
174
|
+
className: "sph-heatmap__grid",
|
|
175
|
+
role: "grid",
|
|
176
|
+
"aria-label": label,
|
|
177
|
+
children: model.rows.map((row, index) => /* @__PURE__ */ jsx("div", {
|
|
178
|
+
className: "sph-heatmap__row",
|
|
179
|
+
role: "row",
|
|
180
|
+
children: row.map((cell) => {
|
|
181
|
+
const day = /* @__PURE__ */ jsx("button", {
|
|
182
|
+
ref: (element) => {
|
|
183
|
+
if (element) cells.current.set(cell.date, element);
|
|
184
|
+
else cells.current.delete(cell.date);
|
|
185
|
+
},
|
|
186
|
+
type: "button",
|
|
187
|
+
role: "gridcell",
|
|
188
|
+
className: "sph-heatmap__cell",
|
|
189
|
+
"data-level": cell.future ? void 0 : cell.level,
|
|
190
|
+
"data-future": cell.future || void 0,
|
|
191
|
+
"aria-hidden": cell.future || void 0,
|
|
192
|
+
tabIndex: cell.future ? -1 : cell.date === focusDate ? 0 : -1,
|
|
193
|
+
"aria-label": cell.future ? void 0 : cellLabel(cell),
|
|
194
|
+
onClick: () => onSelect?.({
|
|
195
|
+
date: cell.date,
|
|
196
|
+
count: cell.count
|
|
197
|
+
}),
|
|
198
|
+
onKeyDown: (event) => handleKeyDown(event, cell.date)
|
|
199
|
+
}, cell.date);
|
|
200
|
+
if (cell.future) return day;
|
|
201
|
+
return /* @__PURE__ */ jsx(Tooltip, {
|
|
202
|
+
content: cellLabel(cell),
|
|
203
|
+
side: "top",
|
|
204
|
+
children: day
|
|
205
|
+
}, cell.date);
|
|
206
|
+
})
|
|
207
|
+
}, index))
|
|
208
|
+
}) })]
|
|
209
|
+
})]
|
|
210
|
+
}), legend && /* @__PURE__ */ jsxs("div", {
|
|
211
|
+
className: "sph-heatmap__legend",
|
|
212
|
+
"aria-hidden": "true",
|
|
213
|
+
children: [
|
|
214
|
+
/* @__PURE__ */ jsx("span", {
|
|
215
|
+
className: "sph-heatmap__legend-label",
|
|
216
|
+
children: "Less"
|
|
217
|
+
}),
|
|
218
|
+
[
|
|
219
|
+
0,
|
|
220
|
+
1,
|
|
221
|
+
2,
|
|
222
|
+
3,
|
|
223
|
+
4
|
|
224
|
+
].map((level) => /* @__PURE__ */ jsx("span", {
|
|
225
|
+
className: "sph-heatmap__cell sph-heatmap__swatch",
|
|
226
|
+
"data-level": level
|
|
227
|
+
}, level)),
|
|
228
|
+
/* @__PURE__ */ jsx("span", {
|
|
229
|
+
className: "sph-heatmap__legend-label",
|
|
230
|
+
children: "More"
|
|
231
|
+
})
|
|
232
|
+
]
|
|
233
|
+
})]
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
//#endregion
|
|
237
|
+
export { ActivityHeatmap, buildHeatmap, heatmapIso, heatmapMs, levelFor, shiftDay, weekdayOf };
|
|
238
|
+
|
|
239
|
+
//# sourceMappingURL=activity-heatmap.js.map
|