@kivacore/ui-pro-shared 0.0.9 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +167 -1
- package/src/.kiva/config.json +27 -0
- package/src/components/avatar-group.tsx +222 -0
- package/src/components/kiva/bulk-update-dialog/bulk-update-dialog.tsx +240 -0
- package/src/components/kiva/bulk-update-dialog/index.tsx +6 -0
- package/src/components/kiva/bulk-update-dialog/types.ts +33 -0
- package/src/components/kiva/calendar/animations.ts +40 -0
- package/src/components/kiva/calendar/calendar-body.tsx +106 -0
- package/src/components/kiva/calendar/calendar-sidebar.tsx +103 -0
- package/src/components/kiva/calendar/calendar.tsx +243 -0
- package/src/components/kiva/calendar/constants.ts +12 -0
- package/src/components/kiva/calendar/contexts/calendar-context.tsx +696 -0
- package/src/components/kiva/calendar/contexts/dnd-context.tsx +173 -0
- package/src/components/kiva/calendar/dialogs/add-edit-event-dialog.tsx +287 -0
- package/src/components/kiva/calendar/dialogs/delete-event-dialog.tsx +73 -0
- package/src/components/kiva/calendar/dialogs/event-details-dialog.tsx +163 -0
- package/src/components/kiva/calendar/dialogs/events-list-dialog.tsx +122 -0
- package/src/components/kiva/calendar/dnd/draggable-event.tsx +66 -0
- package/src/components/kiva/calendar/dnd/droppable-area.tsx +53 -0
- package/src/components/kiva/calendar/dnd/resizable-event.tsx +190 -0
- package/src/components/kiva/calendar/header/calendar-header.tsx +84 -0
- package/src/components/kiva/calendar/header/date-navigator.tsx +188 -0
- package/src/components/kiva/calendar/header/filter.tsx +80 -0
- package/src/components/kiva/calendar/header/today-button.tsx +49 -0
- package/src/components/kiva/calendar/header/user-select.tsx +111 -0
- package/src/components/kiva/calendar/header/view-tabs.tsx +144 -0
- package/src/components/kiva/calendar/helpers.ts +617 -0
- package/src/components/kiva/calendar/hooks/use-disclosure.ts +19 -0
- package/src/components/kiva/calendar/hooks/use-local-storage.ts +40 -0
- package/src/components/kiva/calendar/hooks/use-media-query.ts +25 -0
- package/src/components/kiva/calendar/hooks.ts +5 -0
- package/src/components/kiva/calendar/index.tsx +27 -0
- package/src/components/kiva/calendar/interfaces.ts +35 -0
- package/src/components/kiva/calendar/schemas.ts +20 -0
- package/src/components/kiva/calendar/settings/settings.tsx +116 -0
- package/src/components/kiva/calendar/skeletons/calendar-header-skeleton.tsx +27 -0
- package/src/components/kiva/calendar/skeletons/calendar-skeleton.tsx +19 -0
- package/src/components/kiva/calendar/skeletons/day-view-skeleton.tsx +40 -0
- package/src/components/kiva/calendar/skeletons/month-view-skeleton.tsx +36 -0
- package/src/components/kiva/calendar/skeletons/week-view-skeleton.tsx +48 -0
- package/src/components/kiva/calendar/skeletons/year-view-skeleton.tsx +42 -0
- package/src/components/kiva/calendar/types.ts +25 -0
- package/src/components/kiva/calendar/views/agenda-view/agenda-events.tsx +150 -0
- package/src/components/kiva/calendar/views/month-view/calendar-month-view.tsx +82 -0
- package/src/components/kiva/calendar/views/month-view/day-cell.tsx +218 -0
- package/src/components/kiva/calendar/views/month-view/event-bullet.tsx +46 -0
- package/src/components/kiva/calendar/views/month-view/month-event-badge.tsx +154 -0
- package/src/components/kiva/calendar/views/timeline/calendar-timeline-view.tsx +100 -0
- package/src/components/kiva/calendar/views/timeline/lib/timeline-layout.ts +130 -0
- package/src/components/kiva/calendar/views/timeline/lib/timeline-model.ts +504 -0
- package/src/components/kiva/calendar/views/timeline/timeline-event-bar.tsx +68 -0
- package/src/components/kiva/calendar/views/timeline/timeline-grid-header.tsx +125 -0
- package/src/components/kiva/calendar/views/timeline/timeline-row.tsx +159 -0
- package/src/components/kiva/calendar/views/timeline/timeline-section.tsx +61 -0
- package/src/components/kiva/calendar/views/timeline/use-timeline-sections.ts +278 -0
- package/src/components/kiva/calendar/views/week-and-day-view/calendar-day-view.tsx +277 -0
- package/src/components/kiva/calendar/views/week-and-day-view/calendar-time-line.tsx +47 -0
- package/src/components/kiva/calendar/views/week-and-day-view/calendar-week-view.tsx +229 -0
- package/src/components/kiva/calendar/views/week-and-day-view/day-view-multi-day-events-row.tsx +79 -0
- package/src/components/kiva/calendar/views/week-and-day-view/event-block.tsx +116 -0
- package/src/components/kiva/calendar/views/week-and-day-view/render-grouped-events.tsx +54 -0
- package/src/components/kiva/calendar/views/week-and-day-view/week-view-multi-day-events-row.tsx +159 -0
- package/src/components/kiva/calendar/views/year-view/calendar-year-view.tsx +159 -0
- package/src/components/kiva/data-table-side-filters/components/side-filter-active-chips.tsx +137 -0
- package/src/components/kiva/data-table-side-filters/components/side-filter-clear.tsx +34 -0
- package/src/components/kiva/data-table-side-filters/components/side-filter-search.tsx +67 -0
- package/src/components/kiva/data-table-side-filters/components/side-filter-section.tsx +77 -0
- package/src/components/kiva/data-table-side-filters/controllers/side-filter-async-options.tsx +354 -0
- package/src/components/kiva/data-table-side-filters/controllers/side-filter-boolean.tsx +66 -0
- package/src/components/kiva/data-table-side-filters/controllers/side-filter-checkbox-list.tsx +137 -0
- package/src/components/kiva/data-table-side-filters/controllers/side-filter-date-range.tsx +204 -0
- package/src/components/kiva/data-table-side-filters/controllers/side-filter-numeric-range.tsx +162 -0
- package/src/components/kiva/data-table-side-filters/controllers/side-filter-options-dropdown.tsx +191 -0
- package/src/components/kiva/data-table-side-filters/controllers/side-filter-text.tsx +53 -0
- package/src/components/kiva/data-table-side-filters/core/query-translator.ts +367 -0
- package/src/components/kiva/data-table-side-filters/core/types.ts +81 -0
- package/src/components/kiva/data-table-side-filters/data-table-side-filters.tsx +483 -0
- package/src/components/kiva/data-table-side-filters/hooks/use-data-table-side-filters.tsx +160 -0
- package/src/components/kiva/data-table-side-filters/hooks/use-show-more.tsx +62 -0
- package/src/components/kiva/data-table-side-filters/index.tsx +44 -0
- package/src/components/kiva/data-table-side-filters/lib/render-mode.ts +62 -0
- package/src/components/kiva/date-time-picker.tsx +163 -0
- package/src/components/kiva/editable-record-detail.tsx +809 -0
- package/src/components/kiva/enum-option-editor/enum-option-editor.tsx +891 -0
- package/src/components/kiva/enum-option-editor/index.tsx +26 -0
- package/src/components/kiva/enum-option-editor/kiva-enum-option-editor.tsx +320 -0
- package/src/components/kiva/enum-option-editor/types.ts +90 -0
- package/src/components/kiva/kanban.tsx +1376 -0
- package/src/components/kiva/kiva-data-export-menu.tsx +543 -0
- package/src/components/kiva/map.tsx +1631 -0
- package/src/components/kiva/pivot-calendar/components/group-sidebar.tsx +95 -0
- package/src/components/kiva/pivot-calendar/components/pivot-calendar-toolbar.tsx +113 -0
- package/src/components/kiva/pivot-calendar/components/stats-cell.tsx +126 -0
- package/src/components/kiva/pivot-calendar/helpers.ts +374 -0
- package/src/components/kiva/pivot-calendar/hooks/use-pivot-calendar.ts +222 -0
- package/src/components/kiva/pivot-calendar/index.tsx +32 -0
- package/src/components/kiva/pivot-calendar/pivot-calendar.tsx +107 -0
- package/src/components/kiva/pivot-calendar/types.ts +154 -0
- package/src/components/kiva/pivot-calendar/views/days-of-month-view.tsx +37 -0
- package/src/components/kiva/pivot-calendar/views/days-of-week-view.tsx +37 -0
- package/src/components/kiva/pivot-calendar/views/month-calendar-view.tsx +154 -0
- package/src/components/kiva/pivot-calendar/views/months-of-year-view.tsx +40 -0
- package/src/components/kiva/pivot-calendar/views/pivot-grid-view.tsx +251 -0
- package/src/components/kiva/pivot-filter/index.tsx +9 -0
- package/src/components/kiva/pivot-filter/pivot-filter-item.tsx +159 -0
- package/src/components/kiva/pivot-filter/pivot-filter-settings.tsx +161 -0
- package/src/components/kiva/pivot-filter/pivot-filter.tsx +187 -0
- package/src/components/kiva/pivot-filter/types.ts +82 -0
- package/src/components/kiva/pivot-grid/hooks/use-pivot-grid.ts +683 -0
- package/src/components/kiva/pivot-grid/index.tsx +23 -0
- package/src/components/kiva/pivot-grid/lib/pivot-grid-color-rules.ts +98 -0
- package/src/components/kiva/pivot-grid/lib/pivot-grid-export.ts +265 -0
- package/src/components/kiva/pivot-grid/lib/pivot-grid-model.ts +1110 -0
- package/src/components/kiva/pivot-grid/pivot-grid-demo-data.ts +200 -0
- package/src/components/kiva/pivot-grid/pivot-grid-export-menu.tsx +66 -0
- package/src/components/kiva/pivot-grid/pivot-grid-toolbar.tsx +85 -0
- package/src/components/kiva/pivot-grid/pivot-grid.tsx +601 -0
- package/src/components/kiva/pivot-grid/types.ts +195 -0
- package/src/components/kiva/place-autocomplete.tsx +484 -0
- package/src/components/kiva/record-delete-confirm-dialog/index.tsx +10 -0
- package/src/components/kiva/record-delete-confirm-dialog/record-delete-confirm-dialog.tsx +266 -0
- package/src/components/kiva/record-delete-confirm-dialog/types.ts +25 -0
- package/src/hooks/kiva/_internal/autonumber-setting.ts +112 -0
- package/src/hooks/kiva/_internal/form-layout-to-view.ts +665 -0
- package/src/hooks/kiva/_internal/kiva-hook-utils.ts +143 -0
- package/src/hooks/kiva/_internal/use-computed-field-evaluator.tsx +310 -0
- package/src/hooks/kiva/_internal/use-field-actions-evaluator.tsx +398 -0
- package/src/hooks/kiva/_internal/use-form-actions-evaluator.tsx +363 -0
- package/src/hooks/kiva/_internal/use-form-view-engine.tsx +2200 -0
- package/src/hooks/kiva/_internal/use-kiva-form-view-fields.tsx +190 -0
- package/src/hooks/kiva/_internal/use-kiva-kanban-cards.tsx +311 -0
- package/src/hooks/kiva/use-data-export.tsx +265 -0
- package/src/hooks/kiva/use-kiva-calendar.tsx +992 -0
- package/src/hooks/kiva/use-kiva-data-export.tsx +173 -0
- package/src/hooks/kiva/use-kiva-data-grid.tsx +4750 -0
- package/src/hooks/kiva/use-kiva-data-view-select.tsx +1273 -0
- package/src/hooks/kiva/use-kiva-form-view.tsx +1581 -0
- package/src/hooks/kiva/use-kiva-inventory.tsx +184 -0
- package/src/hooks/kiva/use-kiva-kanban.tsx +1750 -0
- package/src/hooks/kiva/use-kiva-map-view.tsx +2255 -0
- package/src/hooks/kiva/use-kiva-pivot-calendar.tsx +759 -0
- package/src/hooks/kiva/use-kiva-pivot-filter.tsx +1523 -0
- package/src/hooks/kiva/use-kiva-pivot-grid.tsx +543 -0
- package/src/hooks/kiva/use-kiva-tenant.tsx +313 -0
- package/src/hooks/kiva/use-parameter-persistence.ts +191 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import { Checkbox } from '@kivacore/ui-pro-shared/components/checkbox';
|
|
6
|
+
import { ScrollArea } from '@kivacore/ui-pro-shared/components/scroll-area';
|
|
7
|
+
import { cn } from '@kivacore/ui-pro-shared/lib/utils';
|
|
8
|
+
|
|
9
|
+
import { AvatarThumbnail } from '@kivacore/ui-pro-shared/components/kiva/avatar-thumbnail';
|
|
10
|
+
|
|
11
|
+
import { type IPivotCalendarGroup } from '../types';
|
|
12
|
+
|
|
13
|
+
interface GroupSidebarProps {
|
|
14
|
+
label: string;
|
|
15
|
+
groups: Array<IPivotCalendarGroup>;
|
|
16
|
+
selected: Array<string>;
|
|
17
|
+
onChange: (ids: Array<string>) => void;
|
|
18
|
+
className?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function GroupSidebar({
|
|
22
|
+
label,
|
|
23
|
+
groups,
|
|
24
|
+
selected,
|
|
25
|
+
onChange,
|
|
26
|
+
className
|
|
27
|
+
}: GroupSidebarProps) {
|
|
28
|
+
const allSelected = selected.length === groups.length;
|
|
29
|
+
const noneSelected = selected.length === 0;
|
|
30
|
+
|
|
31
|
+
const toggle = (id: string) => {
|
|
32
|
+
if (selected.includes(id)) {
|
|
33
|
+
onChange(selected.filter(x => x !== id));
|
|
34
|
+
} else {
|
|
35
|
+
onChange([...selected, id]);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const toggleAll = () => {
|
|
40
|
+
if (allSelected) {
|
|
41
|
+
onChange([]);
|
|
42
|
+
} else {
|
|
43
|
+
onChange(groups.map(g => g.id));
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<aside className={cn('flex w-56 shrink-0 flex-col border-r bg-muted/20', className)}>
|
|
49
|
+
<div className="flex items-center justify-between border-b px-3 py-2">
|
|
50
|
+
<span className="text-xs font-semibold uppercase tracking-wide text-muted-foreground">
|
|
51
|
+
{label}
|
|
52
|
+
</span>
|
|
53
|
+
<button
|
|
54
|
+
type="button"
|
|
55
|
+
onClick={toggleAll}
|
|
56
|
+
className="text-xs font-medium text-primary hover:underline">
|
|
57
|
+
{allSelected ? 'Clear' : 'All'}
|
|
58
|
+
</button>
|
|
59
|
+
</div>
|
|
60
|
+
<ScrollArea className="flex-1">
|
|
61
|
+
<ul className="flex flex-col py-1">
|
|
62
|
+
{groups.map((group) => {
|
|
63
|
+
const checked = selected.includes(group.id);
|
|
64
|
+
const dim = !checked && !noneSelected;
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<li key={group.id}>
|
|
68
|
+
<button
|
|
69
|
+
type="button"
|
|
70
|
+
onClick={() => toggle(group.id)}
|
|
71
|
+
className={cn(
|
|
72
|
+
'flex w-full items-center gap-2 px-3 py-1.5 text-left text-sm transition-colors',
|
|
73
|
+
'hover:bg-accent/50',
|
|
74
|
+
dim && 'opacity-60'
|
|
75
|
+
)}>
|
|
76
|
+
<Checkbox
|
|
77
|
+
checked={checked}
|
|
78
|
+
onCheckedChange={() => toggle(group.id)}
|
|
79
|
+
onClick={e => e.stopPropagation()} />
|
|
80
|
+
<AvatarThumbnail
|
|
81
|
+
size={6}
|
|
82
|
+
icon={group.icon ?? null}
|
|
83
|
+
color={group.color ?? null}
|
|
84
|
+
image={group.image ?? null}
|
|
85
|
+
shape="circle" />
|
|
86
|
+
<span className="min-w-0 flex-1 truncate">{group.label}</span>
|
|
87
|
+
</button>
|
|
88
|
+
</li>
|
|
89
|
+
);
|
|
90
|
+
})}
|
|
91
|
+
</ul>
|
|
92
|
+
</ScrollArea>
|
|
93
|
+
</aside>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import { type ReactNode } from 'react';
|
|
6
|
+
|
|
7
|
+
import { ChevronLeftIcon, ChevronRightIcon, PanelLeftIcon } from 'lucide-react';
|
|
8
|
+
|
|
9
|
+
import { Button } from '@kivacore/ui-pro-shared/components/button';
|
|
10
|
+
import {
|
|
11
|
+
Tabs,
|
|
12
|
+
TabsList,
|
|
13
|
+
TabsTrigger
|
|
14
|
+
} from '@kivacore/ui-pro-shared/components/tabs';
|
|
15
|
+
import { cn } from '@kivacore/ui-pro-shared/lib/utils';
|
|
16
|
+
|
|
17
|
+
import { type IPivotCalendarController, type TPivotCalendarView } from '../types';
|
|
18
|
+
|
|
19
|
+
const VIEW_LABELS: Record<TPivotCalendarView, string> = {
|
|
20
|
+
'month-calendar': 'Month',
|
|
21
|
+
'days-of-week': 'Week',
|
|
22
|
+
'days-of-month': 'Days',
|
|
23
|
+
'months-of-year': 'Year'
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
interface PivotCalendarToolbarProps<TData> {
|
|
27
|
+
controller: IPivotCalendarController<TData>;
|
|
28
|
+
visibleViews: Array<TPivotCalendarView>;
|
|
29
|
+
hideViewSwitcher?: boolean;
|
|
30
|
+
hideSidebarToggle?: boolean;
|
|
31
|
+
title?: ReactNode;
|
|
32
|
+
className?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function PivotCalendarToolbar<TData>({
|
|
36
|
+
controller,
|
|
37
|
+
visibleViews,
|
|
38
|
+
hideViewSwitcher = false,
|
|
39
|
+
hideSidebarToggle = false,
|
|
40
|
+
title,
|
|
41
|
+
className
|
|
42
|
+
}: PivotCalendarToolbarProps<TData>) {
|
|
43
|
+
const {
|
|
44
|
+
view,
|
|
45
|
+
setView,
|
|
46
|
+
rangeLabel,
|
|
47
|
+
navigatePrevious,
|
|
48
|
+
navigateNext,
|
|
49
|
+
navigateToday,
|
|
50
|
+
toggleSidebar,
|
|
51
|
+
groupBy
|
|
52
|
+
} = controller;
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<div
|
|
56
|
+
className={cn(
|
|
57
|
+
'flex flex-wrap items-center justify-between gap-2 border-b bg-card px-3 py-2',
|
|
58
|
+
className
|
|
59
|
+
)}>
|
|
60
|
+
<div className="flex items-center gap-2">
|
|
61
|
+
{!hideSidebarToggle && groupBy && view === 'month-calendar' ? (
|
|
62
|
+
<Button
|
|
63
|
+
variant="ghost"
|
|
64
|
+
size="icon"
|
|
65
|
+
onClick={toggleSidebar}
|
|
66
|
+
aria-label="Toggle group sidebar">
|
|
67
|
+
<PanelLeftIcon className="size-4" />
|
|
68
|
+
</Button>
|
|
69
|
+
) : null}
|
|
70
|
+
|
|
71
|
+
<Button
|
|
72
|
+
variant="outline"
|
|
73
|
+
size="sm"
|
|
74
|
+
onClick={navigateToday}>
|
|
75
|
+
Today
|
|
76
|
+
</Button>
|
|
77
|
+
|
|
78
|
+
<div className="flex items-center">
|
|
79
|
+
<Button
|
|
80
|
+
variant="ghost"
|
|
81
|
+
size="icon"
|
|
82
|
+
onClick={navigatePrevious}
|
|
83
|
+
aria-label="Previous period">
|
|
84
|
+
<ChevronLeftIcon className="size-4" />
|
|
85
|
+
</Button>
|
|
86
|
+
<Button
|
|
87
|
+
variant="ghost"
|
|
88
|
+
size="icon"
|
|
89
|
+
onClick={navigateNext}
|
|
90
|
+
aria-label="Next period">
|
|
91
|
+
<ChevronRightIcon className="size-4" />
|
|
92
|
+
</Button>
|
|
93
|
+
</div>
|
|
94
|
+
|
|
95
|
+
<div className="text-sm font-semibold text-foreground">
|
|
96
|
+
{title ?? rangeLabel}
|
|
97
|
+
</div>
|
|
98
|
+
</div>
|
|
99
|
+
|
|
100
|
+
{!hideViewSwitcher && visibleViews.length > 1 ? (
|
|
101
|
+
<Tabs value={view} onValueChange={value => setView(value as TPivotCalendarView)}>
|
|
102
|
+
<TabsList>
|
|
103
|
+
{visibleViews.map(v => (
|
|
104
|
+
<TabsTrigger key={v} value={v}>
|
|
105
|
+
{VIEW_LABELS[v]}
|
|
106
|
+
</TabsTrigger>
|
|
107
|
+
))}
|
|
108
|
+
</TabsList>
|
|
109
|
+
</Tabs>
|
|
110
|
+
) : null}
|
|
111
|
+
</div>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import { type ReactNode } from 'react';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
Tooltip,
|
|
9
|
+
TooltipContent,
|
|
10
|
+
TooltipTrigger
|
|
11
|
+
} from '@kivacore/ui-pro-shared/components/tooltip';
|
|
12
|
+
import { cn } from '@kivacore/ui-pro-shared/lib/utils';
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
type IPivotCalendarMeasure,
|
|
16
|
+
type IPivotCalendarMeasureValue
|
|
17
|
+
} from '../types';
|
|
18
|
+
|
|
19
|
+
const ZERO_TEXT = 'text-muted-foreground/40';
|
|
20
|
+
|
|
21
|
+
export type StatsCellLayout = 'horizontal' | 'vertical' | 'auto';
|
|
22
|
+
|
|
23
|
+
interface StatsCellProps {
|
|
24
|
+
measures: Array<IPivotCalendarMeasure<unknown>>;
|
|
25
|
+
values: Array<IPivotCalendarMeasureValue>;
|
|
26
|
+
formatValue: (measureId: string, value: number) => string;
|
|
27
|
+
/** `horizontal` = side by side, `vertical` = stacked, `auto` picks based on count. */
|
|
28
|
+
grid?: StatsCellLayout;
|
|
29
|
+
className?: string;
|
|
30
|
+
emptyState?: ReactNode;
|
|
31
|
+
/** Fires when a measure value is clicked. Receives raw + formatted value. */
|
|
32
|
+
onMeasureClick?: (measure: IPivotCalendarMeasure<unknown>, value: number, formatted: string) => void;
|
|
33
|
+
/** When true, tiles render with interactive hover/cursor styling. */
|
|
34
|
+
interactive?: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Renders up to 2 measure values. Labels are NOT rendered here — show them in
|
|
39
|
+
* a header/legend instead so they're not duplicated for every cell.
|
|
40
|
+
*/
|
|
41
|
+
export function StatsCell({
|
|
42
|
+
measures,
|
|
43
|
+
values,
|
|
44
|
+
formatValue,
|
|
45
|
+
grid = 'auto',
|
|
46
|
+
className,
|
|
47
|
+
emptyState,
|
|
48
|
+
onMeasureClick,
|
|
49
|
+
interactive
|
|
50
|
+
}: StatsCellProps) {
|
|
51
|
+
const limited = measures.slice(0, 2);
|
|
52
|
+
const valueByMeasure = new Map(values.map(v => [v.measureId, v.value]));
|
|
53
|
+
|
|
54
|
+
const hasAny = limited.some((m) => {
|
|
55
|
+
const v = valueByMeasure.get(m.id);
|
|
56
|
+
|
|
57
|
+
return typeof v === 'number' && v !== 0;
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
if (!hasAny && emptyState !== undefined) {
|
|
61
|
+
return (
|
|
62
|
+
<div className={cn('flex items-center justify-center text-xs text-muted-foreground/40', className)}>
|
|
63
|
+
{emptyState}
|
|
64
|
+
</div>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const layout: Exclude<StatsCellLayout, 'auto'> = grid === 'auto' ? 'vertical' : grid;
|
|
69
|
+
const gridClasses = layout === 'horizontal' ? 'grid-cols-2 grid-rows-1' : 'grid-cols-1 grid-rows-2';
|
|
70
|
+
const isInteractive = Boolean(interactive && onMeasureClick);
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<div className={cn('grid w-full gap-1', gridClasses, className)}>
|
|
74
|
+
{limited.map((measure) => {
|
|
75
|
+
const raw = valueByMeasure.get(measure.id) ?? 0;
|
|
76
|
+
const display = formatValue(measure.id, raw);
|
|
77
|
+
const isZero = raw === 0;
|
|
78
|
+
const dotColor = measure.color ?? 'var(--primary)';
|
|
79
|
+
const clickable = isInteractive && !isZero;
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<Tooltip key={measure.id}>
|
|
83
|
+
<TooltipTrigger asChild>
|
|
84
|
+
<button
|
|
85
|
+
type="button"
|
|
86
|
+
disabled={!clickable}
|
|
87
|
+
onClick={(event) => {
|
|
88
|
+
if (!clickable) return;
|
|
89
|
+
event.stopPropagation();
|
|
90
|
+
onMeasureClick?.(measure, raw, display);
|
|
91
|
+
}}
|
|
92
|
+
className={cn(
|
|
93
|
+
'flex min-w-0 items-center justify-end gap-1 rounded px-1.5 py-1 text-left',
|
|
94
|
+
'bg-muted/40 transition-colors',
|
|
95
|
+
clickable ? 'cursor-pointer hover:bg-primary/15 hover:ring-1 hover:ring-primary/30 focus-visible:outline focus-visible:outline-2 focus-visible:outline-primary/40' : 'cursor-default hover:bg-muted/70 disabled:opacity-100',
|
|
96
|
+
isZero && 'bg-muted/20'
|
|
97
|
+
)}>
|
|
98
|
+
<span
|
|
99
|
+
className="size-1.5 shrink-0 rounded-full"
|
|
100
|
+
style={{ backgroundColor: dotColor }}
|
|
101
|
+
aria-hidden />
|
|
102
|
+
<span
|
|
103
|
+
className={cn(
|
|
104
|
+
'truncate text-xs font-semibold leading-none tabular-nums text-foreground',
|
|
105
|
+
isZero && ZERO_TEXT
|
|
106
|
+
)}>
|
|
107
|
+
{display}
|
|
108
|
+
</span>
|
|
109
|
+
</button>
|
|
110
|
+
</TooltipTrigger>
|
|
111
|
+
<TooltipContent side="top" className="text-xs">
|
|
112
|
+
<div className="font-medium">{measure.label}</div>
|
|
113
|
+
<div className="tabular-nums">{display}</div>
|
|
114
|
+
{measure.description ? (
|
|
115
|
+
<div className="mt-0.5 text-xs opacity-80">{measure.description}</div>
|
|
116
|
+
) : null}
|
|
117
|
+
{clickable ? (
|
|
118
|
+
<div className="mt-1 text-xs opacity-70">Click to drill down</div>
|
|
119
|
+
) : null}
|
|
120
|
+
</TooltipContent>
|
|
121
|
+
</Tooltip>
|
|
122
|
+
);
|
|
123
|
+
})}
|
|
124
|
+
</div>
|
|
125
|
+
);
|
|
126
|
+
}
|
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
import {
|
|
4
|
+
addMonths,
|
|
5
|
+
addWeeks,
|
|
6
|
+
addYears,
|
|
7
|
+
eachDayOfInterval,
|
|
8
|
+
endOfMonth,
|
|
9
|
+
endOfWeek,
|
|
10
|
+
endOfYear,
|
|
11
|
+
format,
|
|
12
|
+
getMonth,
|
|
13
|
+
isSameDay,
|
|
14
|
+
parseISO,
|
|
15
|
+
startOfMonth,
|
|
16
|
+
startOfWeek,
|
|
17
|
+
startOfYear,
|
|
18
|
+
subMonths,
|
|
19
|
+
subWeeks,
|
|
20
|
+
subYears
|
|
21
|
+
} from 'date-fns';
|
|
22
|
+
|
|
23
|
+
import {
|
|
24
|
+
type IPivotCalendarMeasure,
|
|
25
|
+
type IPivotCalendarMeasureValue,
|
|
26
|
+
type TPivotCalendarBucketKind,
|
|
27
|
+
type TPivotCalendarView
|
|
28
|
+
} from './types';
|
|
29
|
+
|
|
30
|
+
export function toDate(value: Date | string): Date {
|
|
31
|
+
return typeof value === 'string' ? parseISO(value) : value;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function bucketKindForView(view: TPivotCalendarView): TPivotCalendarBucketKind {
|
|
35
|
+
switch (view) {
|
|
36
|
+
case 'months-of-year':
|
|
37
|
+
return 'month';
|
|
38
|
+
|
|
39
|
+
case 'month-calendar':
|
|
40
|
+
|
|
41
|
+
case 'days-of-week':
|
|
42
|
+
|
|
43
|
+
case 'days-of-month':
|
|
44
|
+
|
|
45
|
+
default:
|
|
46
|
+
return 'day';
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function bucketKeyForDate(
|
|
51
|
+
date: Date,
|
|
52
|
+
view: TPivotCalendarView
|
|
53
|
+
): string {
|
|
54
|
+
const kind = bucketKindForView(view);
|
|
55
|
+
|
|
56
|
+
if (kind === 'month') return format(date, 'yyyy-MM');
|
|
57
|
+
|
|
58
|
+
return format(date, 'yyyy-MM-dd');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function isDateInActiveRange(
|
|
62
|
+
date: Date,
|
|
63
|
+
reference: Date,
|
|
64
|
+
view: TPivotCalendarView
|
|
65
|
+
): boolean {
|
|
66
|
+
switch (view) {
|
|
67
|
+
case 'month-calendar': {
|
|
68
|
+
return getMonth(date) === getMonth(reference) && date.getFullYear() === reference.getFullYear();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
case 'days-of-week': {
|
|
72
|
+
const start = startOfWeek(reference);
|
|
73
|
+
const end = endOfWeek(reference);
|
|
74
|
+
|
|
75
|
+
return date >= start && date <= end;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
case 'days-of-month': {
|
|
79
|
+
return getMonth(date) === getMonth(reference) && date.getFullYear() === reference.getFullYear();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
case 'months-of-year': {
|
|
83
|
+
return date.getFullYear() === reference.getFullYear();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
default:
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function getRangeForView(
|
|
92
|
+
reference: Date,
|
|
93
|
+
view: TPivotCalendarView
|
|
94
|
+
): { start: Date; end: Date } {
|
|
95
|
+
switch (view) {
|
|
96
|
+
case 'days-of-week':
|
|
97
|
+
return { start: startOfWeek(reference), end: endOfWeek(reference) };
|
|
98
|
+
|
|
99
|
+
case 'months-of-year':
|
|
100
|
+
return { start: startOfYear(reference), end: endOfYear(reference) };
|
|
101
|
+
|
|
102
|
+
case 'days-of-month':
|
|
103
|
+
|
|
104
|
+
case 'month-calendar':
|
|
105
|
+
|
|
106
|
+
default:
|
|
107
|
+
return { start: startOfMonth(reference), end: endOfMonth(reference) };
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Given a bucket key produced by `bucketKeyForDate`, returns the inclusive
|
|
113
|
+
* date range it represents. Day-buckets resolve to start/end of that day,
|
|
114
|
+
* month-buckets to start/end of that calendar month.
|
|
115
|
+
*/
|
|
116
|
+
export function getRangeForBucket(
|
|
117
|
+
bucket: string,
|
|
118
|
+
view: TPivotCalendarView
|
|
119
|
+
): { start: Date; end: Date } {
|
|
120
|
+
if (view === 'months-of-year') {
|
|
121
|
+
const [yearStr, monthStr] = bucket.split('-');
|
|
122
|
+
const year = Number(yearStr);
|
|
123
|
+
const month = Number(monthStr) - 1;
|
|
124
|
+
const start = new Date(year, month, 1, 0, 0, 0, 0);
|
|
125
|
+
const end = new Date(year, month + 1, 0, 23, 59, 59, 999);
|
|
126
|
+
|
|
127
|
+
return { start, end };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const [yearStr, monthStr, dayStr] = bucket.split('-');
|
|
131
|
+
const start = new Date(Number(yearStr), Number(monthStr) - 1, Number(dayStr), 0, 0, 0, 0);
|
|
132
|
+
const end = new Date(Number(yearStr), Number(monthStr) - 1, Number(dayStr), 23, 59, 59, 999);
|
|
133
|
+
|
|
134
|
+
return { start, end };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function navigateDate(
|
|
138
|
+
reference: Date,
|
|
139
|
+
view: TPivotCalendarView,
|
|
140
|
+
direction: 'previous' | 'next'
|
|
141
|
+
): Date {
|
|
142
|
+
const sign = direction === 'next' ? 1 : -1;
|
|
143
|
+
|
|
144
|
+
switch (view) {
|
|
145
|
+
case 'days-of-week':
|
|
146
|
+
return sign === 1 ? addWeeks(reference, 1) : subWeeks(reference, 1);
|
|
147
|
+
|
|
148
|
+
case 'months-of-year':
|
|
149
|
+
return sign === 1 ? addYears(reference, 1) : subYears(reference, 1);
|
|
150
|
+
|
|
151
|
+
case 'month-calendar':
|
|
152
|
+
|
|
153
|
+
case 'days-of-month':
|
|
154
|
+
|
|
155
|
+
default:
|
|
156
|
+
return sign === 1 ? addMonths(reference, 1) : subMonths(reference, 1);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function rangeLabelForView(
|
|
161
|
+
reference: Date,
|
|
162
|
+
view: TPivotCalendarView
|
|
163
|
+
): string {
|
|
164
|
+
switch (view) {
|
|
165
|
+
case 'days-of-week': {
|
|
166
|
+
const start = startOfWeek(reference);
|
|
167
|
+
const end = endOfWeek(reference);
|
|
168
|
+
|
|
169
|
+
if (start.getMonth() === end.getMonth()) {
|
|
170
|
+
return `${format(start, 'MMM d')} – ${format(end, 'd, yyyy')}`;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return `${format(start, 'MMM d')} – ${format(end, 'MMM d, yyyy')}`;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
case 'months-of-year':
|
|
177
|
+
return format(reference, 'yyyy');
|
|
178
|
+
|
|
179
|
+
case 'days-of-month':
|
|
180
|
+
|
|
181
|
+
case 'month-calendar':
|
|
182
|
+
|
|
183
|
+
default:
|
|
184
|
+
return format(reference, 'MMMM yyyy');
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export function getMonthCells(reference: Date): Array<{ day: number; date: Date; currentMonth: boolean }> {
|
|
189
|
+
const year = reference.getFullYear();
|
|
190
|
+
const month = reference.getMonth();
|
|
191
|
+
const daysInMonth = endOfMonth(reference).getDate();
|
|
192
|
+
const firstDayOfMonth = startOfMonth(reference).getDay();
|
|
193
|
+
const daysInPrevMonth = endOfMonth(new Date(year, month - 1)).getDate();
|
|
194
|
+
const totalDays = firstDayOfMonth + daysInMonth;
|
|
195
|
+
|
|
196
|
+
const prev = Array.from({ length: firstDayOfMonth }, (_, i) => ({
|
|
197
|
+
day: daysInPrevMonth - firstDayOfMonth + i + 1,
|
|
198
|
+
currentMonth: false,
|
|
199
|
+
date: new Date(year, month - 1, daysInPrevMonth - firstDayOfMonth + i + 1)
|
|
200
|
+
}));
|
|
201
|
+
|
|
202
|
+
const current = Array.from({ length: daysInMonth }, (_, i) => ({
|
|
203
|
+
day: i + 1,
|
|
204
|
+
currentMonth: true,
|
|
205
|
+
date: new Date(year, month, i + 1)
|
|
206
|
+
}));
|
|
207
|
+
|
|
208
|
+
const next = Array.from(
|
|
209
|
+
{ length: (7 - (totalDays % 7)) % 7 },
|
|
210
|
+
(_, i) => ({
|
|
211
|
+
day: i + 1,
|
|
212
|
+
currentMonth: false,
|
|
213
|
+
date: new Date(year, month + 1, i + 1)
|
|
214
|
+
})
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
return [...prev, ...current, ...next];
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export function getDaysOfMonth(reference: Date): Array<Date> {
|
|
221
|
+
return eachDayOfInterval({
|
|
222
|
+
start: startOfMonth(reference),
|
|
223
|
+
end: endOfMonth(reference)
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export function getDaysOfWeek(reference: Date): Array<Date> {
|
|
228
|
+
return eachDayOfInterval({
|
|
229
|
+
start: startOfWeek(reference),
|
|
230
|
+
end: endOfWeek(reference)
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export function getMonthsOfYear(reference: Date): Array<Date> {
|
|
235
|
+
const year = reference.getFullYear();
|
|
236
|
+
|
|
237
|
+
return Array.from({ length: 12 }, (_, i) => new Date(year, i, 1));
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export function aggregateValues<TData>(
|
|
241
|
+
rows: Array<TData>,
|
|
242
|
+
measure: IPivotCalendarMeasure<TData>
|
|
243
|
+
): number {
|
|
244
|
+
if (rows.length === 0) return 0;
|
|
245
|
+
|
|
246
|
+
if (measure.aggregate === 'count') {
|
|
247
|
+
if (!measure.getValue) return rows.length;
|
|
248
|
+
let count = 0;
|
|
249
|
+
|
|
250
|
+
for (const row of rows) {
|
|
251
|
+
const value = measure.getValue(row);
|
|
252
|
+
|
|
253
|
+
if (value != null) count += 1;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
return count;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const numbers: Array<number> = [];
|
|
260
|
+
|
|
261
|
+
for (const row of rows) {
|
|
262
|
+
const raw = measure.getValue?.(row);
|
|
263
|
+
|
|
264
|
+
if (typeof raw === 'number' && Number.isFinite(raw)) {
|
|
265
|
+
numbers.push(raw);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (numbers.length === 0) return 0;
|
|
270
|
+
|
|
271
|
+
switch (measure.aggregate) {
|
|
272
|
+
case 'sum':
|
|
273
|
+
return numbers.reduce((acc, n) => acc + n, 0);
|
|
274
|
+
|
|
275
|
+
case 'avg':
|
|
276
|
+
return numbers.reduce((acc, n) => acc + n, 0) / numbers.length;
|
|
277
|
+
|
|
278
|
+
case 'min':
|
|
279
|
+
return Math.min(...numbers);
|
|
280
|
+
|
|
281
|
+
case 'max':
|
|
282
|
+
return Math.max(...numbers);
|
|
283
|
+
|
|
284
|
+
default:
|
|
285
|
+
return 0;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
export function buildLocalCellMap<TData>(params: {
|
|
290
|
+
data: Array<TData>;
|
|
291
|
+
getDate: (row: TData) => Date | string;
|
|
292
|
+
view: TPivotCalendarView;
|
|
293
|
+
measures: Array<IPivotCalendarMeasure<TData>>;
|
|
294
|
+
groupBy?: { getId: (row: TData) => string | null | undefined };
|
|
295
|
+
}): Map<string, Array<IPivotCalendarMeasureValue>> {
|
|
296
|
+
const {
|
|
297
|
+
data, getDate, view, measures, groupBy
|
|
298
|
+
} = params;
|
|
299
|
+
const buckets = new Map<string, Array<TData>>();
|
|
300
|
+
|
|
301
|
+
for (const row of data) {
|
|
302
|
+
const date = toDate(getDate(row));
|
|
303
|
+
|
|
304
|
+
if (Number.isNaN(date.getTime())) continue;
|
|
305
|
+
|
|
306
|
+
const bucket = bucketKeyForDate(date, view);
|
|
307
|
+
const groupId = groupBy ? (groupBy.getId(row) ?? '') : '';
|
|
308
|
+
const key = `${bucket}::${groupId}`;
|
|
309
|
+
const list = buckets.get(key);
|
|
310
|
+
|
|
311
|
+
if (list) {
|
|
312
|
+
list.push(row);
|
|
313
|
+
} else {
|
|
314
|
+
buckets.set(key, [row]);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const result = new Map<string, Array<IPivotCalendarMeasureValue>>();
|
|
319
|
+
|
|
320
|
+
for (const [key, rows] of buckets) {
|
|
321
|
+
const values: Array<IPivotCalendarMeasureValue> = measures.map(measure => ({
|
|
322
|
+
measureId: measure.id,
|
|
323
|
+
value: aggregateValues(rows, measure)
|
|
324
|
+
}));
|
|
325
|
+
|
|
326
|
+
result.set(key, values);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
return result;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
export function buildRemoteCellMap(
|
|
333
|
+
cells: Array<{ bucket: string; groupId?: string | null; values: Array<IPivotCalendarMeasureValue> }>
|
|
334
|
+
): Map<string, Array<IPivotCalendarMeasureValue>> {
|
|
335
|
+
const result = new Map<string, Array<IPivotCalendarMeasureValue>>();
|
|
336
|
+
|
|
337
|
+
for (const cell of cells) {
|
|
338
|
+
const key = `${cell.bucket}::${cell.groupId ?? ''}`;
|
|
339
|
+
|
|
340
|
+
result.set(key, cell.values);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
return result;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
export function sumCellValues(
|
|
347
|
+
cellMap: Map<string, Array<IPivotCalendarMeasureValue>>,
|
|
348
|
+
bucket: string,
|
|
349
|
+
groupIds: Array<string> | null
|
|
350
|
+
): Array<IPivotCalendarMeasureValue> {
|
|
351
|
+
if (groupIds == null) {
|
|
352
|
+
return cellMap.get(`${bucket}::`) ?? [];
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
if (groupIds.length === 0) return [];
|
|
356
|
+
|
|
357
|
+
const totals = new Map<string, number>();
|
|
358
|
+
|
|
359
|
+
for (const groupId of groupIds) {
|
|
360
|
+
const values = cellMap.get(`${bucket}::${groupId}`);
|
|
361
|
+
|
|
362
|
+
if (!values) continue;
|
|
363
|
+
|
|
364
|
+
for (const v of values) {
|
|
365
|
+
totals.set(v.measureId, (totals.get(v.measureId) ?? 0) + v.value);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
return Array.from(totals.entries()).map(([measureId, value]) => ({ measureId, value }));
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
export function isToday(date: Date): boolean {
|
|
373
|
+
return isSameDay(date, new Date());
|
|
374
|
+
}
|