@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.
Files changed (145) hide show
  1. package/package.json +167 -1
  2. package/src/.kiva/config.json +27 -0
  3. package/src/components/avatar-group.tsx +222 -0
  4. package/src/components/kiva/bulk-update-dialog/bulk-update-dialog.tsx +240 -0
  5. package/src/components/kiva/bulk-update-dialog/index.tsx +6 -0
  6. package/src/components/kiva/bulk-update-dialog/types.ts +33 -0
  7. package/src/components/kiva/calendar/animations.ts +40 -0
  8. package/src/components/kiva/calendar/calendar-body.tsx +106 -0
  9. package/src/components/kiva/calendar/calendar-sidebar.tsx +103 -0
  10. package/src/components/kiva/calendar/calendar.tsx +243 -0
  11. package/src/components/kiva/calendar/constants.ts +12 -0
  12. package/src/components/kiva/calendar/contexts/calendar-context.tsx +696 -0
  13. package/src/components/kiva/calendar/contexts/dnd-context.tsx +173 -0
  14. package/src/components/kiva/calendar/dialogs/add-edit-event-dialog.tsx +287 -0
  15. package/src/components/kiva/calendar/dialogs/delete-event-dialog.tsx +73 -0
  16. package/src/components/kiva/calendar/dialogs/event-details-dialog.tsx +163 -0
  17. package/src/components/kiva/calendar/dialogs/events-list-dialog.tsx +122 -0
  18. package/src/components/kiva/calendar/dnd/draggable-event.tsx +66 -0
  19. package/src/components/kiva/calendar/dnd/droppable-area.tsx +53 -0
  20. package/src/components/kiva/calendar/dnd/resizable-event.tsx +190 -0
  21. package/src/components/kiva/calendar/header/calendar-header.tsx +84 -0
  22. package/src/components/kiva/calendar/header/date-navigator.tsx +188 -0
  23. package/src/components/kiva/calendar/header/filter.tsx +80 -0
  24. package/src/components/kiva/calendar/header/today-button.tsx +49 -0
  25. package/src/components/kiva/calendar/header/user-select.tsx +111 -0
  26. package/src/components/kiva/calendar/header/view-tabs.tsx +144 -0
  27. package/src/components/kiva/calendar/helpers.ts +617 -0
  28. package/src/components/kiva/calendar/hooks/use-disclosure.ts +19 -0
  29. package/src/components/kiva/calendar/hooks/use-local-storage.ts +40 -0
  30. package/src/components/kiva/calendar/hooks/use-media-query.ts +25 -0
  31. package/src/components/kiva/calendar/hooks.ts +5 -0
  32. package/src/components/kiva/calendar/index.tsx +27 -0
  33. package/src/components/kiva/calendar/interfaces.ts +35 -0
  34. package/src/components/kiva/calendar/schemas.ts +20 -0
  35. package/src/components/kiva/calendar/settings/settings.tsx +116 -0
  36. package/src/components/kiva/calendar/skeletons/calendar-header-skeleton.tsx +27 -0
  37. package/src/components/kiva/calendar/skeletons/calendar-skeleton.tsx +19 -0
  38. package/src/components/kiva/calendar/skeletons/day-view-skeleton.tsx +40 -0
  39. package/src/components/kiva/calendar/skeletons/month-view-skeleton.tsx +36 -0
  40. package/src/components/kiva/calendar/skeletons/week-view-skeleton.tsx +48 -0
  41. package/src/components/kiva/calendar/skeletons/year-view-skeleton.tsx +42 -0
  42. package/src/components/kiva/calendar/types.ts +25 -0
  43. package/src/components/kiva/calendar/views/agenda-view/agenda-events.tsx +150 -0
  44. package/src/components/kiva/calendar/views/month-view/calendar-month-view.tsx +82 -0
  45. package/src/components/kiva/calendar/views/month-view/day-cell.tsx +218 -0
  46. package/src/components/kiva/calendar/views/month-view/event-bullet.tsx +46 -0
  47. package/src/components/kiva/calendar/views/month-view/month-event-badge.tsx +154 -0
  48. package/src/components/kiva/calendar/views/timeline/calendar-timeline-view.tsx +100 -0
  49. package/src/components/kiva/calendar/views/timeline/lib/timeline-layout.ts +130 -0
  50. package/src/components/kiva/calendar/views/timeline/lib/timeline-model.ts +504 -0
  51. package/src/components/kiva/calendar/views/timeline/timeline-event-bar.tsx +68 -0
  52. package/src/components/kiva/calendar/views/timeline/timeline-grid-header.tsx +125 -0
  53. package/src/components/kiva/calendar/views/timeline/timeline-row.tsx +159 -0
  54. package/src/components/kiva/calendar/views/timeline/timeline-section.tsx +61 -0
  55. package/src/components/kiva/calendar/views/timeline/use-timeline-sections.ts +278 -0
  56. package/src/components/kiva/calendar/views/week-and-day-view/calendar-day-view.tsx +277 -0
  57. package/src/components/kiva/calendar/views/week-and-day-view/calendar-time-line.tsx +47 -0
  58. package/src/components/kiva/calendar/views/week-and-day-view/calendar-week-view.tsx +229 -0
  59. package/src/components/kiva/calendar/views/week-and-day-view/day-view-multi-day-events-row.tsx +79 -0
  60. package/src/components/kiva/calendar/views/week-and-day-view/event-block.tsx +116 -0
  61. package/src/components/kiva/calendar/views/week-and-day-view/render-grouped-events.tsx +54 -0
  62. package/src/components/kiva/calendar/views/week-and-day-view/week-view-multi-day-events-row.tsx +159 -0
  63. package/src/components/kiva/calendar/views/year-view/calendar-year-view.tsx +159 -0
  64. package/src/components/kiva/data-table-side-filters/components/side-filter-active-chips.tsx +137 -0
  65. package/src/components/kiva/data-table-side-filters/components/side-filter-clear.tsx +34 -0
  66. package/src/components/kiva/data-table-side-filters/components/side-filter-search.tsx +67 -0
  67. package/src/components/kiva/data-table-side-filters/components/side-filter-section.tsx +77 -0
  68. package/src/components/kiva/data-table-side-filters/controllers/side-filter-async-options.tsx +354 -0
  69. package/src/components/kiva/data-table-side-filters/controllers/side-filter-boolean.tsx +66 -0
  70. package/src/components/kiva/data-table-side-filters/controllers/side-filter-checkbox-list.tsx +137 -0
  71. package/src/components/kiva/data-table-side-filters/controllers/side-filter-date-range.tsx +204 -0
  72. package/src/components/kiva/data-table-side-filters/controllers/side-filter-numeric-range.tsx +162 -0
  73. package/src/components/kiva/data-table-side-filters/controllers/side-filter-options-dropdown.tsx +191 -0
  74. package/src/components/kiva/data-table-side-filters/controllers/side-filter-text.tsx +53 -0
  75. package/src/components/kiva/data-table-side-filters/core/query-translator.ts +367 -0
  76. package/src/components/kiva/data-table-side-filters/core/types.ts +81 -0
  77. package/src/components/kiva/data-table-side-filters/data-table-side-filters.tsx +483 -0
  78. package/src/components/kiva/data-table-side-filters/hooks/use-data-table-side-filters.tsx +160 -0
  79. package/src/components/kiva/data-table-side-filters/hooks/use-show-more.tsx +62 -0
  80. package/src/components/kiva/data-table-side-filters/index.tsx +44 -0
  81. package/src/components/kiva/data-table-side-filters/lib/render-mode.ts +62 -0
  82. package/src/components/kiva/date-time-picker.tsx +163 -0
  83. package/src/components/kiva/editable-record-detail.tsx +809 -0
  84. package/src/components/kiva/enum-option-editor/enum-option-editor.tsx +891 -0
  85. package/src/components/kiva/enum-option-editor/index.tsx +26 -0
  86. package/src/components/kiva/enum-option-editor/kiva-enum-option-editor.tsx +320 -0
  87. package/src/components/kiva/enum-option-editor/types.ts +90 -0
  88. package/src/components/kiva/kanban.tsx +1376 -0
  89. package/src/components/kiva/kiva-data-export-menu.tsx +543 -0
  90. package/src/components/kiva/map.tsx +1631 -0
  91. package/src/components/kiva/pivot-calendar/components/group-sidebar.tsx +95 -0
  92. package/src/components/kiva/pivot-calendar/components/pivot-calendar-toolbar.tsx +113 -0
  93. package/src/components/kiva/pivot-calendar/components/stats-cell.tsx +126 -0
  94. package/src/components/kiva/pivot-calendar/helpers.ts +374 -0
  95. package/src/components/kiva/pivot-calendar/hooks/use-pivot-calendar.ts +222 -0
  96. package/src/components/kiva/pivot-calendar/index.tsx +32 -0
  97. package/src/components/kiva/pivot-calendar/pivot-calendar.tsx +107 -0
  98. package/src/components/kiva/pivot-calendar/types.ts +154 -0
  99. package/src/components/kiva/pivot-calendar/views/days-of-month-view.tsx +37 -0
  100. package/src/components/kiva/pivot-calendar/views/days-of-week-view.tsx +37 -0
  101. package/src/components/kiva/pivot-calendar/views/month-calendar-view.tsx +154 -0
  102. package/src/components/kiva/pivot-calendar/views/months-of-year-view.tsx +40 -0
  103. package/src/components/kiva/pivot-calendar/views/pivot-grid-view.tsx +251 -0
  104. package/src/components/kiva/pivot-filter/index.tsx +9 -0
  105. package/src/components/kiva/pivot-filter/pivot-filter-item.tsx +159 -0
  106. package/src/components/kiva/pivot-filter/pivot-filter-settings.tsx +161 -0
  107. package/src/components/kiva/pivot-filter/pivot-filter.tsx +187 -0
  108. package/src/components/kiva/pivot-filter/types.ts +82 -0
  109. package/src/components/kiva/pivot-grid/hooks/use-pivot-grid.ts +683 -0
  110. package/src/components/kiva/pivot-grid/index.tsx +23 -0
  111. package/src/components/kiva/pivot-grid/lib/pivot-grid-color-rules.ts +98 -0
  112. package/src/components/kiva/pivot-grid/lib/pivot-grid-export.ts +265 -0
  113. package/src/components/kiva/pivot-grid/lib/pivot-grid-model.ts +1110 -0
  114. package/src/components/kiva/pivot-grid/pivot-grid-demo-data.ts +200 -0
  115. package/src/components/kiva/pivot-grid/pivot-grid-export-menu.tsx +66 -0
  116. package/src/components/kiva/pivot-grid/pivot-grid-toolbar.tsx +85 -0
  117. package/src/components/kiva/pivot-grid/pivot-grid.tsx +601 -0
  118. package/src/components/kiva/pivot-grid/types.ts +195 -0
  119. package/src/components/kiva/place-autocomplete.tsx +484 -0
  120. package/src/components/kiva/record-delete-confirm-dialog/index.tsx +10 -0
  121. package/src/components/kiva/record-delete-confirm-dialog/record-delete-confirm-dialog.tsx +266 -0
  122. package/src/components/kiva/record-delete-confirm-dialog/types.ts +25 -0
  123. package/src/hooks/kiva/_internal/autonumber-setting.ts +112 -0
  124. package/src/hooks/kiva/_internal/form-layout-to-view.ts +665 -0
  125. package/src/hooks/kiva/_internal/kiva-hook-utils.ts +143 -0
  126. package/src/hooks/kiva/_internal/use-computed-field-evaluator.tsx +310 -0
  127. package/src/hooks/kiva/_internal/use-field-actions-evaluator.tsx +398 -0
  128. package/src/hooks/kiva/_internal/use-form-actions-evaluator.tsx +363 -0
  129. package/src/hooks/kiva/_internal/use-form-view-engine.tsx +2200 -0
  130. package/src/hooks/kiva/_internal/use-kiva-form-view-fields.tsx +190 -0
  131. package/src/hooks/kiva/_internal/use-kiva-kanban-cards.tsx +311 -0
  132. package/src/hooks/kiva/use-data-export.tsx +265 -0
  133. package/src/hooks/kiva/use-kiva-calendar.tsx +992 -0
  134. package/src/hooks/kiva/use-kiva-data-export.tsx +173 -0
  135. package/src/hooks/kiva/use-kiva-data-grid.tsx +4750 -0
  136. package/src/hooks/kiva/use-kiva-data-view-select.tsx +1273 -0
  137. package/src/hooks/kiva/use-kiva-form-view.tsx +1581 -0
  138. package/src/hooks/kiva/use-kiva-inventory.tsx +184 -0
  139. package/src/hooks/kiva/use-kiva-kanban.tsx +1750 -0
  140. package/src/hooks/kiva/use-kiva-map-view.tsx +2255 -0
  141. package/src/hooks/kiva/use-kiva-pivot-calendar.tsx +759 -0
  142. package/src/hooks/kiva/use-kiva-pivot-filter.tsx +1523 -0
  143. package/src/hooks/kiva/use-kiva-pivot-grid.tsx +543 -0
  144. package/src/hooks/kiva/use-kiva-tenant.tsx +313 -0
  145. package/src/hooks/kiva/use-parameter-persistence.ts +191 -0
