@ttt-productions/ui-core 0.11.33 → 0.11.35
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/README.md +1 -1
- package/dist/browser/index.d.ts +2 -2
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.js +1 -2
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/reload-recovery-watch.d.ts +2 -6
- package/dist/browser/reload-recovery-watch.d.ts.map +1 -1
- package/dist/browser/reload-recovery-watch.js +5 -10
- package/dist/browser/reload-recovery-watch.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -4
- package/dist/index.js.map +1 -1
- package/dist/lib/format-numbers.d.ts +0 -6
- package/dist/lib/format-numbers.d.ts.map +1 -1
- package/dist/lib/format-numbers.js +2 -8
- package/dist/lib/format-numbers.js.map +1 -1
- package/dist/lib/reload-recovery.d.ts +1 -9
- package/dist/lib/reload-recovery.d.ts.map +1 -1
- package/dist/lib/reload-recovery.js +14 -24
- package/dist/lib/reload-recovery.js.map +1 -1
- package/dist/lib/utils.d.ts +0 -3
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/lib/utils.js +0 -3
- package/dist/lib/utils.js.map +1 -1
- package/dist/react/components/accordion.d.ts +2 -2
- package/dist/react/components/accordion.d.ts.map +1 -1
- package/dist/react/components/accordion.js +8 -8
- package/dist/react/components/accordion.js.map +1 -1
- package/dist/react/components/action-row.d.ts +2 -9
- package/dist/react/components/action-row.d.ts.map +1 -1
- package/dist/react/components/action-row.js +7 -11
- package/dist/react/components/action-row.js.map +1 -1
- package/dist/react/components/alert-dialog.d.ts +2 -2
- package/dist/react/components/alert-dialog.d.ts.map +1 -1
- package/dist/react/components/alert-dialog.js +15 -15
- package/dist/react/components/alert-dialog.js.map +1 -1
- package/dist/react/components/alert.d.ts +2 -2
- package/dist/react/components/alert.d.ts.map +1 -1
- package/dist/react/components/alert.js +12 -12
- package/dist/react/components/alert.js.map +1 -1
- package/dist/react/components/avatar.d.ts +2 -2
- package/dist/react/components/avatar.d.ts.map +1 -1
- package/dist/react/components/avatar.js +7 -7
- package/dist/react/components/avatar.js.map +1 -1
- package/dist/react/components/badge.d.ts +2 -2
- package/dist/react/components/badge.d.ts.map +1 -1
- package/dist/react/components/badge.js +9 -9
- package/dist/react/components/badge.js.map +1 -1
- package/dist/react/components/button.d.ts +2 -12
- package/dist/react/components/button.d.ts.map +1 -1
- package/dist/react/components/button.js +30 -35
- package/dist/react/components/button.js.map +1 -1
- package/dist/react/components/card.d.ts +1 -1
- package/dist/react/components/card.d.ts.map +1 -1
- package/dist/react/components/card.js +15 -15
- package/dist/react/components/card.js.map +1 -1
- package/dist/react/components/checkbox.d.ts +2 -2
- package/dist/react/components/checkbox.d.ts.map +1 -1
- package/dist/react/components/checkbox.js +6 -6
- package/dist/react/components/checkbox.js.map +1 -1
- package/dist/react/components/collapsible.d.ts +1 -1
- package/dist/react/components/collapsible.d.ts.map +1 -1
- package/dist/react/components/collapsible.js +2 -2
- package/dist/react/components/collapsible.js.map +1 -1
- package/dist/react/components/consequence-dialog.d.ts +1 -48
- package/dist/react/components/consequence-dialog.d.ts.map +1 -1
- package/dist/react/components/consequence-dialog.js +7 -23
- package/dist/react/components/consequence-dialog.js.map +1 -1
- package/dist/react/components/date-picker.d.ts +1 -18
- package/dist/react/components/date-picker.d.ts.map +1 -1
- package/dist/react/components/date-picker.js +102 -98
- package/dist/react/components/date-picker.js.map +1 -1
- package/dist/react/components/date-time-picker.d.ts +1 -24
- package/dist/react/components/date-time-picker.d.ts.map +1 -1
- package/dist/react/components/date-time-picker.js +20 -37
- package/dist/react/components/date-time-picker.js.map +1 -1
- package/dist/react/components/dialog.d.ts +2 -2
- package/dist/react/components/dialog.d.ts.map +1 -1
- package/dist/react/components/dialog.js +14 -14
- package/dist/react/components/dialog.js.map +1 -1
- package/dist/react/components/dropdown-menu.d.ts +2 -10
- package/dist/react/components/dropdown-menu.d.ts.map +1 -1
- package/dist/react/components/dropdown-menu.js +24 -20
- package/dist/react/components/dropdown-menu.js.map +1 -1
- package/dist/react/components/end-of-list-indicator.d.ts +1 -1
- package/dist/react/components/end-of-list-indicator.js +3 -3
- package/dist/react/components/end-of-list-indicator.js.map +1 -1
- package/dist/react/components/form.d.ts +3 -3
- package/dist/react/components/form.d.ts.map +1 -1
- package/dist/react/components/form.js +17 -17
- package/dist/react/components/form.js.map +1 -1
- package/dist/react/components/format-control.d.ts +7 -20
- package/dist/react/components/format-control.d.ts.map +1 -1
- package/dist/react/components/format-control.js +18 -22
- package/dist/react/components/format-control.js.map +1 -1
- package/dist/react/components/input.d.ts +10 -27
- package/dist/react/components/input.d.ts.map +1 -1
- package/dist/react/components/input.js +11 -9
- package/dist/react/components/input.js.map +1 -1
- package/dist/react/components/label.d.ts +3 -3
- package/dist/react/components/label.d.ts.map +1 -1
- package/dist/react/components/label.js +6 -6
- package/dist/react/components/label.js.map +1 -1
- package/dist/react/components/layout/screen-adaptive-view.d.ts +2 -9
- package/dist/react/components/layout/screen-adaptive-view.d.ts.map +1 -1
- package/dist/react/components/layout/screen-adaptive-view.js +40 -37
- package/dist/react/components/layout/screen-adaptive-view.js.map +1 -1
- package/dist/react/components/list-pagination.d.ts +1 -31
- package/dist/react/components/list-pagination.d.ts.map +1 -1
- package/dist/react/components/list-pagination.js +10 -37
- package/dist/react/components/list-pagination.js.map +1 -1
- package/dist/react/components/menubar.d.ts +2 -2
- package/dist/react/components/menubar.d.ts.map +1 -1
- package/dist/react/components/menubar.js +17 -17
- package/dist/react/components/menubar.js.map +1 -1
- package/dist/react/components/opener-focus.d.ts +2 -8
- package/dist/react/components/opener-focus.d.ts.map +1 -1
- package/dist/react/components/opener-focus.js +4 -10
- package/dist/react/components/opener-focus.js.map +1 -1
- package/dist/react/components/pending-guard.d.ts +1 -7
- package/dist/react/components/pending-guard.d.ts.map +1 -1
- package/dist/react/components/pending-guard.js +1 -7
- package/dist/react/components/pending-guard.js.map +1 -1
- package/dist/react/components/popover.d.ts +2 -2
- package/dist/react/components/popover.d.ts.map +1 -1
- package/dist/react/components/popover.js +5 -5
- package/dist/react/components/popover.js.map +1 -1
- package/dist/react/components/progress.d.ts +2 -2
- package/dist/react/components/progress.d.ts.map +1 -1
- package/dist/react/components/progress.js +5 -5
- package/dist/react/components/progress.js.map +1 -1
- package/dist/react/components/radio-group.d.ts +2 -2
- package/dist/react/components/radio-group.d.ts.map +1 -1
- package/dist/react/components/radio-group.js +7 -7
- package/dist/react/components/radio-group.js.map +1 -1
- package/dist/react/components/relative-time.d.ts +1 -9
- package/dist/react/components/relative-time.d.ts.map +1 -1
- package/dist/react/components/relative-time.js +8 -11
- package/dist/react/components/relative-time.js.map +1 -1
- package/dist/react/components/reload-recovery-notice.d.ts +3 -17
- package/dist/react/components/reload-recovery-notice.d.ts.map +1 -1
- package/dist/react/components/reload-recovery-notice.js +7 -12
- package/dist/react/components/reload-recovery-notice.js.map +1 -1
- package/dist/react/components/scroll-area.d.ts +2 -2
- package/dist/react/components/scroll-area.d.ts.map +1 -1
- package/dist/react/components/scroll-area.js +6 -8
- package/dist/react/components/scroll-area.js.map +1 -1
- package/dist/react/components/scroll-to-top-button.d.ts +6 -30
- package/dist/react/components/scroll-to-top-button.d.ts.map +1 -1
- package/dist/react/components/scroll-to-top-button.js +9 -9
- package/dist/react/components/scroll-to-top-button.js.map +1 -1
- package/dist/react/components/search-dropdown.d.ts +0 -53
- package/dist/react/components/search-dropdown.d.ts.map +1 -1
- package/dist/react/components/search-dropdown.js +10 -39
- package/dist/react/components/search-dropdown.js.map +1 -1
- package/dist/react/components/select.d.ts +2 -9
- package/dist/react/components/select.d.ts.map +1 -1
- package/dist/react/components/select.js +19 -21
- package/dist/react/components/select.js.map +1 -1
- package/dist/react/components/separator.d.ts +2 -2
- package/dist/react/components/separator.d.ts.map +1 -1
- package/dist/react/components/separator.js +5 -5
- package/dist/react/components/separator.js.map +1 -1
- package/dist/react/components/sheet.d.ts +3 -3
- package/dist/react/components/sheet.d.ts.map +1 -1
- package/dist/react/components/sheet.js +21 -21
- package/dist/react/components/sheet.js.map +1 -1
- package/dist/react/components/show-more-toggle.d.ts +2 -18
- package/dist/react/components/show-more-toggle.d.ts.map +1 -1
- package/dist/react/components/show-more-toggle.js +6 -11
- package/dist/react/components/show-more-toggle.js.map +1 -1
- package/dist/react/components/skeleton.d.ts +1 -1
- package/dist/react/components/skeleton.d.ts.map +1 -1
- package/dist/react/components/skeleton.js +3 -3
- package/dist/react/components/skeleton.js.map +1 -1
- package/dist/react/components/slider.d.ts +2 -2
- package/dist/react/components/slider.d.ts.map +1 -1
- package/dist/react/components/slider.js +5 -5
- package/dist/react/components/slider.js.map +1 -1
- package/dist/react/components/spinner.d.ts +1 -15
- package/dist/react/components/spinner.d.ts.map +1 -1
- package/dist/react/components/spinner.js +10 -18
- package/dist/react/components/spinner.js.map +1 -1
- package/dist/react/components/switch.d.ts +2 -9
- package/dist/react/components/switch.d.ts.map +1 -1
- package/dist/react/components/switch.js +13 -10
- package/dist/react/components/switch.js.map +1 -1
- package/dist/react/components/table.d.ts +2 -12
- package/dist/react/components/table.d.ts.map +1 -1
- package/dist/react/components/table.js +24 -30
- package/dist/react/components/table.js.map +1 -1
- package/dist/react/components/tabs.d.ts +2 -2
- package/dist/react/components/tabs.d.ts.map +1 -1
- package/dist/react/components/tabs.js +7 -7
- package/dist/react/components/tabs.js.map +1 -1
- package/dist/react/components/textarea.d.ts +5 -16
- package/dist/react/components/textarea.d.ts.map +1 -1
- package/dist/react/components/textarea.js +11 -9
- package/dist/react/components/textarea.js.map +1 -1
- package/dist/react/components/toast.d.ts +4 -8
- package/dist/react/components/toast.d.ts.map +1 -1
- package/dist/react/components/toast.js +26 -47
- package/dist/react/components/toast.js.map +1 -1
- package/dist/react/components/toaster.d.ts.map +1 -1
- package/dist/react/components/toaster.js +5 -5
- package/dist/react/components/toaster.js.map +1 -1
- package/dist/react/components/tooltip.d.ts +2 -2
- package/dist/react/components/tooltip.d.ts.map +1 -1
- package/dist/react/components/tooltip.js +5 -5
- package/dist/react/components/tooltip.js.map +1 -1
- package/dist/react/hooks/use-async-action.d.ts +1 -21
- package/dist/react/hooks/use-async-action.d.ts.map +1 -1
- package/dist/react/hooks/use-async-action.js +3 -11
- package/dist/react/hooks/use-async-action.js.map +1 -1
- package/dist/react/hooks/use-cursor-page.d.ts +1 -63
- package/dist/react/hooks/use-cursor-page.d.ts.map +1 -1
- package/dist/react/hooks/use-cursor-page.js +3 -39
- package/dist/react/hooks/use-cursor-page.js.map +1 -1
- package/dist/react/hooks/use-media-query.js +5 -5
- package/dist/react/hooks/use-media-query.js.map +1 -1
- package/dist/react/hooks/use-paged-list.d.ts +0 -43
- package/dist/react/hooks/use-paged-list.d.ts.map +1 -1
- package/dist/react/hooks/use-paged-list.js +2 -17
- package/dist/react/hooks/use-paged-list.js.map +1 -1
- package/dist/react/hooks/use-return-scroll.d.ts +1 -10
- package/dist/react/hooks/use-return-scroll.d.ts.map +1 -1
- package/dist/react/hooks/use-return-scroll.js +13 -45
- package/dist/react/hooks/use-return-scroll.js.map +1 -1
- package/dist/react/hooks/use-toast.d.ts +3 -11
- package/dist/react/hooks/use-toast.d.ts.map +1 -1
- package/dist/react/hooks/use-toast.js +18 -21
- package/dist/react/hooks/use-toast.js.map +1 -1
- package/dist/react/index.d.ts +74 -74
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +51 -57
- package/dist/react/index.js.map +1 -1
- package/package.json +8 -6
|
@@ -1,82 +1,61 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import * as React from
|
|
3
|
-
import * as ToastPrimitives from
|
|
4
|
-
import { cva } from
|
|
5
|
-
import { X } from
|
|
6
|
-
import { cn } from
|
|
7
|
-
/**
|
|
8
|
-
* ui-core Toasts are consumed by multiple apps.
|
|
9
|
-
*
|
|
10
|
-
* Do NOT rely on app-level CSS (@apply) for critical positioning/visibility.
|
|
11
|
-
* Keep all required styling inline as Tailwind utility classes.
|
|
12
|
-
*/
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import * as ToastPrimitives from '@radix-ui/react-toast';
|
|
4
|
+
import { cva } from 'class-variance-authority';
|
|
5
|
+
import { X } from 'lucide-react';
|
|
6
|
+
import { cn } from '../../lib/utils.js';
|
|
13
7
|
function ToastKeyframes() {
|
|
14
|
-
// Inject a tiny global keyframe used by the optional countdown bar.
|
|
15
8
|
return (_jsx("style", { dangerouslySetInnerHTML: {
|
|
16
9
|
__html: `@keyframes toast-progress{from{transform:scaleX(1)}to{transform:scaleX(0)}}`,
|
|
17
10
|
} }));
|
|
18
11
|
}
|
|
19
|
-
const toastVariants = cva(cn(
|
|
20
|
-
// base
|
|
21
|
-
"pointer-events-auto relative flex w-full items-start justify-between gap-2 overflow-hidden rounded-md border bg-background p-4 text-foreground elevation-raised duration-[var(--motion-base)] ease-[var(--motion-ease)]",
|
|
22
|
-
// radix state/animation
|
|
23
|
-
"data-[state=open]:animate-in data-[state=closed]:animate-out", "data-[state=closed]:fade-out-80 data-[state=open]:fade-in-80", "data-[state=closed]:slide-out-to-top-full data-[state=open]:slide-in-from-top-full", "data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)]", "data-[swipe=cancel]:translate-x-0 data-[swipe=cancel]:transition-transform", "data-[swipe=end]:animate-out data-[swipe=end]:slide-out-to-right-full"), {
|
|
12
|
+
const toastVariants = cva(cn('pointer-events-auto relative flex w-full items-start justify-between gap-2 overflow-hidden rounded-md border bg-background p-4 text-foreground elevation-raised duration-[var(--motion-base)] ease-[var(--motion-ease)]', 'data-[state=open]:animate-in data-[state=closed]:animate-out', 'data-[state=closed]:fade-out-80 data-[state=open]:fade-in-80', 'data-[state=closed]:slide-out-to-top-full data-[state=open]:slide-in-from-top-full', 'data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)]', 'data-[swipe=cancel]:translate-x-0 data-[swipe=cancel]:transition-transform', 'data-[swipe=end]:animate-out data-[swipe=end]:slide-out-to-right-full'), {
|
|
24
13
|
variants: {
|
|
25
14
|
variant: {
|
|
26
|
-
default:
|
|
27
|
-
destructive:
|
|
28
|
-
success:
|
|
29
|
-
warning:
|
|
30
|
-
error:
|
|
15
|
+
default: '',
|
|
16
|
+
destructive: 'border-[color:var(--toast-destructive-border)] bg-[color:var(--toast-destructive)] text-[color:var(--toast-destructive-foreground)]',
|
|
17
|
+
success: 'border-[color:var(--toast-success-border)] bg-[color:var(--toast-success)] text-[color:var(--toast-success-foreground)]',
|
|
18
|
+
warning: 'border-[color:var(--toast-warning-border)] bg-[color:var(--toast-warning)] text-[color:var(--toast-warning-foreground)]',
|
|
19
|
+
error: 'border-[color:var(--toast-destructive-border)] bg-[color:var(--toast-destructive)] text-[color:var(--toast-destructive-foreground)]',
|
|
31
20
|
},
|
|
32
21
|
},
|
|
33
22
|
defaultVariants: {
|
|
34
|
-
variant:
|
|
23
|
+
variant: 'default',
|
|
35
24
|
},
|
|
36
25
|
});
|
|
37
26
|
const ToastProvider = ToastPrimitives.Provider;
|
|
38
|
-
const ToastViewport = React.forwardRef(({ className, ...props }, ref) => (_jsx(ToastPrimitives.Viewport, { ref: ref, className: cn(
|
|
27
|
+
const ToastViewport = React.forwardRef(({ className, ...props }, ref) => (_jsx(ToastPrimitives.Viewport, { ref: ref, className: cn('fixed top-0 left-1/2 -translate-x-1/2 z-[100] flex max-h-screen w-full flex-col gap-2 p-4', 'sm:max-w-[480px] md:max-w-[600px]', className), ...props })));
|
|
39
28
|
ToastViewport.displayName = ToastPrimitives.Viewport.displayName;
|
|
40
29
|
const Toast = React.forwardRef(({ className, variant, duration, dismissible = true, persistent = false, style, children, onOpenChange, ...props }, ref) => {
|
|
41
|
-
// Caller is the source of truth for duration. Persistent toasts disable
|
|
42
|
-
// the auto-dismiss entirely by passing `Infinity` to Radix.
|
|
43
30
|
const effectiveDuration = persistent ? Infinity : (duration ?? 5000);
|
|
44
|
-
// pass duration to Radix AND to CSS countdown bar
|
|
45
31
|
const mergedStyle = {
|
|
46
32
|
...style,
|
|
47
|
-
[
|
|
33
|
+
['--toast-duration']: `${effectiveDuration}ms`,
|
|
48
34
|
};
|
|
49
|
-
return (_jsxs(ToastPrimitives.Root, { ref: ref, duration: effectiveDuration, "data-variant": variant, "data-persistent": persistent ?
|
|
50
|
-
animationName:
|
|
35
|
+
return (_jsxs(ToastPrimitives.Root, { ref: ref, duration: effectiveDuration, "data-variant": variant, "data-persistent": persistent ? '' : undefined, className: cn(toastVariants({ variant }), className), style: mergedStyle, onOpenChange: onOpenChange, ...props, children: [_jsx(ToastKeyframes, {}), children, !persistent ? (_jsx("div", { "aria-hidden": true, className: cn('absolute bottom-0 left-0 h-1 w-full bg-foreground/30', 'origin-left'), style: {
|
|
36
|
+
animationName: 'toast-progress',
|
|
51
37
|
animationDuration: `${effectiveDuration}ms`,
|
|
52
|
-
animationTimingFunction:
|
|
53
|
-
animationFillMode:
|
|
38
|
+
animationTimingFunction: 'linear',
|
|
39
|
+
animationFillMode: 'forwards',
|
|
54
40
|
},
|
|
55
|
-
// Radix's
|
|
56
|
-
//
|
|
57
|
-
// empties we must dismiss regardless of Radix's paused timer, so the
|
|
58
|
-
// toast never lingers after the countdown visibly reaches zero.
|
|
59
|
-
// Only a bar that ran its course counts as empty: a reduced-motion
|
|
60
|
-
// stylesheet that collapses every animation to near zero ends this one
|
|
61
|
-
// at once, and closing then would hide the toast before anyone reads
|
|
62
|
-
// it. Radix's `duration` above is the motion-independent timer that
|
|
63
|
-
// closes the toast in that case.
|
|
41
|
+
// Radix's auto-close timer pauses on hover, focus, and blur but this CSS bar does not, so an emptied bar closes the toast.
|
|
42
|
+
// A reduced-motion stylesheet ends the bar at once; Radix's `duration` closes the toast then.
|
|
64
43
|
onAnimationEnd: (e) => {
|
|
65
|
-
if (e.animationName !==
|
|
44
|
+
if (e.animationName !== 'toast-progress')
|
|
66
45
|
return;
|
|
67
46
|
if (e.elapsedTime * 1000 < effectiveDuration / 2)
|
|
68
47
|
return;
|
|
69
48
|
onOpenChange?.(false);
|
|
70
|
-
} })) : null, dismissible ? (_jsx(ToastPrimitives.Close, { className: cn(
|
|
49
|
+
} })) : null, dismissible ? (_jsx(ToastPrimitives.Close, { className: cn('absolute right-2 top-2 inline-flex h-7 w-7 items-center justify-center rounded-md', 'text-foreground/60 hover:text-foreground', 'focus:outline-hidden focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:ring-offset-background'), "aria-label": "Dismiss toast", children: _jsx(X, { className: "h-4 w-4" }) })) : null] }));
|
|
71
50
|
});
|
|
72
51
|
Toast.displayName = ToastPrimitives.Root.displayName;
|
|
73
52
|
const ToastAction = React.forwardRef(({ className, ...props }, ref) => (_jsx(ToastPrimitives.Action, { ref: ref, className: cn(className), ...props })));
|
|
74
53
|
ToastAction.displayName = ToastPrimitives.Action.displayName;
|
|
75
|
-
const ToastClose = React.forwardRef(({ className, ...props }, ref) => (_jsx(ToastPrimitives.Close, { ref: ref, className: cn(
|
|
54
|
+
const ToastClose = React.forwardRef(({ className, ...props }, ref) => (_jsx(ToastPrimitives.Close, { ref: ref, className: cn('absolute right-2 top-2 inline-flex h-7 w-7 items-center justify-center rounded-md', 'text-foreground/60 hover:text-foreground', 'focus:outline-hidden focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:ring-offset-background', className), ...props })));
|
|
76
55
|
ToastClose.displayName = ToastPrimitives.Close.displayName;
|
|
77
|
-
const ToastTitle = React.forwardRef(({ className, ...props }, ref) => (_jsx(ToastPrimitives.Title, { ref: ref, className: cn(
|
|
56
|
+
const ToastTitle = React.forwardRef(({ className, ...props }, ref) => (_jsx(ToastPrimitives.Title, { ref: ref, className: cn('break-words', className), ...props })));
|
|
78
57
|
ToastTitle.displayName = ToastPrimitives.Title.displayName;
|
|
79
|
-
const ToastDescription = React.forwardRef(({ className, ...props }, ref) => (_jsx(ToastPrimitives.Description, { ref: ref, className: cn(
|
|
58
|
+
const ToastDescription = React.forwardRef(({ className, ...props }, ref) => (_jsx(ToastPrimitives.Description, { ref: ref, className: cn('break-words', className), ...props })));
|
|
80
59
|
ToastDescription.displayName = ToastPrimitives.Description.displayName;
|
|
81
|
-
export { ToastProvider, ToastViewport, Toast, ToastTitle, ToastDescription, ToastClose, ToastAction };
|
|
60
|
+
export { ToastProvider, ToastViewport, Toast, ToastTitle, ToastDescription, ToastClose, ToastAction, };
|
|
82
61
|
//# sourceMappingURL=toast.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toast.js","sourceRoot":"","sources":["../../../src/react/components/toast.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,eAAe,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,GAAG,EAAqB,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,CAAC,EAAE,MAAM,cAAc,CAAC;AAEjC,OAAO,EAAE,EAAE,EAAE,MAAM,oBAAoB,CAAC;AAExC;;;;;GAKG;AACH,SAAS,cAAc;IACrB,oEAAoE;IACpE,OAAO,CACL,gBACE,uBAAuB,EAAE;YACvB,MAAM,EAAE,6EAA6E;SACtF,GACD,CACH,CAAC;AACJ,CAAC;AAED,MAAM,aAAa,GAAG,GAAG,CACvB,EAAE;AACA,OAAO;AACP,yNAAyN;AACzN,wBAAwB;AACxB,8DAA8D,EAC9D,8DAA8D,EAC9D,oFAAoF,EACpF,iEAAiE,EACjE,4EAA4E,EAC5E,uEAAuE,CACxE,EACD;IACE,QAAQ,EAAE;QACR,OAAO,EAAE;YACP,OAAO,EAAE,EAAE;YACX,WAAW,EAAE,qIAAqI;YAClJ,OAAO,EAAE,yHAAyH;YAClI,OAAO,EAAE,yHAAyH;YAClI,KAAK,EAAE,qIAAqI;SAC7I;KACF;IACD,eAAe,EAAE;QACf,OAAO,EAAE,SAAS;KACnB;CACF,CACF,CAAC;AAEF,MAAM,aAAa,GAAG,eAAe,CAAC,QAAQ,CAAC;AAE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toast\";\nimport { cva, type VariantProps } from \"class-variance-authority\";\nimport { X } from \"lucide-react\";\n\nimport { cn } from \"../../lib/utils.js\";\n\n/**\n * ui-core Toasts are consumed by multiple apps.\n *\n * Do NOT rely on app-level CSS (@apply) for critical positioning/visibility.\n * Keep all required styling inline as Tailwind utility classes.\n */\nfunction ToastKeyframes() {\n // Inject a tiny global keyframe used by the optional countdown bar.\n return (\n <style\n dangerouslySetInnerHTML={{\n __html: `@keyframes toast-progress{from{transform:scaleX(1)}to{transform:scaleX(0)}}`,\n }}\n />\n );\n}\n\nconst toastVariants = cva(\n cn(\n // base\n \"pointer-events-auto relative flex w-full items-start justify-between gap-2 overflow-hidden rounded-md border bg-background p-4 text-foreground elevation-raised duration-[var(--motion-base)] ease-[var(--motion-ease)]\",\n // radix state/animation\n \"data-[state=open]:animate-in data-[state=closed]:animate-out\",\n \"data-[state=closed]:fade-out-80 data-[state=open]:fade-in-80\",\n \"data-[state=closed]:slide-out-to-top-full data-[state=open]:slide-in-from-top-full\",\n \"data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)]\",\n \"data-[swipe=cancel]:translate-x-0 data-[swipe=cancel]:transition-transform\",\n \"data-[swipe=end]:animate-out data-[swipe=end]:slide-out-to-right-full\"\n ),\n {\n variants: {\n variant: {\n default: \"\",\n destructive: \"border-[color:var(--toast-destructive-border)] bg-[color:var(--toast-destructive)] text-[color:var(--toast-destructive-foreground)]\",\n success: \"border-[color:var(--toast-success-border)] bg-[color:var(--toast-success)] text-[color:var(--toast-success-foreground)]\",\n warning: \"border-[color:var(--toast-warning-border)] bg-[color:var(--toast-warning)] text-[color:var(--toast-warning-foreground)]\",\n error: \"border-[color:var(--toast-destructive-border)] bg-[color:var(--toast-destructive)] text-[color:var(--toast-destructive-foreground)]\",\n },\n },\n defaultVariants: {\n variant: \"default\",\n },\n }\n);\n\nconst ToastProvider = ToastPrimitives.Provider;\n\nconst ToastViewport = React.forwardRef<\n React.ElementRef<typeof ToastPrimitives.Viewport>,\n React.ComponentPropsWithoutRef<typeof ToastPrimitives.Viewport>\n>(({ className, ...props }, ref) => (\n <ToastPrimitives.Viewport\n ref={ref}\n className={cn(\n \"fixed top-0 left-1/2 -translate-x-1/2 z-[100] flex max-h-screen w-full flex-col gap-2 p-4\",\n \"sm:max-w-[480px] md:max-w-[600px]\",\n className\n )}\n {...props}\n />\n));\nToastViewport.displayName = ToastPrimitives.Viewport.displayName;\n\ntype ToastRootProps = React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> &\n VariantProps<typeof toastVariants> & {\n /** ms; ignored when `persistent` is true */\n duration?: number;\n /** show X button */\n dismissible?: boolean;\n /** When true: no auto-dismiss, no countdown bar. */\n persistent?: boolean;\n };\n\nconst Toast = React.forwardRef<React.ElementRef<typeof ToastPrimitives.Root>, ToastRootProps>(\n ({ className, variant, duration, dismissible = true, persistent = false, style, children, onOpenChange, ...props }, ref) => {\n // Caller is the source of truth for duration. Persistent toasts disable\n // the auto-dismiss entirely by passing `Infinity` to Radix.\n const effectiveDuration = persistent ? Infinity : (duration ?? 5000);\n // pass duration to Radix AND to CSS countdown bar\n const mergedStyle: React.CSSProperties = {\n ...(style as React.CSSProperties),\n [\"--toast-duration\" as any]: `${effectiveDuration}ms`,\n };\n\n return (\n <ToastPrimitives.Root\n ref={ref}\n duration={effectiveDuration}\n data-variant={variant}\n data-persistent={persistent ? \"\" : undefined}\n className={cn(toastVariants({ variant }), className)}\n style={mergedStyle}\n onOpenChange={onOpenChange}\n {...props}\n >\n <ToastKeyframes />\n {children}\n\n {/* countdown bar — hidden entirely for persistent toasts */}\n {!persistent ? (\n <div\n aria-hidden\n className={cn(\"absolute bottom-0 left-0 h-1 w-full bg-foreground/30\", \"origin-left\")}\n style={{\n animationName: \"toast-progress\",\n animationDuration: `${effectiveDuration}ms`,\n animationTimingFunction: \"linear\",\n animationFillMode: \"forwards\",\n }}\n // Radix's own auto-close timer PAUSES on pointer-over the viewport,\n // focus, and window-blur — but this CSS bar does not. When the bar\n // empties we must dismiss regardless of Radix's paused timer, so the\n // toast never lingers after the countdown visibly reaches zero.\n // Only a bar that ran its course counts as empty: a reduced-motion\n // stylesheet that collapses every animation to near zero ends this one\n // at once, and closing then would hide the toast before anyone reads\n // it. Radix's `duration` above is the motion-independent timer that\n // closes the toast in that case.\n onAnimationEnd={(e) => {\n if (e.animationName !== \"toast-progress\") return;\n if (e.elapsedTime * 1000 < effectiveDuration / 2) return;\n onOpenChange?.(false);\n }}\n />\n ) : null}\n\n {/* dismiss button */}\n {dismissible ? (\n <ToastPrimitives.Close\n className={cn(\n \"absolute right-2 top-2 inline-flex h-7 w-7 items-center justify-center rounded-md\",\n \"text-foreground/60 hover:text-foreground\",\n \"focus:outline-hidden focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:ring-offset-background\"\n )}\n aria-label=\"Dismiss toast\"\n >\n <X className=\"h-4 w-4\" />\n </ToastPrimitives.Close>\n ) : null}\n </ToastPrimitives.Root>\n );\n }\n);\nToast.displayName = ToastPrimitives.Root.displayName;\n\nconst ToastAction = React.forwardRef<\n React.ElementRef<typeof ToastPrimitives.Action>,\n React.ComponentPropsWithoutRef<typeof ToastPrimitives.Action>\n>(({ className, ...props }, ref) => (\n <ToastPrimitives.Action ref={ref} className={cn(className)} {...props} />\n));\nToastAction.displayName = ToastPrimitives.Action.displayName;\n\nconst ToastClose = React.forwardRef<\n React.ElementRef<typeof ToastPrimitives.Close>,\n React.ComponentPropsWithoutRef<typeof ToastPrimitives.Close>\n>(({ className, ...props }, ref) => (\n <ToastPrimitives.Close\n ref={ref}\n className={cn(\n \"absolute right-2 top-2 inline-flex h-7 w-7 items-center justify-center rounded-md\",\n \"text-foreground/60 hover:text-foreground\",\n \"focus:outline-hidden focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:ring-offset-background\",\n className\n )}\n {...props}\n />\n));\nToastClose.displayName = ToastPrimitives.Close.displayName;\n\nconst ToastTitle = React.forwardRef<\n React.ElementRef<typeof ToastPrimitives.Title>,\n React.ComponentPropsWithoutRef<typeof ToastPrimitives.Title>\n>(({ className, ...props }, ref) => (\n <ToastPrimitives.Title ref={ref} className={cn(\"break-words\", className)} {...props} />\n));\nToastTitle.displayName = ToastPrimitives.Title.displayName;\n\nconst ToastDescription = React.forwardRef<\n React.ElementRef<typeof ToastPrimitives.Description>,\n React.ComponentPropsWithoutRef<typeof ToastPrimitives.Description>\n>(({ className, ...props }, ref) => (\n <ToastPrimitives.Description ref={ref} className={cn(\"break-words\", className)} {...props} />\n));\nToastDescription.displayName = ToastPrimitives.Description.displayName;\n\n/** Exported types for consumers */\nexport type ToastProps = React.ComponentPropsWithoutRef<typeof Toast>;\nexport type ToastActionElement = React.ReactElement<typeof ToastAction>;\n\nexport { ToastProvider, ToastViewport, Toast, ToastTitle, ToastDescription, ToastClose, ToastAction };\n"]}
|
|
1
|
+
{"version":3,"file":"toast.js","sourceRoot":"","sources":["../../../src/react/components/toast.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,eAAe,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,GAAG,EAAqB,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,CAAC,EAAE,MAAM,cAAc,CAAC;AAEjC,OAAO,EAAE,EAAE,EAAE,MAAM,oBAAoB,CAAC;AAExC,SAAS,cAAc;IACrB,OAAO,CACL,gBACE,uBAAuB,EAAE;YACvB,MAAM,EAAE,6EAA6E;SACtF,GACD,CACH,CAAC;AACJ,CAAC;AAED,MAAM,aAAa,GAAG,GAAG,CACvB,EAAE,CACA,yNAAyN,EACzN,8DAA8D,EAC9D,8DAA8D,EAC9D,oFAAoF,EACpF,iEAAiE,EACjE,4EAA4E,EAC5E,uEAAuE,CACxE,EACD;IACE,QAAQ,EAAE;QACR,OAAO,EAAE;YACP,OAAO,EAAE,EAAE;YACX,WAAW,EACT,qIAAqI;YACvI,OAAO,EACL,yHAAyH;YAC3H,OAAO,EACL,yHA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AAC,MAAM,CAAC,WAAW,CAAC;AAE7D,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CAGjC,CAAC,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,GAAG,EAAE,EAAE,CAAC,CAClC,KAAC,eAAe,CAAC,KAAK,IACpB,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,EAAE,CACX,mFAAmF,EACnF,0CAA0C,EAC1C,oGAAoG,EACpG,SAAS,CACV,KACG,KAAK,GACT,CACH,CAAC,CAAC;AACH,UAAU,CAAC,WAAW,GAAG,eAAe,CAAC,KAAK,CAAC,WAAW,CAAC;AAE3D,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CAGjC,CAAC,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,GAAG,EAAE,EAAE,CAAC,CAClC,KAAC,eAAe,CAAC,KAAK,IAAC,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,CAAC,aAAa,EAAE,SAAS,CAAC,KAAM,KAAK,GAAI,CACxF,CAAC,CAAC;AACH,UAAU,CAAC,WAAW,GAAG,eAAe,CAAC,KAAK,CAAC,WAAW,CAAC;AAE3D,MAAM,gBAAgB,GAAG,KAAK,CAAC,UAAU,CAGvC,CAAC,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,GAAG,EAAE,EAAE,CAAC,CAClC,KAAC,eAAe,CAAC,WAAW,IAAC,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,CAAC,aAAa,EAAE,SAAS,CAAC,KAAM,KAAK,GAAI,CAC9F,CAAC,CAAC;AACH,gBAAgB,CAAC,WAAW,GAAG,eAAe,CAAC,WAAW,CAAC,WAAW,CAAC;AAKvE,OAAO,EACL,aAAa,EACb,aAAa,EACb,KAAK,EACL,UAAU,EACV,gBAAgB,EAChB,UAAU,EACV,WAAW,GACZ,CAAC","sourcesContent":["import * as React from 'react';\nimport * as ToastPrimitives from '@radix-ui/react-toast';\nimport { cva, type VariantProps } from 'class-variance-authority';\nimport { X } from 'lucide-react';\n\nimport { cn } from '../../lib/utils.js';\n\nfunction ToastKeyframes() {\n return (\n <style\n dangerouslySetInnerHTML={{\n __html: `@keyframes toast-progress{from{transform:scaleX(1)}to{transform:scaleX(0)}}`,\n }}\n />\n );\n}\n\nconst toastVariants = cva(\n cn(\n 'pointer-events-auto relative flex w-full items-start justify-between gap-2 overflow-hidden rounded-md border bg-background p-4 text-foreground elevation-raised duration-[var(--motion-base)] ease-[var(--motion-ease)]',\n 'data-[state=open]:animate-in data-[state=closed]:animate-out',\n 'data-[state=closed]:fade-out-80 data-[state=open]:fade-in-80',\n 'data-[state=closed]:slide-out-to-top-full data-[state=open]:slide-in-from-top-full',\n 'data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)]',\n 'data-[swipe=cancel]:translate-x-0 data-[swipe=cancel]:transition-transform',\n 'data-[swipe=end]:animate-out data-[swipe=end]:slide-out-to-right-full',\n ),\n {\n variants: {\n variant: {\n default: '',\n destructive:\n 'border-[color:var(--toast-destructive-border)] bg-[color:var(--toast-destructive)] text-[color:var(--toast-destructive-foreground)]',\n success:\n 'border-[color:var(--toast-success-border)] bg-[color:var(--toast-success)] text-[color:var(--toast-success-foreground)]',\n warning:\n 'border-[color:var(--toast-warning-border)] bg-[color:var(--toast-warning)] text-[color:var(--toast-warning-foreground)]',\n error:\n 'border-[color:var(--toast-destructive-border)] bg-[color:var(--toast-destructive)] text-[color:var(--toast-destructive-foreground)]',\n },\n },\n defaultVariants: {\n variant: 'default',\n },\n },\n);\n\nconst ToastProvider = ToastPrimitives.Provider;\n\nconst ToastViewport = React.forwardRef<\n React.ElementRef<typeof ToastPrimitives.Viewport>,\n React.ComponentPropsWithoutRef<typeof ToastPrimitives.Viewport>\n>(({ className, ...props }, ref) => (\n <ToastPrimitives.Viewport\n ref={ref}\n className={cn(\n 'fixed top-0 left-1/2 -translate-x-1/2 z-[100] flex max-h-screen w-full flex-col gap-2 p-4',\n 'sm:max-w-[480px] md:max-w-[600px]',\n className,\n )}\n {...props}\n />\n));\nToastViewport.displayName = ToastPrimitives.Viewport.displayName;\n\ntype ToastRootProps = React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> &\n VariantProps<typeof toastVariants> & {\n duration?: number;\n dismissible?: boolean;\n persistent?: boolean;\n };\n\nconst Toast = React.forwardRef<React.ElementRef<typeof ToastPrimitives.Root>, ToastRootProps>(\n (\n {\n className,\n variant,\n duration,\n dismissible = true,\n persistent = false,\n style,\n children,\n onOpenChange,\n ...props\n },\n ref,\n ) => {\n const effectiveDuration = persistent ? Infinity : (duration ?? 5000);\n const mergedStyle: React.CSSProperties = {\n ...(style as React.CSSProperties),\n ['--toast-duration' as any]: `${effectiveDuration}ms`,\n };\n\n return (\n <ToastPrimitives.Root\n ref={ref}\n duration={effectiveDuration}\n data-variant={variant}\n data-persistent={persistent ? '' : undefined}\n className={cn(toastVariants({ variant }), className)}\n style={mergedStyle}\n onOpenChange={onOpenChange}\n {...props}\n >\n <ToastKeyframes />\n {children}\n\n {!persistent ? (\n <div\n aria-hidden\n className={cn('absolute bottom-0 left-0 h-1 w-full bg-foreground/30', 'origin-left')}\n style={{\n animationName: 'toast-progress',\n animationDuration: `${effectiveDuration}ms`,\n animationTimingFunction: 'linear',\n animationFillMode: 'forwards',\n }}\n // Radix's auto-close timer pauses on hover, focus, and blur but this CSS bar does not, so an emptied bar closes the toast.\n // A reduced-motion stylesheet ends the bar at once; Radix's `duration` closes the toast then.\n onAnimationEnd={(e) => {\n if (e.animationName !== 'toast-progress') return;\n if (e.elapsedTime * 1000 < effectiveDuration / 2) return;\n onOpenChange?.(false);\n }}\n />\n ) : null}\n\n {dismissible ? (\n <ToastPrimitives.Close\n className={cn(\n 'absolute right-2 top-2 inline-flex h-7 w-7 items-center justify-center rounded-md',\n 'text-foreground/60 hover:text-foreground',\n 'focus:outline-hidden focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:ring-offset-background',\n )}\n aria-label=\"Dismiss toast\"\n >\n <X className=\"h-4 w-4\" />\n </ToastPrimitives.Close>\n ) : null}\n </ToastPrimitives.Root>\n );\n },\n);\nToast.displayName = ToastPrimitives.Root.displayName;\n\nconst ToastAction = React.forwardRef<\n React.ElementRef<typeof ToastPrimitives.Action>,\n React.ComponentPropsWithoutRef<typeof ToastPrimitives.Action>\n>(({ className, ...props }, ref) => (\n <ToastPrimitives.Action ref={ref} className={cn(className)} {...props} />\n));\nToastAction.displayName = ToastPrimitives.Action.displayName;\n\nconst ToastClose = React.forwardRef<\n React.ElementRef<typeof ToastPrimitives.Close>,\n React.ComponentPropsWithoutRef<typeof ToastPrimitives.Close>\n>(({ className, ...props }, ref) => (\n <ToastPrimitives.Close\n ref={ref}\n className={cn(\n 'absolute right-2 top-2 inline-flex h-7 w-7 items-center justify-center rounded-md',\n 'text-foreground/60 hover:text-foreground',\n 'focus:outline-hidden focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:ring-offset-background',\n className,\n )}\n {...props}\n />\n));\nToastClose.displayName = ToastPrimitives.Close.displayName;\n\nconst ToastTitle = React.forwardRef<\n React.ElementRef<typeof ToastPrimitives.Title>,\n React.ComponentPropsWithoutRef<typeof ToastPrimitives.Title>\n>(({ className, ...props }, ref) => (\n <ToastPrimitives.Title ref={ref} className={cn('break-words', className)} {...props} />\n));\nToastTitle.displayName = ToastPrimitives.Title.displayName;\n\nconst ToastDescription = React.forwardRef<\n React.ElementRef<typeof ToastPrimitives.Description>,\n React.ComponentPropsWithoutRef<typeof ToastPrimitives.Description>\n>(({ className, ...props }, ref) => (\n <ToastPrimitives.Description ref={ref} className={cn('break-words', className)} {...props} />\n));\nToastDescription.displayName = ToastPrimitives.Description.displayName;\n\nexport type ToastProps = React.ComponentPropsWithoutRef<typeof Toast>;\nexport type ToastActionElement = React.ReactElement<typeof ToastAction>;\n\nexport {\n ToastProvider,\n ToastViewport,\n Toast,\n ToastTitle,\n ToastDescription,\n ToastClose,\n ToastAction,\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toaster.d.ts","sourceRoot":"","sources":["../../../src/react/components/toaster.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"toaster.d.ts","sourceRoot":"","sources":["../../../src/react/components/toaster.tsx"],"names":[],"mappings":"AAaA,wBAAgB,OAAO,gCAiDtB"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { Toast, ToastClose, ToastDescription, ToastProvider, ToastTitle, ToastViewport } from
|
|
4
|
-
import { useToast } from
|
|
3
|
+
import { Toast, ToastClose, ToastDescription, ToastProvider, ToastTitle, ToastViewport, } from './toast.js';
|
|
4
|
+
import { useToast } from '../hooks/use-toast.js';
|
|
5
5
|
export function Toaster() {
|
|
6
6
|
const { toasts } = useToast();
|
|
7
7
|
return (_jsxs(ToastProvider, { swipeDirection: "right", swipeThreshold: 32, children: [toasts.map((t) => {
|
|
8
8
|
const { id, title, description, action, variant, duration, dismissible, persistent, open, onOpenChange, ...props } = t;
|
|
9
|
-
const v = variant ===
|
|
10
|
-
return (_jsxs(Toast, { open: open, onOpenChange: onOpenChange, variant: v, duration: duration, dismissible: dismissible ?? true, persistent: persistent ?? false, ...props, children: [_jsxs("div", { className: "grid gap-1 pr-10", children: [title ? _jsx(ToastTitle, { className: "font-bold", children: title }) : null, description ? _jsx(ToastDescription, { className: "font-bold", children: description }) : null] }), action, _jsx(ToastClose, {})] }, id));
|
|
9
|
+
const v = variant === 'error' ? 'destructive' : (variant ?? 'default');
|
|
10
|
+
return (_jsxs(Toast, { open: open, onOpenChange: onOpenChange, variant: v, duration: duration, dismissible: dismissible ?? true, persistent: persistent ?? false, ...props, children: [_jsxs("div", { className: "grid gap-1 pr-10", children: [title ? _jsx(ToastTitle, { className: "font-bold", children: title }) : null, description ? (_jsx(ToastDescription, { className: "font-bold", children: description })) : null] }), action, _jsx(ToastClose, {})] }, id));
|
|
11
11
|
}), _jsx(ToastViewport, {})] }));
|
|
12
12
|
}
|
|
13
13
|
//# sourceMappingURL=toaster.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toaster.js","sourceRoot":"","sources":["../../../src/react/components/toaster.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,
|
|
1
|
+
{"version":3,"file":"toaster.js","sourceRoot":"","sources":["../../../src/react/components/toaster.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EACL,KAAK,EACL,UAAU,EACV,gBAAgB,EAChB,aAAa,EACb,UAAU,EACV,aAAa,GACd,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAGjD,MAAM,UAAU,OAAO;IACrB,MAAM,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAgC,CAAC;IAE5D,OAAO,CACL,MAAC,aAAa,IAAC,cAAc,EAAC,OAAO,EAAC,cAAc,EAAE,EAAE,aACrD,MAAM,CAAC,GAAG,CAAC,CAAC,CAAe,EAAE,EAAE;gBAC9B,MAAM,EACJ,EAAE,EACF,KAAK,EACL,WAAW,EACX,MAAM,EACN,OAAO,EACP,QAAQ,EACR,WAAW,EACX,UAAU,EACV,IAAI,EACJ,YAAY,EACZ,GAAG,KAAK,EACT,GAAG,CAAC,CAAC;gBAEN,MAAM,CAAC,GACL,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,OAAO,IAAI,SAAS,CAAC,CAAC;gBAE/D,OAAO,CACL,MAAC,KAAK,IAEJ,IAAI,EAAE,IAAI,EACV,YAAY,EAAE,YAAY,EAC1B,OAAO,EAAE,CAAQ,EACjB,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,WAAW,IAAI,IAAI,EAChC,UAAU,EAAE,UAAU,IAAI,KAAK,KAC1B,KAAa,aAElB,eAAK,SAAS,EAAC,kBAAkB,aAC9B,KAAK,CAAC,CAAC,CAAC,KAAC,UAAU,IAAC,SAAS,EAAC,WAAW,YAAE,KAAK,GAAc,CAAC,CAAC,CAAC,IAAI,EACrE,WAAW,CAAC,CAAC,CAAC,CACb,KAAC,gBAAgB,IAAC,SAAS,EAAC,WAAW,YAAE,WAAW,GAAoB,CACzE,CAAC,CAAC,CAAC,IAAI,IACJ,EACL,MAAM,EACP,KAAC,UAAU,KAAG,KAhBT,EAAE,CAiBD,CACT,CAAC;YACJ,CAAC,CAAC,EAEF,KAAC,aAAa,KAAG,IACH,CACjB,CAAC;AACJ,CAAC","sourcesContent":["'use client';\n\nimport {\n Toast,\n ToastClose,\n ToastDescription,\n ToastProvider,\n ToastTitle,\n ToastViewport,\n} from './toast.js';\nimport { useToast } from '../hooks/use-toast.js';\nimport type { ToasterToast, ToastVariant } from '../hooks/use-toast.js';\n\nexport function Toaster() {\n const { toasts } = useToast() as { toasts: ToasterToast[] };\n\n return (\n <ToastProvider swipeDirection=\"right\" swipeThreshold={32}>\n {toasts.map((t: ToasterToast) => {\n const {\n id,\n title,\n description,\n action,\n variant,\n duration,\n dismissible,\n persistent,\n open,\n onOpenChange,\n ...props\n } = t;\n\n const v: ToastVariant | 'destructive' =\n variant === 'error' ? 'destructive' : (variant ?? 'default');\n\n return (\n <Toast\n key={id}\n open={open}\n onOpenChange={onOpenChange}\n variant={v as any}\n duration={duration}\n dismissible={dismissible ?? true}\n persistent={persistent ?? false}\n {...(props as any)}\n >\n <div className=\"grid gap-1 pr-10\">\n {title ? <ToastTitle className=\"font-bold\">{title}</ToastTitle> : null}\n {description ? (\n <ToastDescription className=\"font-bold\">{description}</ToastDescription>\n ) : null}\n </div>\n {action}\n <ToastClose />\n </Toast>\n );\n })}\n\n <ToastViewport />\n </ToastProvider>\n );\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import * as TooltipPrimitive from
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import * as TooltipPrimitive from '@radix-ui/react-tooltip';
|
|
3
3
|
declare const TooltipProvider: React.FC<TooltipPrimitive.TooltipProviderProps>;
|
|
4
4
|
declare const Tooltip: React.FC<TooltipPrimitive.TooltipProps>;
|
|
5
5
|
declare const TooltipTrigger: React.ForwardRefExoticComponent<TooltipPrimitive.TooltipTriggerProps & React.RefAttributes<HTMLButtonElement>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tooltip.d.ts","sourceRoot":"","sources":["../../../src/react/components/tooltip.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"tooltip.d.ts","sourceRoot":"","sources":["../../../src/react/components/tooltip.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,gBAAgB,MAAM,yBAAyB,CAAC;AAI5D,QAAA,MAAM,eAAe,iDAA4B,CAAC;AAClD,QAAA,MAAM,OAAO,yCAAwB,CAAC;AACtC,QAAA,MAAM,cAAc,gHAA2B,CAAC;AAEhD,QAAA,MAAM,cAAc,gKAalB,CAAC;AAGH,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import * as React from
|
|
4
|
-
import * as TooltipPrimitive from
|
|
5
|
-
import { cn } from
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import * as TooltipPrimitive from '@radix-ui/react-tooltip';
|
|
5
|
+
import { cn } from '../../lib/utils.js';
|
|
6
6
|
const TooltipProvider = TooltipPrimitive.Provider;
|
|
7
7
|
const Tooltip = TooltipPrimitive.Root;
|
|
8
8
|
const TooltipTrigger = TooltipPrimitive.Trigger;
|
|
9
|
-
const TooltipContent = React.forwardRef(({ className, sideOffset = 4, ...props }, ref) => (_jsx(TooltipPrimitive.Content, { ref: ref, sideOffset: sideOffset, className: cn(
|
|
9
|
+
const TooltipContent = React.forwardRef(({ className, sideOffset = 4, ...props }, ref) => (_jsx(TooltipPrimitive.Content, { ref: ref, sideOffset: sideOffset, className: cn('z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground elevation-popover duration-[var(--motion-fast)] ease-[var(--motion-ease)] animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2', className), ...props })));
|
|
10
10
|
TooltipContent.displayName = TooltipPrimitive.Content.displayName;
|
|
11
11
|
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider };
|
|
12
12
|
//# sourceMappingURL=tooltip.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tooltip.js","sourceRoot":"","sources":["../../../src/react/components/tooltip.tsx"],"names":[],"mappings":"AAAA,YAAY,
|
|
1
|
+
{"version":3,"file":"tooltip.js","sourceRoot":"","sources":["../../../src/react/components/tooltip.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,gBAAgB,MAAM,yBAAyB,CAAC;AAE5D,OAAO,EAAE,EAAE,EAAE,MAAM,oBAAoB,CAAC;AAExC,MAAM,eAAe,GAAG,gBAAgB,CAAC,QAAQ,CAAC;AAClD,MAAM,OAAO,GAAG,gBAAgB,CAAC,IAAI,CAAC;AACtC,MAAM,cAAc,GAAG,gBAAgB,CAAC,OAAO,CAAC;AAEhD,MAAM,cAAc,GAAG,KAAK,CAAC,UAAU,CAGrC,CAAC,EAAE,SAAS,EAAE,UAAU,GAAG,CAAC,EAAE,GAAG,KAAK,EAAE,EAAE,GAAG,EAAE,EAAE,CAAC,CAClD,KAAC,gBAAgB,CAAC,OAAO,IACvB,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,EAAE,CACX,ocAAoc,EACpc,SAAS,CACV,KACG,KAAK,GACT,CACH,CAAC,CAAC;AACH,cAAc,CAAC,WAAW,GAAG,gBAAgB,CAAC,OAAO,CAAC,WAAW,CAAC;AAElE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,CAAC","sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport * as TooltipPrimitive from '@radix-ui/react-tooltip';\n\nimport { cn } from '../../lib/utils.js';\n\nconst TooltipProvider = TooltipPrimitive.Provider;\nconst Tooltip = TooltipPrimitive.Root;\nconst TooltipTrigger = TooltipPrimitive.Trigger;\n\nconst TooltipContent = React.forwardRef<\n React.ElementRef<typeof TooltipPrimitive.Content>,\n React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>\n>(({ className, sideOffset = 4, ...props }, ref) => (\n <TooltipPrimitive.Content\n ref={ref}\n sideOffset={sideOffset}\n className={cn(\n 'z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground elevation-popover duration-[var(--motion-fast)] ease-[var(--motion-ease)] animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',\n className,\n )}\n {...props}\n />\n));\nTooltipContent.displayName = TooltipPrimitive.Content.displayName;\n\nexport { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider };\n"]}
|
|
@@ -1,30 +1,10 @@
|
|
|
1
1
|
export interface UseAsyncActionOptions {
|
|
2
|
-
/**
|
|
3
|
-
* Receives anything the action throws. REQUIRED, so every call site decides what a
|
|
4
|
-
* failure means (surface it, capture it, or accept that another layer already did):
|
|
5
|
-
* `run` itself never rejects, so a fire-and-forget `onClick={() => void run()}` can
|
|
6
|
-
* never become an unhandled rejection.
|
|
7
|
-
*/
|
|
8
2
|
onError: (error: unknown) => void;
|
|
9
3
|
}
|
|
10
4
|
export interface AsyncAction<TArgs extends unknown[]> {
|
|
11
|
-
/**
|
|
12
|
-
* Starts the action unless one is already in flight — a repeat call while pending is
|
|
13
|
-
* ignored. Resolves once the action settles: `true` when it completed, `false` when it
|
|
14
|
-
* was ignored or threw. Never rejects.
|
|
15
|
-
*/
|
|
16
5
|
run: (...args: TArgs) => Promise<boolean>;
|
|
17
|
-
/** True from the moment `run` starts the action until it settles. */
|
|
18
6
|
pending: boolean;
|
|
19
7
|
}
|
|
20
|
-
/**
|
|
21
|
-
* Pending state + repeat guard for async work that is NOT a React Query mutation
|
|
22
|
-
* (a local media step, a sign-out, an awaited navigation). Feed `pending` to the
|
|
23
|
-
* control's own `pending` prop. Server writes stay mutations — this hook does not
|
|
24
|
-
* replace the data layer's one mutation path.
|
|
25
|
-
*
|
|
26
|
-
* The guard is a ref, not the state, so two clicks inside one frame cannot both start
|
|
27
|
-
* the action.
|
|
28
|
-
*/
|
|
8
|
+
/** The guard is a ref, not state, so two clicks inside one frame cannot both start the action. */
|
|
29
9
|
export declare function useAsyncAction<TArgs extends unknown[]>(action: (...args: TArgs) => Promise<unknown>, options: UseAsyncActionOptions): AsyncAction<TArgs>;
|
|
30
10
|
//# sourceMappingURL=use-async-action.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-async-action.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/use-async-action.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,qBAAqB;IACpC
|
|
1
|
+
{"version":3,"file":"use-async-action.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/use-async-action.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CACnC;AAED,MAAM,WAAW,WAAW,CAAC,KAAK,SAAS,OAAO,EAAE;IAClD,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAC1C,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,kGAAkG;AAClG,wBAAgB,cAAc,CAAC,KAAK,SAAS,OAAO,EAAE,EACpD,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,CAAC,OAAO,CAAC,EAC5C,OAAO,EAAE,qBAAqB,GAC7B,WAAW,CAAC,KAAK,CAAC,CAyBpB"}
|
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import { useCallback, useRef, useState } from
|
|
3
|
-
/**
|
|
4
|
-
* Pending state + repeat guard for async work that is NOT a React Query mutation
|
|
5
|
-
* (a local media step, a sign-out, an awaited navigation). Feed `pending` to the
|
|
6
|
-
* control's own `pending` prop. Server writes stay mutations — this hook does not
|
|
7
|
-
* replace the data layer's one mutation path.
|
|
8
|
-
*
|
|
9
|
-
* The guard is a ref, not the state, so two clicks inside one frame cannot both start
|
|
10
|
-
* the action.
|
|
11
|
-
*/
|
|
1
|
+
'use client';
|
|
2
|
+
import { useCallback, useRef, useState } from 'react';
|
|
3
|
+
/** The guard is a ref, not state, so two clicks inside one frame cannot both start the action. */
|
|
12
4
|
export function useAsyncAction(action, options) {
|
|
13
5
|
const [pending, setPending] = useState(false);
|
|
14
6
|
const inFlightRef = useRef(false);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-async-action.js","sourceRoot":"","sources":["../../../src/react/hooks/use-async-action.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"use-async-action.js","sourceRoot":"","sources":["../../../src/react/hooks/use-async-action.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAWtD,kGAAkG;AAClG,MAAM,UAAU,cAAc,CAC5B,MAA4C,EAC5C,OAA8B;IAE9B,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9C,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAClC,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IACjC,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC3C,SAAS,CAAC,OAAO,GAAG,MAAM,CAAC;IAC3B,UAAU,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAErC,MAAM,GAAG,GAAG,WAAW,CAAC,KAAK,EAAE,GAAG,IAAW,EAAoB,EAAE;QACjE,IAAI,WAAW,CAAC,OAAO;YAAE,OAAO,KAAK,CAAC;QACtC,WAAW,CAAC,OAAO,GAAG,IAAI,CAAC;QAC3B,UAAU,CAAC,IAAI,CAAC,CAAC;QACjB,IAAI,CAAC;YACH,MAAM,SAAS,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;YACjC,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAC1B,OAAO,KAAK,CAAC;QACf,CAAC;gBAAS,CAAC;YACT,WAAW,CAAC,OAAO,GAAG,KAAK,CAAC;YAC5B,UAAU,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;IACH,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC;AAC1B,CAAC","sourcesContent":["'use client';\n\nimport { useCallback, useRef, useState } from 'react';\n\nexport interface UseAsyncActionOptions {\n onError: (error: unknown) => void;\n}\n\nexport interface AsyncAction<TArgs extends unknown[]> {\n run: (...args: TArgs) => Promise<boolean>;\n pending: boolean;\n}\n\n/** The guard is a ref, not state, so two clicks inside one frame cannot both start the action. */\nexport function useAsyncAction<TArgs extends unknown[]>(\n action: (...args: TArgs) => Promise<unknown>,\n options: UseAsyncActionOptions,\n): AsyncAction<TArgs> {\n const [pending, setPending] = useState(false);\n const inFlightRef = useRef(false);\n const actionRef = useRef(action);\n const onErrorRef = useRef(options.onError);\n actionRef.current = action;\n onErrorRef.current = options.onError;\n\n const run = useCallback(async (...args: TArgs): Promise<boolean> => {\n if (inFlightRef.current) return false;\n inFlightRef.current = true;\n setPending(true);\n try {\n await actionRef.current(...args);\n return true;\n } catch (error) {\n onErrorRef.current(error);\n return false;\n } finally {\n inFlightRef.current = false;\n setPending(false);\n }\n }, []);\n\n return { run, pending };\n}\n"]}
|
|
@@ -1,77 +1,15 @@
|
|
|
1
|
-
import type { ListPaginationState } from
|
|
2
|
-
/**
|
|
3
|
-
* Render-time page state for a cursor feed, shaped as {@link ListPaginationState}
|
|
4
|
-
* so it drops straight into the ONE `ListPagination` control. Produced by
|
|
5
|
-
* {@link CursorPager.paginationFor} once the query for `currentPage` has
|
|
6
|
-
* answered with its `hasMore`.
|
|
7
|
-
*/
|
|
1
|
+
import type { ListPaginationState } from './use-paged-list.js';
|
|
8
2
|
export interface CursorPage extends ListPaginationState {
|
|
9
|
-
/** Never known for cursor pagination — the counter reads "Page N". */
|
|
10
3
|
totalPages?: undefined;
|
|
11
4
|
}
|
|
12
5
|
export interface UseCursorPageOptions {
|
|
13
|
-
/** Called after the page actually changed. Same contract as `usePagedList`. */
|
|
14
6
|
onPageChange?: () => void;
|
|
15
|
-
/**
|
|
16
|
-
* A snapshot of the query inputs the page number belongs to — a tag, a filter,
|
|
17
|
-
* a sort. When it changes, the page is 1 again **in the same render**, so the
|
|
18
|
-
* query never fires for "page 4" of inputs whose page 4 may not exist.
|
|
19
|
-
*
|
|
20
|
-
* Use this when the input change arrives as a prop (there is no event handler
|
|
21
|
-
* of yours to hang the reset on); use {@link CursorPager.reset} when your own
|
|
22
|
-
* handler already owns the change. Compose several inputs into one string
|
|
23
|
-
* (`` `${type}|${projectId ?? ""}` ``) — the type is deliberately narrowed to
|
|
24
|
-
* primitives so a fresh object literal cannot pin the list to page 1 forever.
|
|
25
|
-
*/
|
|
26
7
|
resetKey?: string | number | boolean | null;
|
|
27
8
|
}
|
|
28
|
-
/**
|
|
29
|
-
* What {@link useCursorPage} owns: the page number, the guarded step controls,
|
|
30
|
-
* and the return-to-page-1 control.
|
|
31
|
-
*/
|
|
32
9
|
export interface CursorPager {
|
|
33
|
-
/** 1-based page to feed into the paged query. */
|
|
34
10
|
currentPage: number;
|
|
35
|
-
/**
|
|
36
|
-
* Return to page 1 without walking back. Call it from the handler that changes
|
|
37
|
-
* the query's inputs (a new filter, a new tag, a new sort) — page 4 of the old
|
|
38
|
-
* result set is not page 4 of the new one. A no-op on page 1, so it never
|
|
39
|
-
* fires `onPageChange` for nothing.
|
|
40
|
-
*/
|
|
41
11
|
reset: () => void;
|
|
42
|
-
/**
|
|
43
|
-
* Bind the query's answer to the controls: pass the `hasMore` that came back
|
|
44
|
-
* for {@link currentPage} and render the result as
|
|
45
|
-
* `<ListPagination pagination={…} />`. `hasMore` binds HERE, after the query,
|
|
46
|
-
* because that is the only moment it exists — a cursor query needs
|
|
47
|
-
* `currentPage` as its input, so `hasMore` cannot be an argument to the hook
|
|
48
|
-
* that produces `currentPage`.
|
|
49
|
-
*/
|
|
50
12
|
paginationFor: (hasMore: boolean) => CursorPage;
|
|
51
13
|
}
|
|
52
|
-
/**
|
|
53
|
-
* Page state for a server-paged (cursor / `hasMore`) list: the 1-based page
|
|
54
|
-
* number, the guarded step controls, and the reset — the pieces each
|
|
55
|
-
* server-paged surface was otherwise re-declaring as a local `useState(1)` plus
|
|
56
|
-
* its own clamped increment/decrement and its own "reset when the filter
|
|
57
|
-
* changed" adjustment (ENG-002, ENG-003).
|
|
58
|
-
*
|
|
59
|
-
* The data stays the caller's, and the two halves bind at different moments:
|
|
60
|
-
*
|
|
61
|
-
* ```tsx
|
|
62
|
-
* const pager = useCursorPage({ resetKey: tag });
|
|
63
|
-
* const { data, isFetching } = useThingsByTag(tag, pager.currentPage);
|
|
64
|
-
* …
|
|
65
|
-
* <ListPagination pagination={pager.paginationFor(data?.hasMore ?? false)} busy={isFetching} />
|
|
66
|
-
* ```
|
|
67
|
-
*
|
|
68
|
-
* The guards live in here, not at the call site: a step that cannot move the
|
|
69
|
-
* page changes nothing and does not fire `onPageChange`.
|
|
70
|
-
*
|
|
71
|
-
* A surface whose data hook ALREADY owns its page state (it returns
|
|
72
|
-
* `page`/`hasNextPage`/`nextPage`/`prevPage` itself) does not need this hook —
|
|
73
|
-
* it maps those fields onto {@link ListPaginationState} directly. The hook
|
|
74
|
-
* exists for the surfaces that would otherwise hand-roll the state.
|
|
75
|
-
*/
|
|
76
14
|
export declare function useCursorPage(options?: UseCursorPageOptions): CursorPager;
|
|
77
15
|
//# sourceMappingURL=use-cursor-page.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-cursor-page.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/use-cursor-page.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE/D
|
|
1
|
+
{"version":3,"file":"use-cursor-page.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/use-cursor-page.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE/D,MAAM,WAAW,UAAW,SAAQ,mBAAmB;IACrD,UAAU,CAAC,EAAE,SAAS,CAAC;CACxB;AAED,MAAM,WAAW,oBAAoB;IACnC,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;CAC7C;AAED,MAAM,WAAW,WAAW;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,aAAa,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,UAAU,CAAC;CACjD;AAED,wBAAgB,aAAa,CAAC,OAAO,GAAE,oBAAyB,GAAG,WAAW,CA4C7E"}
|
|
@@ -1,47 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
import { useCallback, useState } from
|
|
3
|
-
/**
|
|
4
|
-
* Page state for a server-paged (cursor / `hasMore`) list: the 1-based page
|
|
5
|
-
* number, the guarded step controls, and the reset — the pieces each
|
|
6
|
-
* server-paged surface was otherwise re-declaring as a local `useState(1)` plus
|
|
7
|
-
* its own clamped increment/decrement and its own "reset when the filter
|
|
8
|
-
* changed" adjustment (ENG-002, ENG-003).
|
|
9
|
-
*
|
|
10
|
-
* The data stays the caller's, and the two halves bind at different moments:
|
|
11
|
-
*
|
|
12
|
-
* ```tsx
|
|
13
|
-
* const pager = useCursorPage({ resetKey: tag });
|
|
14
|
-
* const { data, isFetching } = useThingsByTag(tag, pager.currentPage);
|
|
15
|
-
* …
|
|
16
|
-
* <ListPagination pagination={pager.paginationFor(data?.hasMore ?? false)} busy={isFetching} />
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* The guards live in here, not at the call site: a step that cannot move the
|
|
20
|
-
* page changes nothing and does not fire `onPageChange`.
|
|
21
|
-
*
|
|
22
|
-
* A surface whose data hook ALREADY owns its page state (it returns
|
|
23
|
-
* `page`/`hasNextPage`/`nextPage`/`prevPage` itself) does not need this hook —
|
|
24
|
-
* it maps those fields onto {@link ListPaginationState} directly. The hook
|
|
25
|
-
* exists for the surfaces that would otherwise hand-roll the state.
|
|
26
|
-
*/
|
|
1
|
+
'use client';
|
|
2
|
+
import { useCallback, useState } from 'react';
|
|
27
3
|
export function useCursorPage(options = {}) {
|
|
28
4
|
const { onPageChange, resetKey } = options;
|
|
29
|
-
// The stored page is only meaningful for the inputs it was reached under, so
|
|
30
|
-
// the key it belongs to is stored WITH it.
|
|
31
5
|
const [pageState, setPageState] = useState({ page: 1, key: resetKey });
|
|
32
|
-
// `Object.is`,
|
|
33
|
-
// must compare equal to itself, or the adjustment below would re-fire forever.
|
|
6
|
+
// `Object.is`, as React compares: a `NaN` key must equal itself, or the adjustment below re-fires forever.
|
|
34
7
|
const keyMatches = Object.is(pageState.key, resetKey);
|
|
35
|
-
// React's "adjusting state when a prop changes": a new key retires the stored
|
|
36
|
-
// page, because page 4 of the old result set is not page 4 of the new one.
|
|
37
|
-
// Retiring it (rather than only ignoring it) is what makes going BACK to
|
|
38
|
-
// earlier inputs start at page 1 too, instead of reviving a dead page.
|
|
39
8
|
if (!keyMatches) {
|
|
40
9
|
setPageState({ page: 1, key: resetKey });
|
|
41
10
|
}
|
|
42
|
-
// Derived as well as adjusted, so even the render that triggers the adjustment
|
|
43
|
-
// already reports page 1 — the caller's query is never asked for a page of the
|
|
44
|
-
// new inputs that the user never navigated to.
|
|
45
11
|
const currentPage = keyMatches ? pageState.page : 1;
|
|
46
12
|
const goToPreviousPage = useCallback(() => {
|
|
47
13
|
if (currentPage <= 1)
|
|
@@ -55,8 +21,6 @@ export function useCursorPage(options = {}) {
|
|
|
55
21
|
setPageState({ page: 1, key: resetKey });
|
|
56
22
|
onPageChange?.();
|
|
57
23
|
}, [currentPage, resetKey, onPageChange]);
|
|
58
|
-
// Memoized on the page state itself, so a consumer may hold it in a dep array
|
|
59
|
-
// and it changes only when the page (or the callback/inputs) actually change.
|
|
60
24
|
const paginationFor = useCallback((hasMore) => ({
|
|
61
25
|
currentPage,
|
|
62
26
|
canPreviousPage: currentPage > 1,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-cursor-page.js","sourceRoot":"","sources":["../../../src/react/hooks/use-cursor-page.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,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,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAC;QACzC,YAAY,EAAE,EAAE,CAAC;IACnB,CAAC,EAAE,CAAC,WAAW,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC;IAE1C,MAAM,aAAa,GAAG,WAAW,CAC/B,CAAC,OAAgB,EAAc,EAAE,CAAC,CAAC;QACjC,WAAW;QACX,eAAe,EAAE,WAAW,GAAG,CAAC;QAChC,WAAW,EAAE,OAAO;QACpB,gBAAgB;QAChB,YAAY,EAAE,GAAG,EAAE;YACjB,IAAI,CAAC,OAAO;gBAAE,OAAO;YACrB,YAAY,CAAC,EAAE,IAAI,EAAE,WAAW,GAAG,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAC;YACvD,YAAY,EAAE,EAAE,CAAC;QACnB,CAAC;KACF,CAAC,EACF,CAAC,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,gBAAgB,CAAC,CACxD,CAAC;IAEF,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC;AAC/C,CAAC","sourcesContent":["'use client';\n\nimport { useCallback, useState } from 'react';\nimport type { ListPaginationState } from './use-paged-list.js';\n\nexport interface CursorPage extends ListPaginationState {\n totalPages?: undefined;\n}\n\nexport interface UseCursorPageOptions {\n onPageChange?: () => void;\n resetKey?: string | number | boolean | null;\n}\n\nexport interface CursorPager {\n currentPage: number;\n reset: () => void;\n paginationFor: (hasMore: boolean) => CursorPage;\n}\n\nexport function useCursorPage(options: UseCursorPageOptions = {}): CursorPager {\n const { onPageChange, resetKey } = options;\n\n const [pageState, setPageState] = useState<{\n page: number;\n key: UseCursorPageOptions['resetKey'];\n }>({ page: 1, key: resetKey });\n\n // `Object.is`, as React compares: a `NaN` key must equal itself, or the adjustment below re-fires forever.\n const keyMatches = Object.is(pageState.key, resetKey);\n\n if (!keyMatches) {\n setPageState({ page: 1, key: resetKey });\n }\n const currentPage = keyMatches ? pageState.page : 1;\n\n const goToPreviousPage = useCallback(() => {\n if (currentPage <= 1) return;\n setPageState({ page: currentPage - 1, key: resetKey });\n onPageChange?.();\n }, [currentPage, resetKey, onPageChange]);\n\n const reset = useCallback(() => {\n if (currentPage === 1) return;\n setPageState({ page: 1, key: resetKey });\n onPageChange?.();\n }, [currentPage, resetKey, onPageChange]);\n\n const paginationFor = useCallback(\n (hasMore: boolean): CursorPage => ({\n currentPage,\n canPreviousPage: currentPage > 1,\n canNextPage: hasMore,\n goToPreviousPage,\n goToNextPage: () => {\n if (!hasMore) return;\n setPageState({ page: currentPage + 1, key: resetKey });\n onPageChange?.();\n },\n }),\n [currentPage, resetKey, onPageChange, goToPreviousPage],\n );\n\n return { currentPage, reset, paginationFor };\n}\n"]}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
import * as React from
|
|
1
|
+
'use client';
|
|
2
|
+
import * as React from 'react';
|
|
3
3
|
export function useMediaQuery(query) {
|
|
4
4
|
const [matches, setMatches] = React.useState(false);
|
|
5
5
|
React.useEffect(() => {
|
|
6
|
-
if (typeof window ===
|
|
6
|
+
if (typeof window === 'undefined' || !window.matchMedia)
|
|
7
7
|
return;
|
|
8
8
|
const mql = window.matchMedia(query);
|
|
9
9
|
const onChange = (e) => setMatches(e.matches);
|
|
10
10
|
setMatches(mql.matches);
|
|
11
11
|
if (mql.addEventListener)
|
|
12
|
-
mql.addEventListener(
|
|
12
|
+
mql.addEventListener('change', onChange);
|
|
13
13
|
else
|
|
14
14
|
mql.addListener(onChange);
|
|
15
15
|
return () => {
|
|
16
16
|
if (mql.removeEventListener)
|
|
17
|
-
mql.removeEventListener(
|
|
17
|
+
mql.removeEventListener('change', onChange);
|
|
18
18
|
else
|
|
19
19
|
mql.removeListener(onChange);
|
|
20
20
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-media-query.js","sourceRoot":"","sources":["../../../src/react/hooks/use-media-query.tsx"],"names":[],"mappings":"AAAA,YAAY,C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pD,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,CAAC,MAAM,CAAC,UAAU;YAAE,OAAO;QAEhE,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QACrC,MAAM,QAAQ,GAAG,CAAC,CAAsB,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QAEnE,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAExB,IAAI,GAAG,CAAC,gBAAgB;YAAE,GAAG,CAAC,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;;YAC9D,GAAG,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;QAE/B,OAAO,GAAG,EAAE;YACV,IAAI,GAAG,CAAC,mBAAmB;gBAAE,GAAG,CAAC,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;;gBACpE,GAAG,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;QACpC,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["'use client';\n\nimport * as React from 'react';\n\nexport function useMediaQuery(query: string) {\n const [matches, setMatches] = React.useState(false);\n\n React.useEffect(() => {\n if (typeof window === 'undefined' || !window.matchMedia) return;\n\n const mql = window.matchMedia(query);\n const onChange = (e: MediaQueryListEvent) => setMatches(e.matches);\n\n setMatches(mql.matches);\n\n if (mql.addEventListener) mql.addEventListener('change', onChange);\n else mql.addListener(onChange);\n\n return () => {\n if (mql.removeEventListener) mql.removeEventListener('change', onChange);\n else mql.removeListener(onChange);\n };\n }, [query]);\n\n return matches;\n}\n"]}
|