@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,617 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
import {
|
|
4
|
+
addDays,
|
|
5
|
+
addMonths,
|
|
6
|
+
addQuarters,
|
|
7
|
+
addWeeks,
|
|
8
|
+
addYears,
|
|
9
|
+
differenceInDays,
|
|
10
|
+
differenceInMinutes,
|
|
11
|
+
eachDayOfInterval,
|
|
12
|
+
endOfMonth,
|
|
13
|
+
endOfQuarter,
|
|
14
|
+
endOfWeek,
|
|
15
|
+
endOfYear,
|
|
16
|
+
format,
|
|
17
|
+
isSameDay,
|
|
18
|
+
isSameMonth,
|
|
19
|
+
isSameQuarter,
|
|
20
|
+
isSameWeek,
|
|
21
|
+
isSameYear,
|
|
22
|
+
isValid,
|
|
23
|
+
parseISO,
|
|
24
|
+
startOfDay,
|
|
25
|
+
startOfMonth,
|
|
26
|
+
startOfQuarter,
|
|
27
|
+
startOfWeek,
|
|
28
|
+
startOfYear,
|
|
29
|
+
subDays,
|
|
30
|
+
subMonths,
|
|
31
|
+
subQuarters,
|
|
32
|
+
subWeeks,
|
|
33
|
+
subYears
|
|
34
|
+
} from 'date-fns';
|
|
35
|
+
|
|
36
|
+
type FormatDateFn = (value: unknown) => string;
|
|
37
|
+
|
|
38
|
+
import {
|
|
39
|
+
type ICalendarCell, type IEvent
|
|
40
|
+
} from './interfaces';
|
|
41
|
+
import {
|
|
42
|
+
type TCalendarView, type TEventColor, type TWeekStartsOn
|
|
43
|
+
} from './types';
|
|
44
|
+
|
|
45
|
+
import { useCalendar } from './contexts/calendar-context';
|
|
46
|
+
import { thirteenWeeksStart } from './views/timeline/lib/timeline-model';
|
|
47
|
+
|
|
48
|
+
const FORMAT_STRING = 'MMM d, yyyy';
|
|
49
|
+
|
|
50
|
+
export function rangeText(
|
|
51
|
+
view: TCalendarView,
|
|
52
|
+
date: Date,
|
|
53
|
+
formatDate?: FormatDateFn,
|
|
54
|
+
weekStartsOn: TWeekStartsOn = 0
|
|
55
|
+
): string {
|
|
56
|
+
const fmt: FormatDateFn = formatDate ?? (value => format(value as Date, FORMAT_STRING));
|
|
57
|
+
let start: Date;
|
|
58
|
+
let end: Date;
|
|
59
|
+
|
|
60
|
+
switch (view) {
|
|
61
|
+
case 'month':
|
|
62
|
+
start = startOfMonth(date);
|
|
63
|
+
end = endOfMonth(date);
|
|
64
|
+
break;
|
|
65
|
+
|
|
66
|
+
case 'week':
|
|
67
|
+
start = startOfWeek(date, { weekStartsOn });
|
|
68
|
+
end = endOfWeek(date, { weekStartsOn });
|
|
69
|
+
break;
|
|
70
|
+
|
|
71
|
+
case 'day':
|
|
72
|
+
return fmt(date);
|
|
73
|
+
|
|
74
|
+
case 'year':
|
|
75
|
+
start = startOfYear(date);
|
|
76
|
+
end = endOfYear(date);
|
|
77
|
+
break;
|
|
78
|
+
|
|
79
|
+
case 'agenda':
|
|
80
|
+
start = startOfMonth(date);
|
|
81
|
+
end = endOfMonth(date);
|
|
82
|
+
break;
|
|
83
|
+
|
|
84
|
+
case 'year-timeline':
|
|
85
|
+
start = startOfYear(date);
|
|
86
|
+
end = endOfYear(date);
|
|
87
|
+
break;
|
|
88
|
+
|
|
89
|
+
case 'quarter':
|
|
90
|
+
start = startOfQuarter(date);
|
|
91
|
+
end = endOfQuarter(date);
|
|
92
|
+
break;
|
|
93
|
+
|
|
94
|
+
case '13weeks':
|
|
95
|
+
start = thirteenWeeksStart(date, weekStartsOn);
|
|
96
|
+
end = addDays(addWeeks(start, 13), -1);
|
|
97
|
+
break;
|
|
98
|
+
|
|
99
|
+
default:
|
|
100
|
+
return 'Error while formatting';
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return `${fmt(start)} - ${fmt(end)}`;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function navigateDate(
|
|
107
|
+
date: Date,
|
|
108
|
+
view: TCalendarView,
|
|
109
|
+
direction: 'previous' | 'next'
|
|
110
|
+
): Date {
|
|
111
|
+
const operations: Record<TCalendarView, (d: Date, n: number) => Date> = {
|
|
112
|
+
month: direction === 'next' ? addMonths : subMonths,
|
|
113
|
+
week: direction === 'next' ? addWeeks : subWeeks,
|
|
114
|
+
day: direction === 'next' ? addDays : subDays,
|
|
115
|
+
year: direction === 'next' ? addYears : subYears,
|
|
116
|
+
agenda: direction === 'next' ? addMonths : subMonths,
|
|
117
|
+
'year-timeline': direction === 'next' ? addYears : subYears,
|
|
118
|
+
quarter: direction === 'next' ? addQuarters : subQuarters,
|
|
119
|
+
/* The window floats: one step is exactly thirteen weeks. */
|
|
120
|
+
'13weeks': direction === 'next' ? (d: Date) => addWeeks(d, 13) : (d: Date) => subWeeks(d, 13)
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
return operations[view](date, 1);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Count the events a view is showing. Period-timeline views count every event
|
|
128
|
+
* OVERLAPPING the window (a multi-month bar belongs to every period it crosses),
|
|
129
|
+
* which is also why they accept an explicit `range` — in continuous mode the
|
|
130
|
+
* rendered window spans more than one period.
|
|
131
|
+
*/
|
|
132
|
+
export function getEventsCount(
|
|
133
|
+
events: Array<IEvent>,
|
|
134
|
+
date: Date,
|
|
135
|
+
view: TCalendarView,
|
|
136
|
+
range?: { start: Date; end: Date } | null
|
|
137
|
+
): number {
|
|
138
|
+
const timelineRange = range ?? getTimelineFallbackRange(date, view);
|
|
139
|
+
|
|
140
|
+
if (timelineRange) {
|
|
141
|
+
return events.filter((event) => {
|
|
142
|
+
const start = parseISO(event.startDate);
|
|
143
|
+
const end = parseISO(event.endDate);
|
|
144
|
+
|
|
145
|
+
if (!isValid(start) || !isValid(end)) return false;
|
|
146
|
+
|
|
147
|
+
return start < timelineRange.end && end >= timelineRange.start;
|
|
148
|
+
}).length;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const compareFns: Record<TCalendarView, (d1: Date, d2: Date) => boolean> = {
|
|
152
|
+
day: isSameDay,
|
|
153
|
+
week: isSameWeek,
|
|
154
|
+
month: isSameMonth,
|
|
155
|
+
year: isSameYear,
|
|
156
|
+
agenda: isSameMonth,
|
|
157
|
+
'year-timeline': isSameYear,
|
|
158
|
+
quarter: isSameQuarter,
|
|
159
|
+
'13weeks': isSameQuarter
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const compareFn = compareFns[view];
|
|
163
|
+
|
|
164
|
+
return events.filter(event => compareFn(parseISO(event.startDate), date))
|
|
165
|
+
.length;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function getTimelineFallbackRange(
|
|
169
|
+
date: Date,
|
|
170
|
+
view: TCalendarView
|
|
171
|
+
): { start: Date; end: Date } | null {
|
|
172
|
+
if (view === 'year-timeline') return { start: startOfYear(date), end: endOfYear(date) };
|
|
173
|
+
if (view === 'quarter') return { start: startOfQuarter(date), end: endOfQuarter(date) };
|
|
174
|
+
if (view === '13weeks') {
|
|
175
|
+
const start = thirteenWeeksStart(date, 0);
|
|
176
|
+
|
|
177
|
+
return { start, end: addWeeks(start, 13) };
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export function groupEvents(dayEvents: Array<IEvent>): Array<Array<IEvent>> {
|
|
184
|
+
const sortedEvents = dayEvents.sort(
|
|
185
|
+
(a, b) => parseISO(a.startDate).getTime() - parseISO(b.startDate).getTime()
|
|
186
|
+
);
|
|
187
|
+
const groups: Array<Array<IEvent>> = [];
|
|
188
|
+
|
|
189
|
+
for (const event of sortedEvents) {
|
|
190
|
+
const eventStart = parseISO(event.startDate);
|
|
191
|
+
let placed = false;
|
|
192
|
+
|
|
193
|
+
for (const group of groups) {
|
|
194
|
+
const lastEventInGroup = group[group.length - 1] as IEvent;
|
|
195
|
+
const lastEventEnd = parseISO(lastEventInGroup.endDate);
|
|
196
|
+
|
|
197
|
+
if (eventStart >= lastEventEnd) {
|
|
198
|
+
group.push(event);
|
|
199
|
+
placed = true;
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (!placed) groups.push([event]);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return groups;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export function getEventBlockStyle(
|
|
211
|
+
event: IEvent,
|
|
212
|
+
day: Date,
|
|
213
|
+
groupIndex: number,
|
|
214
|
+
groupSize: number,
|
|
215
|
+
hourRange: { startHour: number; endHour: number } = { startHour: 0, endHour: 24 }
|
|
216
|
+
) {
|
|
217
|
+
const startDate = parseISO(event.startDate);
|
|
218
|
+
const dayStart = startOfDay(day);
|
|
219
|
+
const eventStart = startDate < dayStart ? dayStart : startDate;
|
|
220
|
+
const startMinutes = differenceInMinutes(eventStart, dayStart);
|
|
221
|
+
|
|
222
|
+
const rangeStartMinutes = hourRange.startHour * 60;
|
|
223
|
+
const rangeMinutes = Math.max(1, (hourRange.endHour - hourRange.startHour) * 60);
|
|
224
|
+
const offsetMinutes = startMinutes - rangeStartMinutes;
|
|
225
|
+
const top = (offsetMinutes / rangeMinutes) * 100;
|
|
226
|
+
const width = 100 / groupSize;
|
|
227
|
+
const left = groupIndex * width;
|
|
228
|
+
|
|
229
|
+
return { top: `${top}%`, width: `${width}%`, left: `${left}%` };
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export function getCalendarCells(
|
|
233
|
+
selectedDate: Date,
|
|
234
|
+
weekStartsOn: TWeekStartsOn = 0
|
|
235
|
+
): Array<ICalendarCell> {
|
|
236
|
+
const year = selectedDate.getFullYear();
|
|
237
|
+
const month = selectedDate.getMonth();
|
|
238
|
+
|
|
239
|
+
const daysInMonth = endOfMonth(selectedDate).getDate();
|
|
240
|
+
const rawFirstDayOfMonth = startOfMonth(selectedDate).getDay();
|
|
241
|
+
const firstDayOfMonth = (rawFirstDayOfMonth - weekStartsOn + 7) % 7;
|
|
242
|
+
const daysInPrevMonth = endOfMonth(new Date(year, month - 1)).getDate();
|
|
243
|
+
const totalDays = firstDayOfMonth + daysInMonth;
|
|
244
|
+
|
|
245
|
+
const prevMonthCells = Array.from({ length: firstDayOfMonth }, (_, i) => ({
|
|
246
|
+
day: daysInPrevMonth - firstDayOfMonth + i + 1,
|
|
247
|
+
currentMonth: false,
|
|
248
|
+
date: new Date(year, month - 1, daysInPrevMonth - firstDayOfMonth + i + 1)
|
|
249
|
+
}));
|
|
250
|
+
|
|
251
|
+
const currentMonthCells = Array.from({ length: daysInMonth }, (_, i) => ({
|
|
252
|
+
day: i + 1,
|
|
253
|
+
currentMonth: true,
|
|
254
|
+
date: new Date(year, month, i + 1)
|
|
255
|
+
}));
|
|
256
|
+
|
|
257
|
+
const nextMonthCells = Array.from(
|
|
258
|
+
{ length: (7 - (totalDays % 7)) % 7 },
|
|
259
|
+
(_, i) => ({
|
|
260
|
+
day: i + 1,
|
|
261
|
+
currentMonth: false,
|
|
262
|
+
date: new Date(year, month + 1, i + 1)
|
|
263
|
+
})
|
|
264
|
+
);
|
|
265
|
+
|
|
266
|
+
return [...prevMonthCells, ...currentMonthCells, ...nextMonthCells];
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export function calculateMonthEventPositions(
|
|
270
|
+
multiDayEvents: Array<IEvent>,
|
|
271
|
+
singleDayEvents: Array<IEvent>,
|
|
272
|
+
selectedDate: Date
|
|
273
|
+
): Record<string, number> {
|
|
274
|
+
const monthStart = startOfMonth(selectedDate);
|
|
275
|
+
const monthEnd = endOfMonth(selectedDate);
|
|
276
|
+
|
|
277
|
+
const eventPositions: Record<string, number> = {};
|
|
278
|
+
const occupiedPositions: Record<string, Array<boolean>> = {};
|
|
279
|
+
|
|
280
|
+
eachDayOfInterval({ start: monthStart, end: monthEnd }).forEach((day) => {
|
|
281
|
+
occupiedPositions[day.toISOString()] = [false, false, false];
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
const sortedEvents = [
|
|
285
|
+
...multiDayEvents.sort((a, b) => {
|
|
286
|
+
const aDuration = differenceInDays(
|
|
287
|
+
parseISO(a.endDate),
|
|
288
|
+
parseISO(a.startDate)
|
|
289
|
+
);
|
|
290
|
+
const bDuration = differenceInDays(
|
|
291
|
+
parseISO(b.endDate),
|
|
292
|
+
parseISO(b.startDate)
|
|
293
|
+
);
|
|
294
|
+
|
|
295
|
+
return (
|
|
296
|
+
bDuration - aDuration
|
|
297
|
+
|| parseISO(a.startDate).getTime() - parseISO(b.startDate).getTime()
|
|
298
|
+
);
|
|
299
|
+
}),
|
|
300
|
+
...singleDayEvents.sort(
|
|
301
|
+
(a, b) => parseISO(a.startDate).getTime() - parseISO(b.startDate).getTime()
|
|
302
|
+
)
|
|
303
|
+
];
|
|
304
|
+
|
|
305
|
+
sortedEvents.forEach((event) => {
|
|
306
|
+
const eventStart = parseISO(event.startDate);
|
|
307
|
+
const eventEnd = parseISO(event.endDate);
|
|
308
|
+
const eventDays = eachDayOfInterval({
|
|
309
|
+
start: eventStart < monthStart ? monthStart : eventStart,
|
|
310
|
+
end: eventEnd > monthEnd ? monthEnd : eventEnd
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
let position = -1;
|
|
314
|
+
|
|
315
|
+
for (let i = 0; i < 3; i++) {
|
|
316
|
+
if (
|
|
317
|
+
eventDays.every((day) => {
|
|
318
|
+
const dayPositions = occupiedPositions[
|
|
319
|
+
startOfDay(day).toISOString()
|
|
320
|
+
] as Array<boolean> | undefined;
|
|
321
|
+
|
|
322
|
+
return dayPositions != null && !dayPositions[i];
|
|
323
|
+
})
|
|
324
|
+
) {
|
|
325
|
+
position = i;
|
|
326
|
+
break;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (position !== -1) {
|
|
331
|
+
eventDays.forEach((day) => {
|
|
332
|
+
const dayKey = startOfDay(day).toISOString();
|
|
333
|
+
|
|
334
|
+
const dayPositions = occupiedPositions[dayKey];
|
|
335
|
+
|
|
336
|
+
if (dayPositions) dayPositions[position] = true;
|
|
337
|
+
});
|
|
338
|
+
eventPositions[event.id] = position;
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
return eventPositions;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
export function getMonthCellEvents(
|
|
346
|
+
date: Date,
|
|
347
|
+
events: Array<IEvent>,
|
|
348
|
+
eventPositions: Record<string, number>
|
|
349
|
+
) {
|
|
350
|
+
const dayStart = startOfDay(date);
|
|
351
|
+
const eventsForDate = events.filter((event) => {
|
|
352
|
+
const eventStart = parseISO(event.startDate);
|
|
353
|
+
const eventEnd = parseISO(event.endDate);
|
|
354
|
+
|
|
355
|
+
return (
|
|
356
|
+
(dayStart >= eventStart && dayStart <= eventEnd)
|
|
357
|
+
|| isSameDay(dayStart, eventStart)
|
|
358
|
+
|| isSameDay(dayStart, eventEnd)
|
|
359
|
+
);
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
return eventsForDate
|
|
363
|
+
.map(event => ({
|
|
364
|
+
...event,
|
|
365
|
+
position:
|
|
366
|
+
(eventPositions as Record<string, number | undefined>)[event.id] ?? -1,
|
|
367
|
+
isMultiDay: event.startDate !== event.endDate
|
|
368
|
+
}))
|
|
369
|
+
.sort((a, b) => {
|
|
370
|
+
if (a.isMultiDay && !b.isMultiDay) return -1;
|
|
371
|
+
if (!a.isMultiDay && b.isMultiDay) return 1;
|
|
372
|
+
|
|
373
|
+
return a.position - b.position;
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
export function formatTime(
|
|
378
|
+
date: Date | string,
|
|
379
|
+
use24HourFormat: boolean
|
|
380
|
+
): string {
|
|
381
|
+
const parsedDate = typeof date === 'string' ? parseISO(date) : date;
|
|
382
|
+
|
|
383
|
+
if (!isValid(parsedDate)) return '';
|
|
384
|
+
|
|
385
|
+
return format(parsedDate, use24HourFormat ? 'HH:mm' : 'h:mm a');
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
export const getFirstLetters = (str: string): string => {
|
|
389
|
+
if (!str) return '';
|
|
390
|
+
const words = str.split(' ');
|
|
391
|
+
|
|
392
|
+
if (words.length === 1) return (words[0] as string).charAt(0).toUpperCase();
|
|
393
|
+
|
|
394
|
+
return `${(words[0] as string).charAt(0).toUpperCase()}${(words[1] as string).charAt(0).toUpperCase()}`;
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
export const getEventsForDay = (
|
|
398
|
+
events: Array<IEvent>,
|
|
399
|
+
date: Date,
|
|
400
|
+
isWeek = false
|
|
401
|
+
): Array<IEvent> => {
|
|
402
|
+
const targetDate = startOfDay(date);
|
|
403
|
+
|
|
404
|
+
return events
|
|
405
|
+
.filter((event) => {
|
|
406
|
+
const startOfDayForEventStart = startOfDay(parseISO(event.startDate));
|
|
407
|
+
const startOfDayForEventEnd = startOfDay(parseISO(event.endDate));
|
|
408
|
+
|
|
409
|
+
if (isWeek) {
|
|
410
|
+
return (
|
|
411
|
+
event.startDate !== event.endDate
|
|
412
|
+
&& startOfDayForEventStart <= targetDate
|
|
413
|
+
&& startOfDayForEventEnd >= targetDate
|
|
414
|
+
);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
return (
|
|
418
|
+
startOfDayForEventStart <= targetDate
|
|
419
|
+
&& startOfDayForEventEnd >= targetDate
|
|
420
|
+
);
|
|
421
|
+
})
|
|
422
|
+
.map((event) => {
|
|
423
|
+
const eventStart = startOfDay(parseISO(event.startDate));
|
|
424
|
+
const eventEnd = startOfDay(parseISO(event.endDate));
|
|
425
|
+
let point: 'start' | 'end' | 'none' | undefined;
|
|
426
|
+
|
|
427
|
+
if (isSameDay(eventStart, eventEnd)) {
|
|
428
|
+
point = 'none';
|
|
429
|
+
} else if (isSameDay(eventStart, targetDate)) {
|
|
430
|
+
point = 'start';
|
|
431
|
+
} else if (isSameDay(eventEnd, targetDate)) {
|
|
432
|
+
point = 'end';
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
return { ...event, point };
|
|
436
|
+
});
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
export const getWeekDates = (
|
|
440
|
+
date: Date,
|
|
441
|
+
weekStartsOn: TWeekStartsOn = 0
|
|
442
|
+
): Array<Date> => {
|
|
443
|
+
const startDate = startOfWeek(date, { weekStartsOn });
|
|
444
|
+
|
|
445
|
+
return Array.from({ length: 7 }, (_, i) => addDays(startDate, i));
|
|
446
|
+
};
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* Return the half-open list of hours [startHour, endHour) for week/day grids.
|
|
450
|
+
* Defaults to a full 24-hour day if no range is provided. Falls back to a
|
|
451
|
+
* single-hour window when the inputs are invalid so the grid still renders.
|
|
452
|
+
*/
|
|
453
|
+
export const getHoursInRange = (
|
|
454
|
+
startHour = 0,
|
|
455
|
+
endHour = 24
|
|
456
|
+
): Array<number> => {
|
|
457
|
+
const safeStart = Math.max(0, Math.min(24, Math.floor(startHour)));
|
|
458
|
+
const safeEnd = Math.max(safeStart + 1, Math.min(24, Math.ceil(endHour)));
|
|
459
|
+
|
|
460
|
+
return Array.from({ length: safeEnd - safeStart }, (_, i) => safeStart + i);
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
export const getEventsForWeek = (
|
|
464
|
+
events: Array<IEvent>,
|
|
465
|
+
date: Date,
|
|
466
|
+
weekStartsOn: TWeekStartsOn = 0
|
|
467
|
+
): Array<IEvent> => {
|
|
468
|
+
const weekDates = getWeekDates(date, weekStartsOn);
|
|
469
|
+
const startOfWeekDate = weekDates[0] as Date;
|
|
470
|
+
const endOfWeekDate = weekDates[6] as Date;
|
|
471
|
+
|
|
472
|
+
return events.filter((event) => {
|
|
473
|
+
const eventStart = parseISO(event.startDate);
|
|
474
|
+
const eventEnd = parseISO(event.endDate);
|
|
475
|
+
|
|
476
|
+
return (
|
|
477
|
+
isValid(eventStart)
|
|
478
|
+
&& isValid(eventEnd)
|
|
479
|
+
&& eventStart <= endOfWeekDate
|
|
480
|
+
&& eventEnd >= startOfWeekDate
|
|
481
|
+
);
|
|
482
|
+
});
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
export const getEventsForMonth = (
|
|
486
|
+
events: Array<IEvent>,
|
|
487
|
+
date: Date
|
|
488
|
+
): Array<IEvent> => {
|
|
489
|
+
const startOfMonthDate = startOfMonth(date);
|
|
490
|
+
const endOfMonthDate = endOfMonth(date);
|
|
491
|
+
|
|
492
|
+
return events.filter((event) => {
|
|
493
|
+
const eventStart = parseISO(event.startDate);
|
|
494
|
+
const eventEnd = parseISO(event.endDate);
|
|
495
|
+
|
|
496
|
+
return (
|
|
497
|
+
isValid(eventStart)
|
|
498
|
+
&& isValid(eventEnd)
|
|
499
|
+
&& eventStart <= endOfMonthDate
|
|
500
|
+
&& eventEnd >= startOfMonthDate
|
|
501
|
+
);
|
|
502
|
+
});
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
export const getEventsForYear = (
|
|
506
|
+
events: Array<IEvent>,
|
|
507
|
+
date: Date
|
|
508
|
+
): Array<IEvent> => {
|
|
509
|
+
if (!isValid(date)) return [];
|
|
510
|
+
|
|
511
|
+
const startOfYearDate = startOfYear(date);
|
|
512
|
+
const endOfYearDate = endOfYear(date);
|
|
513
|
+
|
|
514
|
+
return events.filter((event) => {
|
|
515
|
+
const eventStart = parseISO(event.startDate);
|
|
516
|
+
const eventEnd = parseISO(event.endDate);
|
|
517
|
+
|
|
518
|
+
return (
|
|
519
|
+
isValid(eventStart)
|
|
520
|
+
&& isValid(eventEnd)
|
|
521
|
+
&& eventStart <= endOfYearDate
|
|
522
|
+
&& eventEnd >= startOfYearDate
|
|
523
|
+
);
|
|
524
|
+
});
|
|
525
|
+
};
|
|
526
|
+
|
|
527
|
+
/** Events whose date range overlaps `[start, end]`. */
|
|
528
|
+
export const getEventsForInterval = (
|
|
529
|
+
events: Array<IEvent>,
|
|
530
|
+
start: Date,
|
|
531
|
+
end: Date
|
|
532
|
+
): Array<IEvent> => events.filter((event) => {
|
|
533
|
+
const eventStart = parseISO(event.startDate);
|
|
534
|
+
const eventEnd = parseISO(event.endDate);
|
|
535
|
+
|
|
536
|
+
return (
|
|
537
|
+
isValid(eventStart)
|
|
538
|
+
&& isValid(eventEnd)
|
|
539
|
+
&& eventStart <= end
|
|
540
|
+
&& eventEnd >= start
|
|
541
|
+
);
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
export const getColorClass = (color: string): string => {
|
|
545
|
+
const colorClasses: Record<TEventColor, string> = {
|
|
546
|
+
red: 'border-red-200 bg-red-50 text-red-700 dark:border-red-800 dark:bg-red-950 dark:text-red-300',
|
|
547
|
+
yellow:
|
|
548
|
+
'border-yellow-200 bg-yellow-50 text-yellow-700 dark:border-yellow-800 dark:bg-yellow-950 dark:text-yellow-300',
|
|
549
|
+
green:
|
|
550
|
+
'border-green-200 bg-green-50 text-green-700 dark:border-green-800 dark:bg-green-950 dark:text-green-300',
|
|
551
|
+
blue: 'border-blue-200 bg-blue-50 text-blue-700 dark:border-blue-800 dark:bg-blue-950 dark:text-blue-300',
|
|
552
|
+
orange:
|
|
553
|
+
'border-orange-200 bg-orange-50 text-orange-700 dark:border-orange-800 dark:bg-orange-950 dark:text-orange-300',
|
|
554
|
+
purple:
|
|
555
|
+
'border-purple-200 bg-purple-50 text-purple-700 dark:border-purple-800 dark:bg-purple-950 dark:text-purple-300'
|
|
556
|
+
};
|
|
557
|
+
|
|
558
|
+
return colorClasses[color as TEventColor] || '';
|
|
559
|
+
};
|
|
560
|
+
|
|
561
|
+
export const getBgColor = (color: string): string => {
|
|
562
|
+
const colorClasses: Record<TEventColor, string> = {
|
|
563
|
+
red: 'bg-red-400 dark:bg-red-600',
|
|
564
|
+
yellow: 'bg-yellow-400 dark:bg-yellow-600',
|
|
565
|
+
green: 'bg-green-400 dark:bg-green-600',
|
|
566
|
+
blue: 'bg-blue-400 dark:bg-blue-600',
|
|
567
|
+
orange: 'bg-orange-400 dark:bg-orange-600',
|
|
568
|
+
purple: 'bg-purple-400 dark:bg-purple-600'
|
|
569
|
+
};
|
|
570
|
+
|
|
571
|
+
return colorClasses[color as TEventColor] || '';
|
|
572
|
+
};
|
|
573
|
+
|
|
574
|
+
export const useGetEventsByMode = (events: Array<IEvent>) => {
|
|
575
|
+
const { view, selectedDate, weekStartsOn } = useCalendar();
|
|
576
|
+
|
|
577
|
+
switch (view) {
|
|
578
|
+
case 'day':
|
|
579
|
+
return getEventsForDay(events, selectedDate);
|
|
580
|
+
|
|
581
|
+
case 'week':
|
|
582
|
+
return getEventsForWeek(events, selectedDate, weekStartsOn);
|
|
583
|
+
|
|
584
|
+
case 'agenda':
|
|
585
|
+
|
|
586
|
+
case 'month':
|
|
587
|
+
return getEventsForMonth(events, selectedDate);
|
|
588
|
+
|
|
589
|
+
case 'year':
|
|
590
|
+
|
|
591
|
+
case 'year-timeline':
|
|
592
|
+
return getEventsForYear(events, selectedDate);
|
|
593
|
+
|
|
594
|
+
case 'quarter':
|
|
595
|
+
return getEventsForInterval(
|
|
596
|
+
events,
|
|
597
|
+
startOfQuarter(selectedDate),
|
|
598
|
+
endOfQuarter(selectedDate)
|
|
599
|
+
);
|
|
600
|
+
|
|
601
|
+
case '13weeks':
|
|
602
|
+
return getEventsForInterval(
|
|
603
|
+
events,
|
|
604
|
+
thirteenWeeksStart(selectedDate, weekStartsOn),
|
|
605
|
+
addWeeks(thirteenWeeksStart(selectedDate, weekStartsOn), 13)
|
|
606
|
+
);
|
|
607
|
+
|
|
608
|
+
default:
|
|
609
|
+
return [];
|
|
610
|
+
}
|
|
611
|
+
};
|
|
612
|
+
|
|
613
|
+
export const toCapitalize = (str: string): string => {
|
|
614
|
+
if (!str) return '';
|
|
615
|
+
|
|
616
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
617
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
|
|
5
|
+
export function useDisclosure({
|
|
6
|
+
defaultIsOpen = false
|
|
7
|
+
}: {
|
|
8
|
+
defaultIsOpen?: boolean;
|
|
9
|
+
} = {}) {
|
|
10
|
+
const [isOpen, setIsOpen] = useState(defaultIsOpen);
|
|
11
|
+
|
|
12
|
+
const onOpen = () => setIsOpen(true);
|
|
13
|
+
const onClose = () => setIsOpen(false);
|
|
14
|
+
const onToggle = () => setIsOpen(currentValue => !currentValue);
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
onOpen, onClose, isOpen, onToggle
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
|
|
5
|
+
export function useLocalStorage<T>(
|
|
6
|
+
key: string,
|
|
7
|
+
initialValue: T
|
|
8
|
+
): [T, (value: T) => void] {
|
|
9
|
+
const readValue = (): T => {
|
|
10
|
+
if (typeof window === 'undefined') return initialValue;
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
const item = window.localStorage.getItem(key);
|
|
14
|
+
|
|
15
|
+
return item ? (JSON.parse(item) as T) : initialValue;
|
|
16
|
+
} catch (error) {
|
|
17
|
+
console.warn(`Error reading localStorage key "${key}":`, error);
|
|
18
|
+
|
|
19
|
+
return initialValue;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const [storedValue, setStoredValue] = useState<T>(readValue);
|
|
24
|
+
|
|
25
|
+
const setValue = (value: T) => {
|
|
26
|
+
try {
|
|
27
|
+
const valueToStore = value instanceof Function ? value(storedValue) : value;
|
|
28
|
+
|
|
29
|
+
setStoredValue(valueToStore);
|
|
30
|
+
|
|
31
|
+
if (typeof window !== 'undefined') {
|
|
32
|
+
window.localStorage.setItem(key, JSON.stringify(valueToStore));
|
|
33
|
+
}
|
|
34
|
+
} catch (error) {
|
|
35
|
+
console.warn(`Error setting localStorage key "${key}":`, error);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
return [storedValue, setValue];
|
|
40
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
import { useEffect, useState } from 'react';
|
|
4
|
+
|
|
5
|
+
export function useMediaQuery(query: string): boolean {
|
|
6
|
+
const [matches, setMatches] = useState(
|
|
7
|
+
() => typeof window !== 'undefined' && window.matchMedia(query).matches
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
const media = window.matchMedia(query);
|
|
12
|
+
|
|
13
|
+
if (media.matches !== matches) {
|
|
14
|
+
queueMicrotask(() => setMatches(media.matches));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const listener = () => setMatches(media.matches);
|
|
18
|
+
|
|
19
|
+
media.addEventListener('change', listener);
|
|
20
|
+
|
|
21
|
+
return () => media.removeEventListener('change', listener);
|
|
22
|
+
}, [matches, query]);
|
|
23
|
+
|
|
24
|
+
return matches;
|
|
25
|
+
}
|