@@ -0,0 +1,222 @@
1
+ // @ts-nocheck
2
+ /* eslint-disable */
3
+ import {
4
+ useCallback,
5
+ useEffect,
6
+ useMemo,
7
+ useRef,
8
+ useState
9
+ } from 'react';
10
+
11
+ import {
12
+ bucketKeyForDate,
13
+ buildLocalCellMap,
14
+ buildRemoteCellMap,
15
+ navigateDate,
16
+ rangeLabelForView,
17
+ toDate
18
+ } from '../helpers';
19
+
20
+ import {
21
+ type IPivotCalendarCellClick,
22
+ type IPivotCalendarController,
23
+ type IPivotCalendarGroup,
24
+ type IPivotCalendarMeasureValue,
25
+ type PivotCalendarProps,
26
+ type TPivotCalendarView
27
+ } from '../types';
28
+
29
+ const DEFAULT_VIEW: TPivotCalendarView = 'month-calendar';
30
+
31
+ export function usePivotCalendarController<TData>(
32
+ props: PivotCalendarProps<TData>
33
+ ): IPivotCalendarController<TData> {
34
+ const {
35
+ mode = 'local',
36
+ data,
37
+ cells,
38
+ getDate,
39
+ groupBy,
40
+ groups: providedGroups,
41
+ measures,
42
+ defaultView = DEFAULT_VIEW,
43
+ view: controlledView,
44
+ onViewChange,
45
+ defaultDate,
46
+ date: controlledDate,
47
+ onDateChange,
48
+ defaultSelectedGroupIds,
49
+ selectedGroupIds: controlledSelectedGroupIds,
50
+ onSelectedGroupIdsChange,
51
+ hideSidebar = false,
52
+ onCellClick
53
+ } = props;
54
+
55
+ const [internalView, setInternalView] = useState<TPivotCalendarView>(defaultView);
56
+ const view = controlledView ?? internalView;
57
+
58
+ const setView = useCallback((next: TPivotCalendarView) => {
59
+ if (controlledView === undefined) setInternalView(next);
60
+ onViewChange?.(next);
61
+ }, [controlledView, onViewChange]);
62
+
63
+ const [internalDate, setInternalDate] = useState<Date>(() => defaultDate ?? new Date());
64
+ const selectedDate = controlledDate ?? internalDate;
65
+
66
+ const setSelectedDate = useCallback((next: Date) => {
67
+ if (controlledDate === undefined) setInternalDate(next);
68
+ onDateChange?.(next);
69
+ }, [controlledDate, onDateChange]);
70
+
71
+ const inferredGroups = useMemo<Array<IPivotCalendarGroup>>(() => {
72
+ if (providedGroups && providedGroups.length > 0) return providedGroups;
73
+ if (mode !== 'local' || !groupBy || !data) return [];
74
+
75
+ const seen = new Map<string, IPivotCalendarGroup>();
76
+
77
+ for (const row of data) {
78
+ const id = groupBy.getId(row);
79
+
80
+ if (id == null || id === '') continue;
81
+ if (seen.has(id)) continue;
82
+
83
+ const supplied = groupBy.getGroup?.(row);
84
+ const fallback: IPivotCalendarGroup = supplied ?? { id, label: id };
85
+
86
+ seen.set(id, fallback);
87
+ }
88
+
89
+ return Array.from(seen.values()).sort((a, b) => a.label.localeCompare(b.label));
90
+ }, [
91
+ providedGroups,
92
+ mode,
93
+ data,
94
+ groupBy
95
+ ]);
96
+
97
+ const [internalSelectedGroupIds, setInternalSelectedGroupIds] = useState<Array<string>>(
98
+ () => defaultSelectedGroupIds ?? inferredGroups.map(g => g.id)
99
+ );
100
+ const lastInferredKeyRef = useRef<string>('');
101
+
102
+ useEffect(() => {
103
+ if (controlledSelectedGroupIds !== undefined) return;
104
+ if (defaultSelectedGroupIds !== undefined) return;
105
+ const key = inferredGroups.map(g => g.id).join('|');
106
+
107
+ if (key === lastInferredKeyRef.current) return;
108
+ lastInferredKeyRef.current = key;
109
+ const nextIds = inferredGroups.map(g => g.id);
110
+
111
+ queueMicrotask(() => setInternalSelectedGroupIds(nextIds));
112
+ }, [inferredGroups, controlledSelectedGroupIds, defaultSelectedGroupIds]);
113
+
114
+ const selectedGroupIds = controlledSelectedGroupIds ?? internalSelectedGroupIds;
115
+
116
+ const setSelectedGroupIds = useCallback((next: Array<string>) => {
117
+ if (controlledSelectedGroupIds === undefined) setInternalSelectedGroupIds(next);
118
+ onSelectedGroupIdsChange?.(next);
119
+ }, [controlledSelectedGroupIds, onSelectedGroupIdsChange]);
120
+
121
+ const cellMap = useMemo<Map<string, Array<IPivotCalendarMeasureValue>>>(() => {
122
+ if (mode === 'remote') {
123
+ return buildRemoteCellMap(cells ?? []);
124
+ }
125
+
126
+ if (!data || !getDate) return new Map();
127
+
128
+ return buildLocalCellMap({
129
+ data,
130
+ getDate: row => toDate(getDate(row)),
131
+ view,
132
+ measures,
133
+ groupBy
134
+ });
135
+ }, [
136
+ mode,
137
+ cells,
138
+ data,
139
+ getDate,
140
+ view,
141
+ measures,
142
+ groupBy
143
+ ]);
144
+
145
+ const getCellValues = useCallback(
146
+ (bucket: string, groupId?: string | null): Array<IPivotCalendarMeasureValue> => {
147
+ const key = `${bucket}::${groupId ?? ''}`;
148
+
149
+ return cellMap.get(key) ?? [];
150
+ },
151
+ [cellMap]
152
+ );
153
+
154
+ const formatValue = useCallback((measureId: string, value: number): string => {
155
+ const measure = measures.find(m => m.id === measureId);
156
+
157
+ if (measure?.formatValue) return measure.formatValue(value);
158
+
159
+ return String(Math.round(value * 100) / 100);
160
+ }, [measures]);
161
+
162
+ const navigatePrevious = useCallback(() => {
163
+ setSelectedDate(navigateDate(selectedDate, view, 'previous'));
164
+ }, [selectedDate, view, setSelectedDate]);
165
+
166
+ const navigateNext = useCallback(() => {
167
+ setSelectedDate(navigateDate(selectedDate, view, 'next'));
168
+ }, [selectedDate, view, setSelectedDate]);
169
+
170
+ const navigateToday = useCallback(() => {
171
+ setSelectedDate(new Date());
172
+ }, [setSelectedDate]);
173
+
174
+ const rangeLabel = useMemo(
175
+ () => rangeLabelForView(selectedDate, view),
176
+ [selectedDate, view]
177
+ );
178
+
179
+ const [internalSidebarHidden, setInternalSidebarHidden] = useState(hideSidebar);
180
+
181
+ useEffect(() => {
182
+ queueMicrotask(() => setInternalSidebarHidden(hideSidebar));
183
+ }, [hideSidebar]);
184
+
185
+ const toggleSidebar = useCallback(() => {
186
+ setInternalSidebarHidden(prev => !prev);
187
+ }, []);
188
+
189
+ const onCellClickRef = useRef(onCellClick);
190
+
191
+ useEffect(() => {
192
+ onCellClickRef.current = onCellClick;
193
+ }, [onCellClick]);
194
+
195
+ const emitCellClick = useCallback((info: IPivotCalendarCellClick<TData>) => {
196
+ onCellClickRef.current?.(info);
197
+ }, []);
198
+
199
+ return {
200
+ view,
201
+ setView,
202
+ selectedDate,
203
+ setSelectedDate,
204
+ measures,
205
+ groupBy,
206
+ groups: inferredGroups,
207
+ selectedGroupIds,
208
+ setSelectedGroupIds,
209
+ getCellValues,
210
+ formatValue,
211
+ navigatePrevious,
212
+ navigateNext,
213
+ navigateToday,
214
+ rangeLabel,
215
+ hideSidebar: internalSidebarHidden,
216
+ toggleSidebar,
217
+ emitCellClick,
218
+ hasCellClickHandler: Boolean(onCellClick)
219
+ };
220
+ }
221
+
222
+ export { bucketKeyForDate };
@@ -0,0 +1,32 @@
1
+ 'use client';
2
+
3
+ // @ts-nocheck
4
+ /* eslint-disable */
5
+ export { PivotCalendar } from './pivot-calendar';
6
+ export type { PivotCalendarRootProps } from './pivot-calendar';
7
+ export type {
8
+ IPivotCalendarCellClick,
9
+ IPivotCalendarController,
10
+ IPivotCalendarGroup,
11
+ IPivotCalendarGroupBy,
12
+ IPivotCalendarMeasure,
13
+ IPivotCalendarMeasureValue,
14
+ IPivotCalendarRemoteCell,
15
+ PivotCalendarProps,
16
+ TPivotCalendarAggregate,
17
+ TPivotCalendarBucketKind,
18
+ TPivotCalendarMode,
19
+ TPivotCalendarView
20
+ } from './types';
21
+
22
+ export { pivotCalendarVariants } from './pivot-calendar';
23
+ export { usePivotCalendarController } from './hooks/use-pivot-calendar';
24
+ export {
25
+ bucketKeyForDate,
26
+ buildLocalCellMap,
27
+ buildRemoteCellMap,
28
+ getRangeForBucket,
29
+ getRangeForView,
30
+ navigateDate,
31
+ rangeLabelForView
32
+ } from './helpers';
@@ -0,0 +1,107 @@
1
+ 'use client';
2
+
3
+ // @ts-nocheck
4
+ /* eslint-disable */
5
+ import { type VariantProps, cva } from 'class-variance-authority';
6
+
7
+ import { TooltipProvider } from '@kivacore/ui-pro-shared/components/tooltip';
8
+ import { cn } from '@kivacore/ui-pro-shared/lib/utils';
9
+
10
+ import { GroupSidebar } from './components/group-sidebar';
11
+ import { PivotCalendarToolbar } from './components/pivot-calendar-toolbar';
12
+
13
+ import { usePivotCalendarController } from './hooks/use-pivot-calendar';
14
+
15
+ import { type PivotCalendarProps, type TPivotCalendarView } from './types';
16
+
17
+ import { DaysOfMonthView } from './views/days-of-month-view';
18
+ import { DaysOfWeekView } from './views/days-of-week-view';
19
+ import { MonthCalendarView } from './views/month-calendar-view';
20
+ import { MonthsOfYearView } from './views/months-of-year-view';
21
+
22
+ const ALL_VIEWS: Array<TPivotCalendarView> = [
23
+ 'month-calendar',
24
+ 'days-of-week',
25
+ 'days-of-month',
26
+ 'months-of-year'
27
+ ];
28
+
29
+ export interface PivotCalendarRootProps<TData = Record<string, unknown>>
30
+ extends PivotCalendarProps<TData>,
31
+ VariantProps<typeof pivotCalendarVariants> {}
32
+
33
+ function PivotCalendar<TData = Record<string, unknown>>(props: PivotCalendarRootProps<TData>) {
34
+ const {
35
+ className, size, hideViewSwitcher, visibleViews, title, hideSidebar
36
+ } = props;
37
+
38
+ const controller = usePivotCalendarController(props);
39
+
40
+ const views = visibleViews ?? ALL_VIEWS;
41
+ const showSidebar
42
+ = !hideSidebar
43
+ && !controller.hideSidebar
44
+ && Boolean(controller.groupBy)
45
+ && controller.view === 'month-calendar';
46
+
47
+ const renderView = () => {
48
+ switch (controller.view) {
49
+ case 'month-calendar':
50
+ return <MonthCalendarView controller={controller} />;
51
+
52
+ case 'days-of-week':
53
+ return <DaysOfWeekView controller={controller} />;
54
+
55
+ case 'days-of-month':
56
+ return <DaysOfMonthView controller={controller} />;
57
+
58
+ case 'months-of-year':
59
+ return <MonthsOfYearView controller={controller} />;
60
+
61
+ default:
62
+ return null;
63
+ }
64
+ };
65
+
66
+ return (
67
+ <TooltipProvider delayDuration={100}>
68
+ <div className={cn(pivotCalendarVariants({ size }), className)}>
69
+ <PivotCalendarToolbar
70
+ controller={controller}
71
+ visibleViews={views}
72
+ hideViewSwitcher={hideViewSwitcher}
73
+ title={title} />
74
+ <div className="flex min-h-0 flex-1 overflow-hidden">
75
+ {showSidebar ? (
76
+ <GroupSidebar
77
+ label={controller.groupBy?.label ?? 'Groups'}
78
+ groups={controller.groups}
79
+ selected={controller.selectedGroupIds}
80
+ onChange={controller.setSelectedGroupIds} />
81
+ ) : null}
82
+ <div className="flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden">
83
+ {renderView()}
84
+ </div>
85
+ </div>
86
+ </div>
87
+ </TooltipProvider>
88
+ );
89
+ }
90
+
91
+ export { PivotCalendar };
92
+
93
+ export const pivotCalendarVariants = cva(
94
+ 'flex w-full flex-col overflow-hidden rounded-lg border bg-card text-card-foreground',
95
+ {
96
+ variants: {
97
+ size: {
98
+ default: 'min-h-[600px]',
99
+ sm: 'min-h-[480px]',
100
+ lg: 'min-h-[720px]'
101
+ }
102
+ },
103
+ defaultVariants: {
104
+ size: 'default'
105
+ }
106
+ }
107
+ );
@@ -0,0 +1,154 @@
1
+ // @ts-nocheck
2
+ /* eslint-disable */
3
+ import { type ReactNode } from 'react';
4
+
5
+ export type TPivotCalendarView
6
+ = | 'month-calendar'
7
+ | 'days-of-week'
8
+ | 'days-of-month'
9
+ | 'months-of-year';
10
+
11
+ export type TPivotCalendarMode = 'local' | 'remote';
12
+
13
+ export type TPivotCalendarAggregate = 'sum' | 'count' | 'avg' | 'min' | 'max';
14
+
15
+ export interface IPivotCalendarMeasure<TData = Record<string, unknown>> {
16
+ id: string;
17
+ label: string;
18
+ shortLabel?: string;
19
+ aggregate: TPivotCalendarAggregate;
20
+ getValue?: (row: TData) => number | null | undefined;
21
+ formatValue?: (value: number) => string;
22
+ color?: string;
23
+ description?: string;
24
+ }
25
+
26
+ export interface IPivotCalendarGroup {
27
+ id: string;
28
+ label: string;
29
+ color?: string | null;
30
+ icon?: string | null;
31
+ image?: { signed_url?: string | null; file_name?: string } | null;
32
+ description?: string;
33
+ }
34
+
35
+ export interface IPivotCalendarGroupBy<TData = Record<string, unknown>> {
36
+ id: string;
37
+ label: string;
38
+ getId: (row: TData) => string | null | undefined;
39
+ getGroup?: (row: TData) => IPivotCalendarGroup | null | undefined;
40
+ }
41
+
42
+ export type TPivotCalendarBucketKind
43
+ = | 'day'
44
+ | 'weekday'
45
+ | 'month';
46
+
47
+ export interface IPivotCalendarMeasureValue {
48
+ measureId: string;
49
+ value: number;
50
+ }
51
+
52
+ export interface IPivotCalendarCellClick<TData = Record<string, unknown>> {
53
+ /** Bucket key from the active view (yyyy-MM-dd or yyyy-MM). */
54
+ bucket: string;
55
+ /** Inclusive start of the bucket's date range (local time). */
56
+ bucketStart: Date;
57
+ /** Inclusive end of the bucket's date range (local time, end-of-day or end-of-month). */
58
+ bucketEnd: Date;
59
+ /** Active view at the time of click. */
60
+ view: TPivotCalendarView;
61
+ /** Group id when groupBy is configured. Null for ungrouped totals or "Totals" row. */
62
+ groupId: string | null;
63
+ /** Group entry when available (sidebar/row axis). */
64
+ group?: IPivotCalendarGroup;
65
+ /** Measure descriptor that was clicked. */
66
+ measure: IPivotCalendarMeasure<TData>;
67
+ /** Raw aggregated value before formatting. */
68
+ value: number;
69
+ /** Formatted display value. */
70
+ formattedValue: string;
71
+ }
72
+
73
+ export interface IPivotCalendarRemoteCell {
74
+ /** Bucket key — for day: 'YYYY-MM-DD', weekday: '0'..'6' (0=Sunday), month: '0'..'11' */
75
+ bucket: string;
76
+ /** Group id when groupBy is configured. Omit for ungrouped totals. */
77
+ groupId?: string | null;
78
+ values: Array<IPivotCalendarMeasureValue>;
79
+ }
80
+
81
+ export interface IPivotCalendarController<TData = Record<string, unknown>> {
82
+ view: TPivotCalendarView;
83
+ setView: (view: TPivotCalendarView) => void;
84
+ selectedDate: Date;
85
+ setSelectedDate: (date: Date) => void;
86
+ measures: Array<IPivotCalendarMeasure<TData>>;
87
+ groupBy?: IPivotCalendarGroupBy<TData>;
88
+ groups: Array<IPivotCalendarGroup>;
89
+ selectedGroupIds: Array<string>;
90
+ setSelectedGroupIds: (ids: Array<string>) => void;
91
+ /** Returns aggregated values for a given bucket+group combination */
92
+ getCellValues: (bucket: string, groupId?: string | null) => Array<IPivotCalendarMeasureValue>;
93
+ /** Returns formatted display string for a measure value */
94
+ formatValue: (measureId: string, value: number) => string;
95
+ navigatePrevious: () => void;
96
+ navigateNext: () => void;
97
+ navigateToday: () => void;
98
+ rangeLabel: string;
99
+ hideSidebar: boolean;
100
+ toggleSidebar: () => void;
101
+ /** Notifies parent of a stat tile click. Views call this when the user clicks a measure value. */
102
+ emitCellClick: (info: IPivotCalendarCellClick<TData>) => void;
103
+ /** True when an `onCellClick` handler has been provided — views use it to enable interactive styles. */
104
+ hasCellClickHandler: boolean;
105
+ }
106
+
107
+ export interface PivotCalendarProps<TData = Record<string, unknown>> {
108
+ /** Calculation mode. 'local' aggregates raw data; 'remote' uses pre-aggregated cells. */
109
+ mode?: TPivotCalendarMode;
110
+ /** Raw data rows. Required when mode='local'. */
111
+ data?: Array<TData>;
112
+ /** Pre-aggregated cells. Required when mode='remote'. */
113
+ cells?: Array<IPivotCalendarRemoteCell>;
114
+ /** Reads the date for a row (returns Date or ISO string). Required when mode='local'. */
115
+ getDate?: (row: TData) => Date | string;
116
+ /** Optional grouping category dimension. When set, the month view shows a side panel of groups. */
117
+ groupBy?: IPivotCalendarGroupBy<TData>;
118
+ /** Group catalog used for the side filter and as the row axis on grid views. Required when mode='remote' with groupBy. */
119
+ groups?: Array<IPivotCalendarGroup>;
120
+ /** Measures to display. Up to 4 measures are shown in calendar day cells. */
121
+ measures: Array<IPivotCalendarMeasure<TData>>;
122
+ /** Initial view. Defaults to 'month-calendar'. */
123
+ defaultView?: TPivotCalendarView;
124
+ /** Controlled view value. */
125
+ view?: TPivotCalendarView;
126
+ /** Called when view changes (uncontrolled or controlled). */
127
+ onViewChange?: (view: TPivotCalendarView) => void;
128
+ /** Initial reference date. Defaults to today. */
129
+ defaultDate?: Date;
130
+ /** Controlled reference date. */
131
+ date?: Date;
132
+ /** Called when reference date changes. */
133
+ onDateChange?: (date: Date) => void;
134
+ /** Initial selected groups for filtering. Defaults to all. */
135
+ defaultSelectedGroupIds?: Array<string>;
136
+ /** Controlled selected groups. */
137
+ selectedGroupIds?: Array<string>;
138
+ /** Called when group selection changes. */
139
+ onSelectedGroupIdsChange?: (ids: Array<string>) => void;
140
+ /** Hide the view switcher tabs. */
141
+ hideViewSwitcher?: boolean;
142
+ /** Hide the side panel of groups (only relevant for the calendar month view). */
143
+ hideSidebar?: boolean;
144
+ /** Which views to expose in the switcher. */
145
+ visibleViews?: Array<TPivotCalendarView>;
146
+ /** Custom title. Defaults to the rangeLabel of the active view. */
147
+ title?: ReactNode;
148
+ /**
149
+ * Fires when the user clicks a measure value (a stat tile or grid value
150
+ * cell). Use it to open a drilldown dialog with the matching records.
151
+ */
152
+ onCellClick?: (info: IPivotCalendarCellClick<TData>) => void;
153
+ className?: string;
154
+ }
@@ -0,0 +1,37 @@
1
+ 'use client';
2
+
3
+ // @ts-nocheck
4
+ /* eslint-disable */
5
+ import { useMemo } from 'react';
6
+
7
+ import { format, isSameDay } from 'date-fns';
8
+
9
+ import { getDaysOfMonth } from '../helpers';
10
+
11
+ import { type IPivotCalendarController } from '../types';
12
+
13
+ import { PivotGridView, type PivotColumn } from './pivot-grid-view';
14
+
15
+ export function DaysOfMonthView<TData>({ controller }: { controller: IPivotCalendarController<TData> }) {
16
+ const { selectedDate } = controller;
17
+
18
+ const columns = useMemo<Array<PivotColumn>>(() => {
19
+ const today = new Date();
20
+ const days = getDaysOfMonth(selectedDate);
21
+
22
+ return days.map(day => ({
23
+ id: day.toISOString(),
24
+ bucket: format(day, 'yyyy-MM-dd'),
25
+ primaryLabel: format(day, 'EEE'),
26
+ secondaryLabel: format(day, 'd'),
27
+ isHighlighted: isSameDay(day, today)
28
+ }));
29
+ }, [selectedDate]);
30
+
31
+ return (
32
+ <PivotGridView
33
+ controller={controller}
34
+ columns={columns}
35
+ leafMinWidth={70} />
36
+ );
37
+ }
@@ -0,0 +1,37 @@
1
+ 'use client';
2
+
3
+ // @ts-nocheck
4
+ /* eslint-disable */
5
+ import { useMemo } from 'react';
6
+
7
+ import { format, isSameDay } from 'date-fns';
8
+
9
+ import { getDaysOfWeek } from '../helpers';
10
+
11
+ import { type IPivotCalendarController } from '../types';
12
+
13
+ import { PivotGridView, type PivotColumn } from './pivot-grid-view';
14
+
15
+ export function DaysOfWeekView<TData>({ controller }: { controller: IPivotCalendarController<TData> }) {
16
+ const { selectedDate } = controller;
17
+
18
+ const columns = useMemo<Array<PivotColumn>>(() => {
19
+ const today = new Date();
20
+ const days = getDaysOfWeek(selectedDate);
21
+
22
+ return days.map(day => ({
23
+ id: day.toISOString(),
24
+ bucket: format(day, 'yyyy-MM-dd'),
25
+ primaryLabel: format(day, 'EEE'),
26
+ secondaryLabel: format(day, 'MMM d'),
27
+ isHighlighted: isSameDay(day, today)
28
+ }));
29
+ }, [selectedDate]);
30
+
31
+ return (
32
+ <PivotGridView
33
+ controller={controller}
34
+ columns={columns}
35
+ leafMinWidth={80} />
36
+ );
37
+ }