react-native-ll-calendar 0.10.0 → 0.11.0

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 (26) hide show
  1. package/lib/module/calendar/resources-calendar/ResourcesCalendar.js +429 -0
  2. package/lib/module/calendar/resources-calendar/ResourcesCalendar.js.map +1 -0
  3. package/lib/module/index.js +1 -0
  4. package/lib/module/index.js.map +1 -1
  5. package/lib/module/types/resources-calendar.js +2 -0
  6. package/lib/module/types/resources-calendar.js.map +1 -0
  7. package/lib/module/utils/functions.js +30 -0
  8. package/lib/module/utils/functions.js.map +1 -1
  9. package/lib/module/utils/resources-calendar-event-position.js +68 -0
  10. package/lib/module/utils/resources-calendar-event-position.js.map +1 -0
  11. package/lib/typescript/src/calendar/resources-calendar/ResourcesCalendar.d.ts +34 -0
  12. package/lib/typescript/src/calendar/resources-calendar/ResourcesCalendar.d.ts.map +1 -0
  13. package/lib/typescript/src/index.d.ts +2 -0
  14. package/lib/typescript/src/index.d.ts.map +1 -1
  15. package/lib/typescript/src/types/resources-calendar.d.ts +18 -0
  16. package/lib/typescript/src/types/resources-calendar.d.ts.map +1 -0
  17. package/lib/typescript/src/utils/functions.d.ts +8 -0
  18. package/lib/typescript/src/utils/functions.d.ts.map +1 -1
  19. package/lib/typescript/src/utils/resources-calendar-event-position.d.ts +22 -0
  20. package/lib/typescript/src/utils/resources-calendar-event-position.d.ts.map +1 -0
  21. package/package.json +1 -1
  22. package/src/calendar/resources-calendar/ResourcesCalendar.tsx +580 -0
  23. package/src/index.tsx +6 -0
  24. package/src/types/resources-calendar.ts +18 -0
  25. package/src/utils/functions.ts +34 -0
  26. package/src/utils/resources-calendar-event-position.ts +68 -0
@@ -77,3 +77,37 @@ export function getWeekIds(args: {
77
77
  }
78
78
  return weekIds;
79
79
  }
80
+
81
+ export function generateDates(from: Date, to: Date): Date[] {
82
+ const dates: Date[] = [];
83
+ const current = new Date(from);
84
+ current.setHours(0, 0, 0, 0);
85
+ const end = new Date(to);
86
+ end.setHours(0, 0, 0, 0);
87
+ while (current <= end) {
88
+ dates.push(new Date(current));
89
+ current.setDate(current.getDate() + 1);
90
+ }
91
+ return dates;
92
+ }
93
+
94
+ type MonthGroup = {
95
+ year: number;
96
+ month: number;
97
+ dates: Date[];
98
+ };
99
+
100
+ export function groupDatesByMonth(dates: Date[]): MonthGroup[] {
101
+ const groups: MonthGroup[] = [];
102
+ for (const date of dates) {
103
+ const year = date.getFullYear();
104
+ const month = date.getMonth() + 1;
105
+ const last = groups[groups.length - 1];
106
+ if (last && last.year === year && last.month === month) {
107
+ last.dates.push(date);
108
+ } else {
109
+ groups.push({ year, month, dates: [date] });
110
+ }
111
+ }
112
+ return groups;
113
+ }
@@ -0,0 +1,68 @@
1
+ class ResourcesCalendarEventPosition {
2
+ public record: Record<string, Record<string, number[]>> = {};
3
+ constructor() {}
4
+
5
+ private generateKey(date: Date): string {
6
+ const year = date.getFullYear();
7
+ const month = date.getMonth() + 1;
8
+ const day = date.getDate();
9
+ return `${year}-${month}-${day}`;
10
+ }
11
+
12
+ public push(arg: {
13
+ resourceId: string;
14
+ startDate: Date;
15
+ days: number;
16
+ rowNum: number;
17
+ }) {
18
+ const { resourceId, startDate, days, rowNum } = arg;
19
+
20
+ for (let i = 0; i < days; i++) {
21
+ const date = new Date(startDate);
22
+ date.setDate(date.getDate() + i);
23
+ const key = this.generateKey(date);
24
+ if (!this.record[resourceId]) {
25
+ this.record[resourceId] = {};
26
+ }
27
+ if (!this.record[resourceId][key]) {
28
+ this.record[resourceId][key] = [];
29
+ }
30
+ this.record[resourceId][key]?.push(rowNum);
31
+ }
32
+ }
33
+
34
+ public getMaxRowNum(arg: { resourceId: string; date: Date }): number {
35
+ const { resourceId, date } = arg;
36
+ const key = this.generateKey(date);
37
+ const resourceRecord = this.record[resourceId];
38
+ if (!resourceRecord) {
39
+ return 0;
40
+ }
41
+
42
+ const indexes = resourceRecord[key];
43
+
44
+ if (indexes === undefined || indexes.length === 0) {
45
+ return 0;
46
+ }
47
+
48
+ return Math.max(...indexes);
49
+ }
50
+
51
+ public getRowNums(arg: { resourceId: string; date: Date }): number[] {
52
+ const { resourceId, date } = arg;
53
+ const key = this.generateKey(date);
54
+ const resourceRecord = this.record[resourceId];
55
+ if (!resourceRecord) {
56
+ return [];
57
+ }
58
+ if (!resourceRecord[key]) {
59
+ return [];
60
+ }
61
+ return resourceRecord[key];
62
+ }
63
+
64
+ public reset(resourceId: string) {
65
+ this.record[resourceId] = {};
66
+ }
67
+ }
68
+ export default ResourcesCalendarEventPosition;