@oaiz/app-kit 0.0.0-stage → 0.1.4128
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/LICENSE +21 -0
- package/README.md +143 -2
- package/THIRD_PARTY_NOTICES.md +76 -0
- package/package.json +139 -4
- package/registry.json +1847 -0
- package/src/components/activity-timeline.tsx +227 -0
- package/src/components/app-shell.tsx +622 -0
- package/src/components/bar-list.tsx +47 -0
- package/src/components/board.tsx +700 -0
- package/src/components/calendar-view.tsx +1388 -0
- package/src/components/card-grid.tsx +462 -0
- package/src/components/charts.tsx +701 -0
- package/src/components/chat-markdown.tsx +230 -0
- package/src/components/chat-panel.tsx +760 -0
- package/src/components/code-editor.tsx +276 -0
- package/src/components/collection-controls.tsx +226 -0
- package/src/components/command-palette.tsx +403 -0
- package/src/components/confirm-action.tsx +123 -0
- package/src/components/data-table.tsx +821 -0
- package/src/components/date-input.tsx +429 -0
- package/src/components/empty-state.tsx +31 -0
- package/src/components/error-state.tsx +37 -0
- package/src/components/file-upload.tsx +595 -0
- package/src/components/filter-bar.tsx +415 -0
- package/src/components/grouped-picker.tsx +250 -0
- package/src/components/line-items.tsx +601 -0
- package/src/components/list-view.tsx +491 -0
- package/src/components/metrics.tsx +53 -0
- package/src/components/page-header.tsx +33 -0
- package/src/components/property-picker.tsx +546 -0
- package/src/components/record-detail.tsx +416 -0
- package/src/components/record-form.tsx +295 -0
- package/src/components/record-name.tsx +85 -0
- package/src/components/save-bar.tsx +142 -0
- package/src/components/sign-in.tsx +179 -0
- package/src/components/split-view.tsx +128 -0
- package/src/components/status-dot.tsx +56 -0
- package/src/components/stepper.tsx +153 -0
- package/src/components/text-diff-model.ts +111 -0
- package/src/components/text-diff.tsx +98 -0
- package/src/components/time-zone-picker.tsx +69 -0
- package/src/components/ui/accordion.tsx +138 -0
- package/src/components/ui/alert-dialog.tsx +67 -0
- package/src/components/ui/alert.tsx +65 -0
- package/src/components/ui/avatar-group.tsx +119 -0
- package/src/components/ui/avatar.tsx +55 -0
- package/src/components/ui/badge.tsx +59 -0
- package/src/components/ui/bottom-navigation.tsx +102 -0
- package/src/components/ui/breadcrumb.tsx +117 -0
- package/src/components/ui/button.tsx +71 -0
- package/src/components/ui/card.tsx +95 -0
- package/src/components/ui/checkbox.tsx +31 -0
- package/src/components/ui/collapsible.tsx +27 -0
- package/src/components/ui/context-menu.tsx +270 -0
- package/src/components/ui/count-up.tsx +136 -0
- package/src/components/ui/detail-disclosure-section.tsx +109 -0
- package/src/components/ui/dialog.tsx +157 -0
- package/src/components/ui/dropdown-menu.tsx +273 -0
- package/src/components/ui/form-field.tsx +155 -0
- package/src/components/ui/heading.tsx +126 -0
- package/src/components/ui/hover-card.tsx +45 -0
- package/src/components/ui/input.tsx +50 -0
- package/src/components/ui/label.tsx +30 -0
- package/src/components/ui/orb-spinner.tsx +238 -0
- package/src/components/ui/popover.tsx +59 -0
- package/src/components/ui/progress-ring.tsx +125 -0
- package/src/components/ui/progress.tsx +38 -0
- package/src/components/ui/radio-group.tsx +124 -0
- package/src/components/ui/resizable.tsx +48 -0
- package/src/components/ui/scroll-fade.tsx +98 -0
- package/src/components/ui/segmented-control.tsx +70 -0
- package/src/components/ui/select.tsx +230 -0
- package/src/components/ui/separator.tsx +29 -0
- package/src/components/ui/sheet.tsx +170 -0
- package/src/components/ui/shimmer-text.tsx +87 -0
- package/src/components/ui/shortcut.tsx +39 -0
- package/src/components/ui/skeleton.tsx +15 -0
- package/src/components/ui/slider.tsx +48 -0
- package/src/components/ui/switch.tsx +44 -0
- package/src/components/ui/table.tsx +119 -0
- package/src/components/ui/tabs.tsx +80 -0
- package/src/components/ui/text.tsx +93 -0
- package/src/components/ui/textarea.tsx +51 -0
- package/src/components/ui/toast.tsx +141 -0
- package/src/components/ui/toaster.tsx +40 -0
- package/src/components/ui/tooltip.tsx +38 -0
- package/src/components/ui/top-banner.tsx +108 -0
- package/src/components/ui/tree-view.tsx +215 -0
- package/src/components/ui/use-toast.tsx +184 -0
- package/src/components/ui/voice-orb.tsx +252 -0
- package/src/hooks/oaiz-chat.tsx +530 -0
- package/src/hooks/oaiz-data.tsx +617 -0
- package/src/hooks/oaiz-session.tsx +63 -0
- package/src/hooks/use-arrivals.ts +19 -0
- package/src/hooks/use-breakpoint.ts +100 -0
- package/src/hooks/use-media-query.ts +36 -0
- package/src/hooks/use-theme.ts +67 -0
- package/src/hooks/use-url-state.ts +77 -0
- package/src/lib/breakpoints.ts +81 -0
- package/src/lib/csp-nonce.ts +15 -0
- package/src/lib/format.ts +291 -0
- package/src/lib/speech-level.ts +118 -0
- package/src/lib/utils.ts +109 -0
- package/src/styles/oaiz/app.css +21 -0
- package/src/styles/oaiz/scrollbars.css +20 -0
- package/src/styles/oaiz/tokens.css +952 -0
- package/src/styles/oaiz/voice-orb.css +39 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import * as TooltipPrimitive from '@radix-ui/react-tooltip';
|
|
3
|
+
|
|
4
|
+
import { cn } from '../../lib/utils';
|
|
5
|
+
import { Text } from './text';
|
|
6
|
+
|
|
7
|
+
const TooltipProvider = TooltipPrimitive.Provider;
|
|
8
|
+
|
|
9
|
+
const Tooltip = TooltipPrimitive.Root;
|
|
10
|
+
|
|
11
|
+
const TooltipTrigger = TooltipPrimitive.Trigger;
|
|
12
|
+
|
|
13
|
+
interface TooltipContentProps extends React.ComponentPropsWithoutRef<
|
|
14
|
+
typeof TooltipPrimitive.Content
|
|
15
|
+
> {
|
|
16
|
+
size?: 'xs' | 'sm';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const TooltipContent = React.forwardRef<
|
|
20
|
+
React.ElementRef<typeof TooltipPrimitive.Content>,
|
|
21
|
+
TooltipContentProps
|
|
22
|
+
>(({ className, sideOffset = 4, size = 'sm', ...props }, ref) => (
|
|
23
|
+
<TooltipPrimitive.Portal>
|
|
24
|
+
<Text
|
|
25
|
+
asChild
|
|
26
|
+
size={size}
|
|
27
|
+
className={cn(
|
|
28
|
+
'z-50 overflow-hidden rounded-md border bg-popover px-inset py-1.5 text-popover-foreground shadow-md duration-fast ease-enter data-[state=closed]:ease-exit 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',
|
|
29
|
+
className,
|
|
30
|
+
)}
|
|
31
|
+
>
|
|
32
|
+
<TooltipPrimitive.Content ref={ref} sideOffset={sideOffset} {...props} />
|
|
33
|
+
</Text>
|
|
34
|
+
</TooltipPrimitive.Portal>
|
|
35
|
+
));
|
|
36
|
+
TooltipContent.displayName = TooltipPrimitive.Content.displayName;
|
|
37
|
+
|
|
38
|
+
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/* eslint-disable react-refresh/only-export-components */
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { cva, type VariantProps } from 'class-variance-authority';
|
|
4
|
+
import { X } from 'lucide-react';
|
|
5
|
+
|
|
6
|
+
import { cn } from '../../lib/utils';
|
|
7
|
+
import { Button, type ButtonProps } from './button';
|
|
8
|
+
import { Separator } from './separator';
|
|
9
|
+
import { Text } from './text';
|
|
10
|
+
|
|
11
|
+
const topBannerVariants = cva(
|
|
12
|
+
'grid w-full min-w-0 shrink-0 items-center gap-inline border-b px-inline [&_svg]:size-3.5 [&_svg]:shrink-0',
|
|
13
|
+
{
|
|
14
|
+
variants: {
|
|
15
|
+
layout: {
|
|
16
|
+
compact: 'h-8 grid-cols-[1fr_minmax(0,auto)_1fr] whitespace-nowrap',
|
|
17
|
+
wrap: 'min-h-8 grid-cols-[minmax(0,1fr)_auto] py-1',
|
|
18
|
+
},
|
|
19
|
+
tone: {
|
|
20
|
+
muted: 'border-border bg-muted',
|
|
21
|
+
warning: 'border-warning-text/30 bg-warning-bg-subtle',
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
defaultVariants: {
|
|
25
|
+
layout: 'compact',
|
|
26
|
+
tone: 'muted',
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
export interface TopBannerProps
|
|
32
|
+
extends
|
|
33
|
+
React.HTMLAttributes<HTMLDivElement>,
|
|
34
|
+
VariantProps<typeof topBannerVariants> {
|
|
35
|
+
/** Controls aligned to the end of the banner, such as `TopBannerDismiss`. */
|
|
36
|
+
actions?: React.ReactNode;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Full-width strip above the app shell for environment or status notices. */
|
|
40
|
+
const TopBanner = React.forwardRef<HTMLDivElement, TopBannerProps>(
|
|
41
|
+
(
|
|
42
|
+
{ className, tone, layout = 'compact', actions, children, ...props },
|
|
43
|
+
ref,
|
|
44
|
+
) => (
|
|
45
|
+
<Text
|
|
46
|
+
as="div"
|
|
47
|
+
size="xs"
|
|
48
|
+
ref={ref}
|
|
49
|
+
className={cn(topBannerVariants({ tone, layout }), className)}
|
|
50
|
+
{...props}
|
|
51
|
+
>
|
|
52
|
+
<div
|
|
53
|
+
className={cn(
|
|
54
|
+
'flex min-w-0 items-center justify-center gap-inline',
|
|
55
|
+
layout === 'compact'
|
|
56
|
+
? 'col-start-2'
|
|
57
|
+
: 'flex-wrap [overflow-wrap:anywhere]',
|
|
58
|
+
)}
|
|
59
|
+
>
|
|
60
|
+
{children}
|
|
61
|
+
</div>
|
|
62
|
+
{actions ? (
|
|
63
|
+
<div
|
|
64
|
+
className={cn(
|
|
65
|
+
'flex items-center justify-end gap-inline [&>*]:shrink-0',
|
|
66
|
+
layout === 'compact'
|
|
67
|
+
? 'col-start-3'
|
|
68
|
+
: 'col-start-2 min-w-0 flex-wrap',
|
|
69
|
+
)}
|
|
70
|
+
>
|
|
71
|
+
{actions}
|
|
72
|
+
</div>
|
|
73
|
+
) : null}
|
|
74
|
+
</Text>
|
|
75
|
+
),
|
|
76
|
+
);
|
|
77
|
+
TopBanner.displayName = 'TopBanner';
|
|
78
|
+
|
|
79
|
+
export type TopBannerDismissProps = Omit<
|
|
80
|
+
ButtonProps,
|
|
81
|
+
'variant' | 'size' | 'children' | 'asChild'
|
|
82
|
+
> & { 'aria-label': string };
|
|
83
|
+
|
|
84
|
+
const TopBannerDismiss = React.forwardRef<
|
|
85
|
+
HTMLButtonElement,
|
|
86
|
+
TopBannerDismissProps
|
|
87
|
+
>((props, ref) => (
|
|
88
|
+
<Button ref={ref} variant="ghost" size="icon-xs" {...props}>
|
|
89
|
+
<X aria-hidden="true" />
|
|
90
|
+
</Button>
|
|
91
|
+
));
|
|
92
|
+
TopBannerDismiss.displayName = 'TopBannerDismiss';
|
|
93
|
+
|
|
94
|
+
/** Vertical rule between banner segments, sized to the banner's icons. */
|
|
95
|
+
const TopBannerSeparator = React.forwardRef<
|
|
96
|
+
React.ElementRef<typeof Separator>,
|
|
97
|
+
Omit<React.ComponentPropsWithoutRef<typeof Separator>, 'orientation'>
|
|
98
|
+
>(({ className, ...props }, ref) => (
|
|
99
|
+
<Separator
|
|
100
|
+
ref={ref}
|
|
101
|
+
orientation="vertical"
|
|
102
|
+
className={cn('h-3.5', className)}
|
|
103
|
+
{...props}
|
|
104
|
+
/>
|
|
105
|
+
));
|
|
106
|
+
TopBannerSeparator.displayName = 'TopBannerSeparator';
|
|
107
|
+
|
|
108
|
+
export { TopBanner, TopBannerDismiss, TopBannerSeparator, topBannerVariants };
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ChevronRight } from 'lucide-react';
|
|
3
|
+
|
|
4
|
+
import { cn } from '../../lib/utils';
|
|
5
|
+
import { Text } from './text';
|
|
6
|
+
|
|
7
|
+
export interface TreeNode {
|
|
8
|
+
id: string;
|
|
9
|
+
label: React.ReactNode;
|
|
10
|
+
/** The text a screen reader and type-ahead use when `label` is not plain text. */
|
|
11
|
+
textValue?: string;
|
|
12
|
+
icon?: React.ReactNode;
|
|
13
|
+
/** Shown after the label, such as a count. */
|
|
14
|
+
meta?: React.ReactNode;
|
|
15
|
+
children?: TreeNode[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface TreeViewProps {
|
|
19
|
+
nodes: TreeNode[];
|
|
20
|
+
/** Names the tree, such as "Folders". */
|
|
21
|
+
label: string;
|
|
22
|
+
/** The chosen node's id. */
|
|
23
|
+
selected?: string | null;
|
|
24
|
+
onSelect?: (node: TreeNode) => void;
|
|
25
|
+
/** The ids of nodes open at first. */
|
|
26
|
+
defaultExpanded?: string[];
|
|
27
|
+
className?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface Row {
|
|
31
|
+
node: TreeNode;
|
|
32
|
+
level: number;
|
|
33
|
+
parent: string | null;
|
|
34
|
+
open: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function visibleRows(
|
|
38
|
+
nodes: TreeNode[],
|
|
39
|
+
expanded: Set<string>,
|
|
40
|
+
level = 1,
|
|
41
|
+
parent: string | null = null,
|
|
42
|
+
): Row[] {
|
|
43
|
+
return nodes.flatMap((node) => {
|
|
44
|
+
const open = expanded.has(node.id);
|
|
45
|
+
const row = { node, level, parent, open };
|
|
46
|
+
return node.children?.length && open
|
|
47
|
+
? [row, ...visibleRows(node.children, expanded, level + 1, node.id)]
|
|
48
|
+
: [row];
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const textOf = (node: TreeNode) =>
|
|
53
|
+
node.textValue ?? (typeof node.label === 'string' ? node.label : node.id);
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Nested items, such as folders, categories or org units, in the WAI-ARIA tree pattern. Arrow
|
|
57
|
+
* keys move and open, Home and End jump, Enter or Space choose, and typing a letter finds the
|
|
58
|
+
* next item that starts with it.
|
|
59
|
+
*/
|
|
60
|
+
function TreeView({
|
|
61
|
+
nodes,
|
|
62
|
+
label,
|
|
63
|
+
selected = null,
|
|
64
|
+
onSelect,
|
|
65
|
+
defaultExpanded = [],
|
|
66
|
+
className,
|
|
67
|
+
}: TreeViewProps) {
|
|
68
|
+
const [expanded, setExpanded] = React.useState(
|
|
69
|
+
() => new Set(defaultExpanded),
|
|
70
|
+
);
|
|
71
|
+
const [focused, setFocused] = React.useState<string | null>(null);
|
|
72
|
+
const refs = React.useRef(new Map<string, HTMLDivElement>());
|
|
73
|
+
const rows = visibleRows(nodes, expanded);
|
|
74
|
+
const current = focused ?? selected ?? rows[0]?.node.id ?? null;
|
|
75
|
+
|
|
76
|
+
const focus = (id: string | undefined) => {
|
|
77
|
+
if (!id) return;
|
|
78
|
+
setFocused(id);
|
|
79
|
+
refs.current.get(id)?.focus();
|
|
80
|
+
};
|
|
81
|
+
const toggle = (id: string, open: boolean) =>
|
|
82
|
+
setExpanded((now) => {
|
|
83
|
+
const next = new Set(now);
|
|
84
|
+
if (open) next.add(id);
|
|
85
|
+
else next.delete(id);
|
|
86
|
+
return next;
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
function onKeyDown(event: React.KeyboardEvent, row: Row, index: number) {
|
|
90
|
+
const hasChildren = Boolean(row.node.children?.length);
|
|
91
|
+
switch (event.key) {
|
|
92
|
+
case 'ArrowDown':
|
|
93
|
+
focus(rows[index + 1]?.node.id);
|
|
94
|
+
break;
|
|
95
|
+
case 'ArrowUp':
|
|
96
|
+
focus(rows[index - 1]?.node.id);
|
|
97
|
+
break;
|
|
98
|
+
case 'ArrowRight':
|
|
99
|
+
if (hasChildren && !row.open) toggle(row.node.id, true);
|
|
100
|
+
else if (hasChildren) focus(rows[index + 1]?.node.id);
|
|
101
|
+
break;
|
|
102
|
+
case 'ArrowLeft':
|
|
103
|
+
if (hasChildren && row.open) toggle(row.node.id, false);
|
|
104
|
+
else focus(row.parent ?? undefined);
|
|
105
|
+
break;
|
|
106
|
+
case 'Home':
|
|
107
|
+
focus(rows[0]?.node.id);
|
|
108
|
+
break;
|
|
109
|
+
case 'End':
|
|
110
|
+
focus(rows[rows.length - 1]?.node.id);
|
|
111
|
+
break;
|
|
112
|
+
case 'Enter':
|
|
113
|
+
case ' ':
|
|
114
|
+
onSelect?.(row.node);
|
|
115
|
+
if (hasChildren && !onSelect) toggle(row.node.id, !row.open);
|
|
116
|
+
break;
|
|
117
|
+
default:
|
|
118
|
+
if (event.key.length === 1 && /\S/.test(event.key)) {
|
|
119
|
+
const key = event.key.toLowerCase();
|
|
120
|
+
const after = [...rows.slice(index + 1), ...rows.slice(0, index)];
|
|
121
|
+
focus(
|
|
122
|
+
after.find((each) =>
|
|
123
|
+
textOf(each.node).toLowerCase().startsWith(key),
|
|
124
|
+
)?.node.id,
|
|
125
|
+
);
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
event.preventDefault();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<div
|
|
135
|
+
role="tree"
|
|
136
|
+
aria-label={label}
|
|
137
|
+
className={cn('flex flex-col', className)}
|
|
138
|
+
>
|
|
139
|
+
{rows.map((row, index) => {
|
|
140
|
+
const hasChildren = Boolean(row.node.children?.length);
|
|
141
|
+
const isSelected = row.node.id === selected;
|
|
142
|
+
return (
|
|
143
|
+
<div
|
|
144
|
+
key={row.node.id}
|
|
145
|
+
ref={(element) => {
|
|
146
|
+
if (element) refs.current.set(row.node.id, element);
|
|
147
|
+
else refs.current.delete(row.node.id);
|
|
148
|
+
}}
|
|
149
|
+
role="treeitem"
|
|
150
|
+
aria-level={row.level}
|
|
151
|
+
aria-expanded={hasChildren ? row.open : undefined}
|
|
152
|
+
aria-selected={onSelect ? isSelected : undefined}
|
|
153
|
+
aria-label={textOf(row.node)}
|
|
154
|
+
tabIndex={row.node.id === current ? 0 : -1}
|
|
155
|
+
onFocus={() => setFocused(row.node.id)}
|
|
156
|
+
onKeyDown={(event) => onKeyDown(event, row, index)}
|
|
157
|
+
onClick={() => {
|
|
158
|
+
setFocused(row.node.id);
|
|
159
|
+
if (onSelect) onSelect(row.node);
|
|
160
|
+
else if (hasChildren) toggle(row.node.id, !row.open);
|
|
161
|
+
}}
|
|
162
|
+
// Each level indents by one stack step from the inline gutter.
|
|
163
|
+
style={{
|
|
164
|
+
paddingInlineStart: `calc(var(--spacing-inline) + ${row.level - 1} * var(--spacing-stack))`,
|
|
165
|
+
}}
|
|
166
|
+
className={cn(
|
|
167
|
+
'flex cursor-pointer select-none items-center gap-1.5 rounded-sm py-1.5 pr-inline outline-none transition-colors duration-fast ease-move hover:bg-muted focus-visible:ring-2 focus-visible:ring-ring max-mobile:py-inset [&_svg]:size-4 [&_svg]:shrink-0',
|
|
168
|
+
isSelected && 'bg-accent text-accent-foreground',
|
|
169
|
+
)}
|
|
170
|
+
>
|
|
171
|
+
<span
|
|
172
|
+
aria-hidden="true"
|
|
173
|
+
className={cn(
|
|
174
|
+
'flex size-4 items-center justify-center text-muted-foreground',
|
|
175
|
+
!hasChildren && 'invisible',
|
|
176
|
+
)}
|
|
177
|
+
onClick={(event) => {
|
|
178
|
+
if (!hasChildren) return;
|
|
179
|
+
event.stopPropagation();
|
|
180
|
+
toggle(row.node.id, !row.open);
|
|
181
|
+
}}
|
|
182
|
+
>
|
|
183
|
+
<ChevronRight
|
|
184
|
+
className={cn(
|
|
185
|
+
'transition-transform duration-fast ease-move',
|
|
186
|
+
row.open && 'rotate-90',
|
|
187
|
+
)}
|
|
188
|
+
/>
|
|
189
|
+
</span>
|
|
190
|
+
{row.node.icon && (
|
|
191
|
+
<span aria-hidden="true" className="flex text-muted-foreground">
|
|
192
|
+
{row.node.icon}
|
|
193
|
+
</span>
|
|
194
|
+
)}
|
|
195
|
+
<Text as="span" className="min-w-0 flex-1 truncate">
|
|
196
|
+
{row.node.label}
|
|
197
|
+
</Text>
|
|
198
|
+
{row.node.meta !== undefined && (
|
|
199
|
+
<Text
|
|
200
|
+
as="span"
|
|
201
|
+
size="xs"
|
|
202
|
+
variant="muted"
|
|
203
|
+
className="shrink-0 tabular-nums"
|
|
204
|
+
>
|
|
205
|
+
{row.node.meta}
|
|
206
|
+
</Text>
|
|
207
|
+
)}
|
|
208
|
+
</div>
|
|
209
|
+
);
|
|
210
|
+
})}
|
|
211
|
+
</div>
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export { TreeView };
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
// Adapted from shadcn/ui toast
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
|
|
4
|
+
import type { ToastActionElement, ToastProps } from './toast';
|
|
5
|
+
|
|
6
|
+
const TOAST_LIMIT = 3;
|
|
7
|
+
const TOAST_REMOVE_DELAY = 1000;
|
|
8
|
+
|
|
9
|
+
type ToasterToast = ToastProps & {
|
|
10
|
+
id: string;
|
|
11
|
+
title?: React.ReactNode;
|
|
12
|
+
description?: React.ReactNode;
|
|
13
|
+
action?: ToastActionElement;
|
|
14
|
+
testId?: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const actionTypes = {
|
|
18
|
+
ADD_TOAST: 'ADD_TOAST',
|
|
19
|
+
UPDATE_TOAST: 'UPDATE_TOAST',
|
|
20
|
+
DISMISS_TOAST: 'DISMISS_TOAST',
|
|
21
|
+
REMOVE_TOAST: 'REMOVE_TOAST',
|
|
22
|
+
} as const;
|
|
23
|
+
|
|
24
|
+
let count = 0;
|
|
25
|
+
|
|
26
|
+
function genId() {
|
|
27
|
+
count = (count + 1) % Number.MAX_VALUE;
|
|
28
|
+
return count.toString();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type ActionType = typeof actionTypes;
|
|
32
|
+
|
|
33
|
+
type Action =
|
|
34
|
+
| {
|
|
35
|
+
type: ActionType['ADD_TOAST'];
|
|
36
|
+
toast: ToasterToast;
|
|
37
|
+
}
|
|
38
|
+
| {
|
|
39
|
+
type: ActionType['UPDATE_TOAST'];
|
|
40
|
+
toast: Partial<ToasterToast>;
|
|
41
|
+
}
|
|
42
|
+
| {
|
|
43
|
+
type: ActionType['DISMISS_TOAST'];
|
|
44
|
+
toastId?: string;
|
|
45
|
+
}
|
|
46
|
+
| {
|
|
47
|
+
type: ActionType['REMOVE_TOAST'];
|
|
48
|
+
toastId?: string;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
interface State {
|
|
52
|
+
toasts: ToasterToast[];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const toastTimeouts = new Map<string, ReturnType<typeof setTimeout>>();
|
|
56
|
+
|
|
57
|
+
const reducer = (state: State, action: Action): State => {
|
|
58
|
+
switch (action.type) {
|
|
59
|
+
case actionTypes.ADD_TOAST:
|
|
60
|
+
return {
|
|
61
|
+
...state,
|
|
62
|
+
toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT),
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
case actionTypes.UPDATE_TOAST:
|
|
66
|
+
return {
|
|
67
|
+
...state,
|
|
68
|
+
toasts: state.toasts.map((t) =>
|
|
69
|
+
t.id === action.toast.id ? { ...t, ...action.toast } : t,
|
|
70
|
+
),
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
case actionTypes.DISMISS_TOAST: {
|
|
74
|
+
const { toastId } = action;
|
|
75
|
+
|
|
76
|
+
// ! Side effects ! - This could be extracted into a dismissToast() action,
|
|
77
|
+
// but I'll keep it here for simplicity
|
|
78
|
+
if (toastId) {
|
|
79
|
+
toastTimeouts.set(
|
|
80
|
+
toastId,
|
|
81
|
+
setTimeout(() => {
|
|
82
|
+
dispatch({
|
|
83
|
+
type: actionTypes.REMOVE_TOAST,
|
|
84
|
+
toastId,
|
|
85
|
+
});
|
|
86
|
+
}, TOAST_REMOVE_DELAY),
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
...state,
|
|
92
|
+
toasts: state.toasts.map((t) =>
|
|
93
|
+
t.id === toastId || toastId === undefined
|
|
94
|
+
? {
|
|
95
|
+
...t,
|
|
96
|
+
open: false,
|
|
97
|
+
}
|
|
98
|
+
: t,
|
|
99
|
+
),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
case actionTypes.REMOVE_TOAST: {
|
|
103
|
+
const { toastId } = action;
|
|
104
|
+
|
|
105
|
+
if (toastId) {
|
|
106
|
+
toastTimeouts.delete(toastId);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return {
|
|
110
|
+
...state,
|
|
111
|
+
toasts: state.toasts.filter(
|
|
112
|
+
(t) =>
|
|
113
|
+
t.id !== toastId && (toastId !== undefined || t.open !== false),
|
|
114
|
+
),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const listeners: ((state: State) => void)[] = [];
|
|
121
|
+
|
|
122
|
+
let memoryState: State = { toasts: [] };
|
|
123
|
+
|
|
124
|
+
function dispatch(action: Action) {
|
|
125
|
+
memoryState = reducer(memoryState, action);
|
|
126
|
+
listeners.forEach((listener) => {
|
|
127
|
+
listener(memoryState);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
type Toast = Omit<ToasterToast, 'id'>;
|
|
132
|
+
|
|
133
|
+
function toast(props: Toast) {
|
|
134
|
+
const id = genId();
|
|
135
|
+
|
|
136
|
+
const update = (props: ToasterToast) =>
|
|
137
|
+
dispatch({
|
|
138
|
+
type: actionTypes.UPDATE_TOAST,
|
|
139
|
+
toast: { ...props, id },
|
|
140
|
+
});
|
|
141
|
+
const dismiss = () =>
|
|
142
|
+
dispatch({ type: actionTypes.DISMISS_TOAST, toastId: id });
|
|
143
|
+
|
|
144
|
+
dispatch({
|
|
145
|
+
type: actionTypes.ADD_TOAST,
|
|
146
|
+
toast: {
|
|
147
|
+
...props,
|
|
148
|
+
id,
|
|
149
|
+
open: true,
|
|
150
|
+
onOpenChange: (open: boolean) => {
|
|
151
|
+
if (!open) dismiss();
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
return {
|
|
157
|
+
id,
|
|
158
|
+
dismiss,
|
|
159
|
+
update,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function useToast() {
|
|
164
|
+
const [state, setState] = React.useState<State>(memoryState);
|
|
165
|
+
|
|
166
|
+
React.useEffect(() => {
|
|
167
|
+
listeners.push(setState);
|
|
168
|
+
return () => {
|
|
169
|
+
const index = listeners.indexOf(setState);
|
|
170
|
+
if (index > -1) {
|
|
171
|
+
listeners.splice(index, 1);
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
}, [state]);
|
|
175
|
+
|
|
176
|
+
return {
|
|
177
|
+
...state,
|
|
178
|
+
toast,
|
|
179
|
+
dismiss: (toastId?: string) =>
|
|
180
|
+
dispatch({ type: actionTypes.DISMISS_TOAST, toastId }),
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export { useToast, toast };
|