@kivacore/ui-pro-shared 0.0.9 → 0.0.10
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 +187 -21
- 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,218 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import { useCallback, useMemo, type CSSProperties } from 'react';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
getDay, isSameMonth, isToday, startOfDay
|
|
9
|
+
} from 'date-fns';
|
|
10
|
+
import { motion } from 'motion/react';
|
|
11
|
+
|
|
12
|
+
import { Plus } from 'lucide-react';
|
|
13
|
+
|
|
14
|
+
import { cn } from '@kivacore/ui-pro-shared/lib/utils';
|
|
15
|
+
|
|
16
|
+
import { useUiTranslation } from '@kivacore/ui-pro-shared/hooks/kiva/use-ui-translation';
|
|
17
|
+
|
|
18
|
+
import { Button } from '@kivacore/ui-pro-shared/components/button';
|
|
19
|
+
|
|
20
|
+
import { type ICalendarCell, type IEvent } from '../../interfaces';
|
|
21
|
+
|
|
22
|
+
import { transition } from '../../animations';
|
|
23
|
+
import { EventListDialog } from '../../dialogs/events-list-dialog';
|
|
24
|
+
import { DroppableArea } from '../../dnd/droppable-area';
|
|
25
|
+
import { getMonthCellEvents } from '../../helpers';
|
|
26
|
+
import { useMediaQuery } from '../../hooks';
|
|
27
|
+
import { EventBullet } from './event-bullet';
|
|
28
|
+
import { MonthEventBadge } from './month-event-badge';
|
|
29
|
+
|
|
30
|
+
import { useCalendar } from '../../contexts/calendar-context';
|
|
31
|
+
import { AddEditEventDialog } from '../../dialogs/add-edit-event-dialog';
|
|
32
|
+
|
|
33
|
+
interface IProps {
|
|
34
|
+
cell: ICalendarCell;
|
|
35
|
+
events: Array<IEvent>;
|
|
36
|
+
eventPositions: Record<string, number>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const MAX_VISIBLE_EVENTS = 3;
|
|
40
|
+
|
|
41
|
+
export function DayCell({ cell, events, eventPositions }: IProps) {
|
|
42
|
+
const { t } = useUiTranslation();
|
|
43
|
+
const {
|
|
44
|
+
hideAddButton, hideCellAddButton, onDaySelect, weekStartsOn,
|
|
45
|
+
cellMinHeight, cellMinWidth
|
|
46
|
+
} = useCalendar();
|
|
47
|
+
const { day, currentMonth, date } = cell;
|
|
48
|
+
const isMobile = useMediaQuery('(max-width: 768px)');
|
|
49
|
+
const shouldHideCellAdd = hideCellAddButton ?? hideAddButton;
|
|
50
|
+
const isFirstColumn = getDay(date) === weekStartsOn;
|
|
51
|
+
|
|
52
|
+
const cellStyle = useMemo<CSSProperties | undefined>(() => {
|
|
53
|
+
if (cellMinHeight == null && cellMinWidth == null) return undefined;
|
|
54
|
+
const style: CSSProperties = {};
|
|
55
|
+
|
|
56
|
+
if (cellMinHeight != null) {
|
|
57
|
+
style.minHeight = typeof cellMinHeight === 'number' ? `${cellMinHeight}px` : cellMinHeight;
|
|
58
|
+
}
|
|
59
|
+
if (cellMinWidth != null) {
|
|
60
|
+
style.minWidth = typeof cellMinWidth === 'number' ? `${cellMinWidth}px` : cellMinWidth;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return style;
|
|
64
|
+
}, [cellMinHeight, cellMinWidth]);
|
|
65
|
+
|
|
66
|
+
const { cellEvents, currentCellMonth } = useMemo(() => {
|
|
67
|
+
const evts = getMonthCellEvents(date, events, eventPositions);
|
|
68
|
+
const cellMonth = startOfDay(
|
|
69
|
+
new Date(date.getFullYear(), date.getMonth(), 1)
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
return { cellEvents: evts, currentCellMonth: cellMonth };
|
|
73
|
+
}, [date, events, eventPositions]);
|
|
74
|
+
|
|
75
|
+
const renderEventAtPosition = useCallback(
|
|
76
|
+
(position: number) => {
|
|
77
|
+
const event = cellEvents.find(e => e.position === position);
|
|
78
|
+
|
|
79
|
+
if (!event) {
|
|
80
|
+
return (
|
|
81
|
+
<motion.div
|
|
82
|
+
key={`empty-${position}`}
|
|
83
|
+
className="lg:flex-1"
|
|
84
|
+
initial={false}
|
|
85
|
+
animate={false} />
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
const showBullet = isSameMonth(
|
|
89
|
+
new Date(event.startDate),
|
|
90
|
+
currentCellMonth
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<motion.div
|
|
95
|
+
key={`event-${event.id}-${position}`}
|
|
96
|
+
className="lg:flex-1"
|
|
97
|
+
initial={{ opacity: 0, x: -10 }}
|
|
98
|
+
animate={{ opacity: 1, x: 0 }}
|
|
99
|
+
transition={{ delay: position * 0.1, ...transition }}>
|
|
100
|
+
{showBullet && (
|
|
101
|
+
<EventBullet className="lg:hidden" color={event.color} />
|
|
102
|
+
)}
|
|
103
|
+
<MonthEventBadge
|
|
104
|
+
className="hidden lg:flex"
|
|
105
|
+
event={event}
|
|
106
|
+
cellDate={startOfDay(date)} />
|
|
107
|
+
</motion.div>
|
|
108
|
+
);
|
|
109
|
+
},
|
|
110
|
+
[cellEvents, currentCellMonth, date]
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
const showMoreCount = cellEvents.length - MAX_VISIBLE_EVENTS;
|
|
114
|
+
|
|
115
|
+
const showMobileMore = isMobile && currentMonth && showMoreCount > 0;
|
|
116
|
+
const showDesktopMore = !isMobile && currentMonth && showMoreCount > 0;
|
|
117
|
+
|
|
118
|
+
const handleDayClick = useCallback(() => {
|
|
119
|
+
onDaySelect?.(date);
|
|
120
|
+
}, [date, onDaySelect]);
|
|
121
|
+
|
|
122
|
+
const cellContent = useMemo(
|
|
123
|
+
() => (
|
|
124
|
+
<motion.div
|
|
125
|
+
className={cn(
|
|
126
|
+
'flex h-full lg:min-h-40 flex-col gap-1 border-l border-t cursor-pointer',
|
|
127
|
+
isFirstColumn && 'border-l-0'
|
|
128
|
+
)}
|
|
129
|
+
style={cellStyle}
|
|
130
|
+
initial={{ opacity: 0, y: 10 }}
|
|
131
|
+
animate={{ opacity: 1, y: 0 }}
|
|
132
|
+
transition={transition}
|
|
133
|
+
onClick={handleDayClick}>
|
|
134
|
+
<DroppableArea date={date} className="size-full py-2">
|
|
135
|
+
<motion.span
|
|
136
|
+
/*
|
|
137
|
+
* Every day number sits in the same 24px box, so the today pill is
|
|
138
|
+
* a background on that box instead of a `translate-x` nudge — the
|
|
139
|
+
* old version left today's number a few pixels out of the column.
|
|
140
|
+
*/
|
|
141
|
+
className={cn(
|
|
142
|
+
'ml-1 flex size-6 items-center justify-center text-xs font-semibold lg:ml-1.5',
|
|
143
|
+
!currentMonth && 'opacity-20',
|
|
144
|
+
isToday(date) && 'rounded-full bg-primary font-bold text-primary-foreground'
|
|
145
|
+
)}>
|
|
146
|
+
{day}
|
|
147
|
+
</motion.span>
|
|
148
|
+
|
|
149
|
+
<motion.div
|
|
150
|
+
className={cn(
|
|
151
|
+
'relative flex h-fit gap-1 px-2 mt-1 lg:flex-col lg:gap-2 lg:px-0 lg:flex-1 lg:min-h-0',
|
|
152
|
+
!currentMonth && 'opacity-50'
|
|
153
|
+
)}>
|
|
154
|
+
{cellEvents.length === 0 && !isMobile && !shouldHideCellAdd ? (
|
|
155
|
+
<div className="pointer-events-none absolute inset-0 flex justify-center items-center group">
|
|
156
|
+
<AddEditEventDialog startDate={date}>
|
|
157
|
+
<Button
|
|
158
|
+
variant="ghost"
|
|
159
|
+
size="xs"
|
|
160
|
+
className="pointer-events-auto border opacity-0 group-hover:opacity-100 transition-opacity duration-200">
|
|
161
|
+
<Plus className="size-3" />
|
|
162
|
+
<span className="max-sm:hidden">{t('ui.calendar.addEvent', 'Add Event')}</span>
|
|
163
|
+
</Button>
|
|
164
|
+
</AddEditEventDialog>
|
|
165
|
+
</div>
|
|
166
|
+
) : (
|
|
167
|
+
[0, 1, 2].map(renderEventAtPosition)
|
|
168
|
+
)}
|
|
169
|
+
</motion.div>
|
|
170
|
+
|
|
171
|
+
{showMobileMore && (
|
|
172
|
+
<div className="flex justify-end items-end mx-2">
|
|
173
|
+
<span className="text-[0.6rem] font-semibold text-accent-foreground">
|
|
174
|
+
+{showMoreCount}
|
|
175
|
+
</span>
|
|
176
|
+
</div>
|
|
177
|
+
)}
|
|
178
|
+
|
|
179
|
+
{showDesktopMore && (
|
|
180
|
+
<motion.div
|
|
181
|
+
className="h-4.5 px-1.5 my-2 text-end text-xs font-semibold text-muted-foreground"
|
|
182
|
+
initial={{ opacity: 0, y: 5 }}
|
|
183
|
+
animate={{ opacity: 1, y: 0 }}
|
|
184
|
+
transition={{ delay: 0.3, ...transition }}>
|
|
185
|
+
<EventListDialog date={date} events={cellEvents} />
|
|
186
|
+
</motion.div>
|
|
187
|
+
)}
|
|
188
|
+
</DroppableArea>
|
|
189
|
+
</motion.div>
|
|
190
|
+
),
|
|
191
|
+
[
|
|
192
|
+
date,
|
|
193
|
+
day,
|
|
194
|
+
currentMonth,
|
|
195
|
+
cellEvents,
|
|
196
|
+
showMobileMore,
|
|
197
|
+
showDesktopMore,
|
|
198
|
+
showMoreCount,
|
|
199
|
+
renderEventAtPosition,
|
|
200
|
+
isMobile,
|
|
201
|
+
t,
|
|
202
|
+
handleDayClick,
|
|
203
|
+
shouldHideCellAdd,
|
|
204
|
+
isFirstColumn,
|
|
205
|
+
cellStyle
|
|
206
|
+
]
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
if (isMobile && currentMonth) {
|
|
210
|
+
return (
|
|
211
|
+
<EventListDialog date={date} events={cellEvents}>
|
|
212
|
+
{cellContent}
|
|
213
|
+
</EventListDialog>
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return cellContent;
|
|
218
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import { cva } from 'class-variance-authority';
|
|
6
|
+
import { motion } from 'motion/react';
|
|
7
|
+
|
|
8
|
+
import { cn } from '@kivacore/ui-pro-shared/lib/utils';
|
|
9
|
+
|
|
10
|
+
import { type TEventColor } from '../../types';
|
|
11
|
+
|
|
12
|
+
import { transition } from '../../animations';
|
|
13
|
+
|
|
14
|
+
const eventBulletVariants = cva('size-2 rounded-full', {
|
|
15
|
+
variants: {
|
|
16
|
+
color: {
|
|
17
|
+
blue: 'bg-blue-600 dark:bg-blue-500',
|
|
18
|
+
green: 'bg-green-600 dark:bg-green-500',
|
|
19
|
+
red: 'bg-red-600 dark:bg-red-500',
|
|
20
|
+
yellow: 'bg-yellow-600 dark:bg-yellow-500',
|
|
21
|
+
purple: 'bg-purple-600 dark:bg-purple-500',
|
|
22
|
+
orange: 'bg-orange-600 dark:bg-orange-500',
|
|
23
|
+
gray: 'bg-gray-600 dark:bg-gray-500'
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
defaultVariants: {
|
|
27
|
+
color: 'blue'
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export function EventBullet({
|
|
32
|
+
color,
|
|
33
|
+
className
|
|
34
|
+
}: {
|
|
35
|
+
color: TEventColor;
|
|
36
|
+
className?: string;
|
|
37
|
+
}) {
|
|
38
|
+
return (
|
|
39
|
+
<motion.div
|
|
40
|
+
className={cn(eventBulletVariants({ color, className }))}
|
|
41
|
+
initial={{ scale: 0.95, opacity: 0 }}
|
|
42
|
+
animate={{ scale: 1, opacity: 1 }}
|
|
43
|
+
whileHover={{ scale: 1.2 }}
|
|
44
|
+
transition={transition} />
|
|
45
|
+
);
|
|
46
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import { type VariantProps, cva } from 'class-variance-authority';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
endOfDay, isSameDay, parseISO, startOfDay
|
|
9
|
+
} from 'date-fns';
|
|
10
|
+
|
|
11
|
+
import { cn } from '@kivacore/ui-pro-shared/lib/utils';
|
|
12
|
+
|
|
13
|
+
import { type IEvent } from '../../interfaces';
|
|
14
|
+
|
|
15
|
+
import { useCalendar } from '../../contexts/calendar-context';
|
|
16
|
+
import { EventDetailsDialog } from '../../dialogs/event-details-dialog';
|
|
17
|
+
import { DraggableEvent } from '../../dnd/draggable-event';
|
|
18
|
+
import { formatTime } from '../../helpers';
|
|
19
|
+
import { EventBullet } from './event-bullet';
|
|
20
|
+
|
|
21
|
+
const eventBadgeVariants = cva(
|
|
22
|
+
'flex w-full h-6.5 select-none items-center justify-between gap-1.5 truncate whitespace-nowrap rounded-md border px-2 text-xs cursor-grab',
|
|
23
|
+
{
|
|
24
|
+
variants: {
|
|
25
|
+
color: {
|
|
26
|
+
blue: 'border-blue-200 bg-blue-50 text-blue-700 dark:border-blue-800 dark:bg-blue-950 dark:text-blue-300',
|
|
27
|
+
green:
|
|
28
|
+
'border-green-200 bg-green-50 text-green-700 dark:border-green-800 dark:bg-green-950 dark:text-green-300',
|
|
29
|
+
red: 'border-red-200 bg-red-50 text-red-700 dark:border-red-800 dark:bg-red-950 dark:text-red-300',
|
|
30
|
+
yellow:
|
|
31
|
+
'border-yellow-200 bg-yellow-50 text-yellow-700 dark:border-yellow-800 dark:bg-yellow-950 dark:text-yellow-300',
|
|
32
|
+
purple:
|
|
33
|
+
'border-purple-200 bg-purple-50 text-purple-700 dark:border-purple-800 dark:bg-purple-950 dark:text-purple-300',
|
|
34
|
+
orange:
|
|
35
|
+
'border-orange-200 bg-orange-50 text-orange-700 dark:border-orange-800 dark:bg-orange-950 dark:text-orange-300',
|
|
36
|
+
|
|
37
|
+
'blue-dot': 'bg-secondary text-foreground [&_svg]:fill-blue-600',
|
|
38
|
+
'green-dot': 'bg-secondary text-foreground [&_svg]:fill-green-600',
|
|
39
|
+
'red-dot': 'bg-secondary text-foreground [&_svg]:fill-red-600',
|
|
40
|
+
'orange-dot': 'bg-secondary text-foreground [&_svg]:fill-orange-600',
|
|
41
|
+
'purple-dot': 'bg-secondary text-foreground [&_svg]:fill-purple-600',
|
|
42
|
+
'yellow-dot': 'bg-secondary text-foreground [&_svg]:fill-yellow-600'
|
|
43
|
+
},
|
|
44
|
+
multiDayPosition: {
|
|
45
|
+
first: 'relative z-10 mr-0 rounded-r-none border-r-0 [&>span]:mr-2.5',
|
|
46
|
+
middle:
|
|
47
|
+
'relative z-10 mx-0 w-[calc(100%_+_1px)] rounded-none border-x-0',
|
|
48
|
+
last: 'ml-0 rounded-l-none border-l-0',
|
|
49
|
+
none: ''
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
defaultVariants: {
|
|
53
|
+
color: 'blue-dot'
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
interface IProps extends Omit<
|
|
59
|
+
VariantProps<typeof eventBadgeVariants>,
|
|
60
|
+
'color' | 'multiDayPosition'
|
|
61
|
+
> {
|
|
62
|
+
event: IEvent;
|
|
63
|
+
cellDate: Date;
|
|
64
|
+
eventCurrentDay?: number;
|
|
65
|
+
eventTotalDays?: number;
|
|
66
|
+
className?: string;
|
|
67
|
+
position?: 'first' | 'middle' | 'last' | 'none';
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function MonthEventBadge({
|
|
71
|
+
event,
|
|
72
|
+
cellDate,
|
|
73
|
+
eventCurrentDay,
|
|
74
|
+
eventTotalDays,
|
|
75
|
+
className,
|
|
76
|
+
position: propPosition
|
|
77
|
+
}: IProps) {
|
|
78
|
+
const { badgeVariant, use24HourFormat, renderEventBadge } = useCalendar();
|
|
79
|
+
|
|
80
|
+
const itemStart = startOfDay(parseISO(event.startDate));
|
|
81
|
+
const itemEnd = endOfDay(parseISO(event.endDate));
|
|
82
|
+
|
|
83
|
+
if (cellDate < itemStart || cellDate > itemEnd) return null;
|
|
84
|
+
|
|
85
|
+
let position: 'first' | 'middle' | 'last' | 'none' = 'none';
|
|
86
|
+
|
|
87
|
+
if (propPosition) {
|
|
88
|
+
position = propPosition;
|
|
89
|
+
} else if (eventCurrentDay && eventTotalDays) {
|
|
90
|
+
position = 'none';
|
|
91
|
+
} else if (isSameDay(itemStart, itemEnd)) {
|
|
92
|
+
position = 'none';
|
|
93
|
+
} else if (isSameDay(cellDate, itemStart)) {
|
|
94
|
+
position = 'first';
|
|
95
|
+
} else if (isSameDay(cellDate, itemEnd)) {
|
|
96
|
+
position = 'last';
|
|
97
|
+
} else {
|
|
98
|
+
position = 'middle';
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const renderBadgeText = ['first', 'none'].includes(position);
|
|
102
|
+
const renderBadgeTime = ['last', 'none'].includes(position);
|
|
103
|
+
|
|
104
|
+
const color = (
|
|
105
|
+
badgeVariant === 'dot' ? `${event.color}-dot` : event.color
|
|
106
|
+
) as VariantProps<typeof eventBadgeVariants>['color'];
|
|
107
|
+
|
|
108
|
+
const eventBadgeClasses = cn(
|
|
109
|
+
eventBadgeVariants({ color, multiDayPosition: position, className })
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
const marginClass = {
|
|
113
|
+
first: 'ml-1 mr-0',
|
|
114
|
+
middle: 'mx-0',
|
|
115
|
+
last: 'ml-0 mr-1',
|
|
116
|
+
none: 'mx-1'
|
|
117
|
+
}[position];
|
|
118
|
+
|
|
119
|
+
const defaultBadge = (
|
|
120
|
+
<button type="button" className={eventBadgeClasses}>
|
|
121
|
+
<div className="flex items-center gap-1.5 truncate">
|
|
122
|
+
{!['middle', 'last'].includes(position)
|
|
123
|
+
&& badgeVariant === 'dot' && <EventBullet color={event.color} />}
|
|
124
|
+
|
|
125
|
+
{renderBadgeText && (
|
|
126
|
+
<p className="flex-1 truncate font-semibold">
|
|
127
|
+
{eventCurrentDay && (
|
|
128
|
+
<span className="text-xs">
|
|
129
|
+
Day {eventCurrentDay} of {eventTotalDays} •{' '}
|
|
130
|
+
</span>
|
|
131
|
+
)}
|
|
132
|
+
{event.title}
|
|
133
|
+
</p>
|
|
134
|
+
)}
|
|
135
|
+
</div>
|
|
136
|
+
|
|
137
|
+
<div className="hidden sm:block">
|
|
138
|
+
{renderBadgeTime && (
|
|
139
|
+
<span>
|
|
140
|
+
{formatTime(new Date(event.startDate), use24HourFormat)}
|
|
141
|
+
</span>
|
|
142
|
+
)}
|
|
143
|
+
</div>
|
|
144
|
+
</button>
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
return (
|
|
148
|
+
<DraggableEvent event={event} className={marginClass}>
|
|
149
|
+
<EventDetailsDialog event={event}>
|
|
150
|
+
{renderEventBadge ? renderEventBadge(event, defaultBadge) : defaultBadge}
|
|
151
|
+
</EventDetailsDialog>
|
|
152
|
+
</DraggableEvent>
|
|
153
|
+
);
|
|
154
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import { useCallback, useMemo, useState } from 'react';
|
|
6
|
+
|
|
7
|
+
import { startOfDay } from 'date-fns';
|
|
8
|
+
|
|
9
|
+
import { type TTimelineNavigationMode, type TTimelineView } from '../../types';
|
|
10
|
+
|
|
11
|
+
import { useCalendar } from '../../contexts/calendar-context';
|
|
12
|
+
|
|
13
|
+
import { eventsOverlapping } from './lib/timeline-layout';
|
|
14
|
+
import { TimelineSectionView } from './timeline-section';
|
|
15
|
+
import { useTimelineSections } from './use-timeline-sections';
|
|
16
|
+
|
|
17
|
+
const GUTTER_WIDTH = 132;
|
|
18
|
+
|
|
19
|
+
const MIN_BODY_WIDTH: Record<TTimelineView, number> = {
|
|
20
|
+
'year-timeline': 1040,
|
|
21
|
+
quarter: 1120,
|
|
22
|
+
'13weeks': 720
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
interface CalendarTimelineViewProps {
|
|
26
|
+
view: TTimelineView;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Shared shell for the three period-timeline views (Year / Quarter / 13 Weeks).
|
|
31
|
+
* The view id picks the period model; everything below is variant-driven.
|
|
32
|
+
*/
|
|
33
|
+
export function CalendarTimelineView({ view }: CalendarTimelineViewProps) {
|
|
34
|
+
const {
|
|
35
|
+
events,
|
|
36
|
+
selectedDate,
|
|
37
|
+
weekStartsOn,
|
|
38
|
+
timelineMaxLanes,
|
|
39
|
+
yearTimelineMode,
|
|
40
|
+
quarterMode,
|
|
41
|
+
reportTimelineRange
|
|
42
|
+
} = useCalendar();
|
|
43
|
+
|
|
44
|
+
const [expandedRows, setExpandedRows] = useState<Set<string>>(() => new Set());
|
|
45
|
+
const today = useMemo(() => startOfDay(new Date()), []);
|
|
46
|
+
|
|
47
|
+
let mode: TTimelineNavigationMode = 'single';
|
|
48
|
+
|
|
49
|
+
if (view === 'year-timeline') mode = yearTimelineMode;
|
|
50
|
+
if (view === 'quarter') mode = quarterMode;
|
|
51
|
+
|
|
52
|
+
const {
|
|
53
|
+
sections, containerRef, startSentinelRef, endSentinelRef, isContinuous
|
|
54
|
+
} = useTimelineSections({
|
|
55
|
+
view,
|
|
56
|
+
anchor: selectedDate,
|
|
57
|
+
mode,
|
|
58
|
+
weekStartsOn,
|
|
59
|
+
today,
|
|
60
|
+
onRangeChange: reportTimelineRange
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const sectionEvents = useMemo(
|
|
64
|
+
() => sections.map(section => eventsOverlapping(events, section.start, section.end)),
|
|
65
|
+
[sections, events]
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
const toggleRow = useCallback((rowKey: string) => {
|
|
69
|
+
setExpandedRows((prev) => {
|
|
70
|
+
const next = new Set(prev);
|
|
71
|
+
|
|
72
|
+
if (next.has(rowKey)) {
|
|
73
|
+
next.delete(rowKey);
|
|
74
|
+
} else {
|
|
75
|
+
next.add(rowKey);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return next;
|
|
79
|
+
});
|
|
80
|
+
}, []);
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<div ref={containerRef} className="w-full" style={{ minWidth: MIN_BODY_WIDTH[view] }}>
|
|
84
|
+
{isContinuous && <div ref={startSentinelRef} className="h-px" />}
|
|
85
|
+
|
|
86
|
+
{sections.map((section, index) => (
|
|
87
|
+
<TimelineSectionView
|
|
88
|
+
key={section.key}
|
|
89
|
+
section={section}
|
|
90
|
+
events={sectionEvents[index] ?? []}
|
|
91
|
+
maxLanes={timelineMaxLanes}
|
|
92
|
+
expandedRows={expandedRows}
|
|
93
|
+
onToggleRow={toggleRow}
|
|
94
|
+
gutterWidth={GUTTER_WIDTH} />
|
|
95
|
+
))}
|
|
96
|
+
|
|
97
|
+
{isContinuous && <div ref={endSentinelRef} className="h-px" />}
|
|
98
|
+
</div>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
import { isValid, parseISO } from 'date-fns';
|
|
4
|
+
|
|
5
|
+
import { type IEvent } from '../../../interfaces';
|
|
6
|
+
|
|
7
|
+
import { type TimelineRow, dateToFraction } from './timeline-model';
|
|
8
|
+
|
|
9
|
+
/** One event clipped to a single row, positioned as 0..1 fractions of its width. */
|
|
10
|
+
export interface TimelineSegment {
|
|
11
|
+
key: string;
|
|
12
|
+
event: IEvent;
|
|
13
|
+
left: number;
|
|
14
|
+
width: number;
|
|
15
|
+
start: Date;
|
|
16
|
+
end: Date;
|
|
17
|
+
/** The event started before this row — the bar is a continuation. */
|
|
18
|
+
continuesBefore: boolean;
|
|
19
|
+
/** The event runs past this row and repeats in the next one. */
|
|
20
|
+
continuesAfter: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface TimelineRowLayout {
|
|
24
|
+
/** Every lane, including the ones hidden while the row is collapsed. */
|
|
25
|
+
lanes: Array<Array<TimelineSegment>>;
|
|
26
|
+
/** Lanes currently rendered (all of them once the row is expanded). */
|
|
27
|
+
visibleLanes: Array<Array<TimelineSegment>>;
|
|
28
|
+
hiddenEvents: Array<IEvent>;
|
|
29
|
+
hiddenCount: number;
|
|
30
|
+
/** All events overlapping the row, in packing order. */
|
|
31
|
+
events: Array<IEvent>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface EventInterval {
|
|
35
|
+
event: IEvent;
|
|
36
|
+
start: Date;
|
|
37
|
+
end: Date;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function toInterval(event: IEvent): EventInterval | null {
|
|
41
|
+
const start = parseISO(event.startDate);
|
|
42
|
+
const end = parseISO(event.endDate);
|
|
43
|
+
|
|
44
|
+
if (!isValid(start) || !isValid(end)) return null;
|
|
45
|
+
|
|
46
|
+
return { event, start, end: end < start ? start : end };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Events whose date range overlaps `[start, end)`. */
|
|
50
|
+
export function eventsOverlapping(
|
|
51
|
+
events: Array<IEvent>,
|
|
52
|
+
start: Date,
|
|
53
|
+
end: Date
|
|
54
|
+
): Array<IEvent> {
|
|
55
|
+
return events.filter((event) => {
|
|
56
|
+
const interval = toInterval(event);
|
|
57
|
+
|
|
58
|
+
if (!interval) return false;
|
|
59
|
+
|
|
60
|
+
return interval.start < end && interval.end >= start;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Clip every overlapping event to the row, then greedily pack the segments into
|
|
66
|
+
* lanes (earliest start first, longest first on ties) so a long bar never gets
|
|
67
|
+
* pushed below the short ones that start after it.
|
|
68
|
+
*/
|
|
69
|
+
export function layoutRowEvents(
|
|
70
|
+
events: Array<IEvent>,
|
|
71
|
+
row: TimelineRow,
|
|
72
|
+
options: { maxLanes: number; expanded: boolean }
|
|
73
|
+
): TimelineRowLayout {
|
|
74
|
+
const intervals = events
|
|
75
|
+
.map(toInterval)
|
|
76
|
+
.filter((interval): interval is EventInterval => interval !== null)
|
|
77
|
+
.filter(interval => interval.start < row.end && interval.end >= row.start)
|
|
78
|
+
.sort((a, b) => {
|
|
79
|
+
const byStart = a.start.getTime() - b.start.getTime();
|
|
80
|
+
|
|
81
|
+
if (byStart !== 0) return byStart;
|
|
82
|
+
|
|
83
|
+
return (b.end.getTime() - b.start.getTime()) - (a.end.getTime() - a.start.getTime());
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const lanes: Array<Array<TimelineSegment>> = [];
|
|
87
|
+
const laneEnds: Array<number> = [];
|
|
88
|
+
|
|
89
|
+
for (const interval of intervals) {
|
|
90
|
+
const clippedStart = interval.start < row.start ? row.start : interval.start;
|
|
91
|
+
const clippedEnd = interval.end > row.end ? row.end : interval.end;
|
|
92
|
+
const left = dateToFraction(row, clippedStart);
|
|
93
|
+
const right = dateToFraction(row, clippedEnd);
|
|
94
|
+
|
|
95
|
+
const segment: TimelineSegment = {
|
|
96
|
+
key: `${interval.event.id}-${row.key}`,
|
|
97
|
+
event: interval.event,
|
|
98
|
+
left,
|
|
99
|
+
width: Math.max(right - left, 0),
|
|
100
|
+
start: clippedStart,
|
|
101
|
+
end: clippedEnd,
|
|
102
|
+
continuesBefore: interval.start < row.start,
|
|
103
|
+
continuesAfter: interval.end > row.end
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const startTime = clippedStart.getTime();
|
|
107
|
+
let laneIndex = laneEnds.findIndex(laneEnd => laneEnd <= startTime);
|
|
108
|
+
|
|
109
|
+
if (laneIndex === -1) {
|
|
110
|
+
laneIndex = lanes.length;
|
|
111
|
+
lanes.push([]);
|
|
112
|
+
laneEnds.push(0);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
(lanes[laneIndex] as Array<TimelineSegment>).push(segment);
|
|
116
|
+
laneEnds[laneIndex] = clippedEnd.getTime();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const maxLanes = Math.max(1, options.maxLanes);
|
|
120
|
+
const visibleLanes = options.expanded ? lanes : lanes.slice(0, maxLanes);
|
|
121
|
+
const hiddenEvents = options.expanded ? [] : lanes.slice(maxLanes).flat().map(segment => segment.event);
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
lanes,
|
|
125
|
+
visibleLanes,
|
|
126
|
+
hiddenEvents,
|
|
127
|
+
hiddenCount: hiddenEvents.length,
|
|
128
|
+
events: intervals.map(interval => interval.event)
|
|
129
|
+
};
|
|
130
|
+
}
|