@flightlesslabs/dodo-ui 0.10.3 → 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 (44) hide show
  1. package/dist/index.d.ts +3 -3
  2. package/dist/index.js +2 -2
  3. package/dist/stories/components/Form/DatePicker/DatePicker.stories.svelte +16 -0
  4. package/dist/stories/components/Form/DatePicker/DatePicker.svelte +2 -1
  5. package/dist/stories/components/Form/DatePicker/DatePicker.svelte.d.ts +3 -1
  6. package/dist/stories/components/Form/DatePicker/Positions/AutoPosition/AutoPosition.stories.svelte +43 -0
  7. package/dist/stories/components/Form/DatePicker/Positions/AutoPosition/AutoPosition.stories.svelte.d.ts +18 -0
  8. package/dist/stories/components/Form/DatePicker/Positions/Positions.stories.svelte +54 -0
  9. package/dist/stories/components/Form/DatePicker/Positions/Positions.stories.svelte.d.ts +18 -0
  10. package/dist/stories/components/Info/Calendar/Calendar.stories.svelte +14 -0
  11. package/dist/stories/components/Info/Calendar/Calendar.svelte +2 -1
  12. package/dist/stories/components/Info/Calendar/Calendar.svelte.d.ts +3 -3
  13. package/dist/stories/components/Info/Calendar/SubComponents/CalendarDatesChart/CalendarDateChip/CalendarDateChip.svelte +2 -215
  14. package/dist/stories/components/Info/Calendar/SubComponents/CalendarDatesChart/CalendarDateChip/CalendarDateChip.svelte.d.ts +1 -7
  15. package/dist/stories/components/Info/Calendar/SubComponents/CalendarDatesChart/CalendarDateChip/utils/scss/mixins.scss +0 -46
  16. package/dist/stories/components/Info/Calendar/SubComponents/CalendarDatesChart/CalendarDatesChart.stories.svelte +14 -0
  17. package/dist/stories/components/Info/Calendar/SubComponents/CalendarDatesChart/CalendarDatesChart.svelte +3 -25
  18. package/dist/stories/components/Info/Calendar/SubComponents/CalendarDatesChart/CalendarDatesChart.svelte.d.ts +4 -5
  19. package/dist/stories/components/Info/Calendar/utils/createDateOfMonth/createDateOfMonth.d.ts +27 -0
  20. package/dist/stories/components/Info/Calendar/utils/createDateOfMonth/createDateOfMonth.js +72 -0
  21. package/dist/stories/components/Info/Calendar/utils/createDateOfMonth/index.mdx +121 -0
  22. package/dist/stories/components/Info/Calendar/utils/getDatesOfMonth/getDatesOfMonth.d.ts +10 -0
  23. package/dist/stories/components/Info/Calendar/utils/{getDatesOfMonth.js → getDatesOfMonth/getDatesOfMonth.js} +20 -13
  24. package/dist/stories/components/Info/Calendar/utils/getDatesOfMonth/index.mdx +37 -0
  25. package/dist/stories/components/Info/Calendar/utils/types.d.ts +0 -4
  26. package/dist/stories/developer tools/helpers/Time/getMoment/getMoment.d.ts +10 -11
  27. package/dist/stories/developer tools/helpers/Time/getMoment/getMoment.js +8 -8
  28. package/dist/stories/developer tools/helpers/Time/getMoment/index.mdx +31 -4
  29. package/package.json +3 -3
  30. package/src/lib/index.ts +3 -3
  31. package/src/lib/stories/components/Form/DatePicker/DatePicker.svelte +10 -0
  32. package/src/lib/stories/components/Info/Calendar/Calendar.svelte +8 -2
  33. package/src/lib/stories/components/Info/Calendar/SubComponents/CalendarDatesChart/CalendarDateChip/CalendarDateChip.svelte +2 -25
  34. package/src/lib/stories/components/Info/Calendar/SubComponents/CalendarDatesChart/CalendarDateChip/utils/scss/mixins.scss +0 -46
  35. package/src/lib/stories/components/Info/Calendar/SubComponents/CalendarDatesChart/CalendarDatesChart.svelte +23 -53
  36. package/src/lib/stories/components/Info/Calendar/utils/createDateOfMonth/createDateOfMonth.ts +120 -0
  37. package/src/lib/stories/components/Info/Calendar/utils/{getDatesOfMonth.ts → getDatesOfMonth/getDatesOfMonth.ts} +30 -16
  38. package/src/lib/stories/components/Info/Calendar/utils/types.ts +0 -5
  39. package/src/lib/stories/developer tools/helpers/Time/getMoment/getMoment.ts +11 -12
  40. package/dist/stories/components/Info/Calendar/utils/createDateOfMonth.d.ts +0 -28
  41. package/dist/stories/components/Info/Calendar/utils/createDateOfMonth.js +0 -87
  42. package/dist/stories/components/Info/Calendar/utils/getDatesOfMonth.d.ts +0 -10
  43. package/dist/stories/components/Info/Calendar/utils/index.mdx +0 -64
  44. package/src/lib/stories/components/Info/Calendar/utils/createDateOfMonth.ts +0 -160
package/src/lib/index.ts CHANGED
@@ -199,9 +199,9 @@ export { default as CalendarYearChip } from '$lib/stories/components/Info/Calend
199
199
 
200
200
  export type { DateOfMonth } from '$lib/stories/components/Info/Calendar/utils/types.js';
201
201
  export { DAYS_OF_WEEK, MONTHS } from '$lib/stories/components/Info/Calendar/utils/types.js';
202
- export { default as getDatesOfMonth } from '$lib/stories/components/Info/Calendar/utils/getDatesOfMonth.js';
203
- export { default as createDateOfMonth } from '$lib/stories/components/Info/Calendar/utils/createDateOfMonth.js';
202
+ export { default as getDatesOfMonth } from '$lib/stories/components/Info/Calendar/utils/getDatesOfMonth/getDatesOfMonth.js';
203
+ export { default as createDateOfMonth } from '$lib/stories/components/Info/Calendar/utils/createDateOfMonth/createDateOfMonth.js';
204
204
  export type {
205
205
  CreateDatesOfMonthSettings,
206
206
  CreateDateOfMonthType,
207
- } from '$lib/stories/components/Info/Calendar/utils/createDateOfMonth.js';
207
+ } from '$lib/stories/components/Info/Calendar/utils/createDateOfMonth/createDateOfMonth.js';
@@ -224,6 +224,12 @@
224
224
  calendarTopContent?: (activeSection: CalendarActiveSection) => Snippet;
225
225
  /** calendar Bottom Content*/
226
226
  calendarBottomContent?: (activeSection: CalendarActiveSection) => Snippet;
227
+
228
+ /** manipulate date callback */
229
+ manipulateDate?: (
230
+ dateToModify: DateOfMonth,
231
+ settings?: CreateDatesOfMonthSettings,
232
+ ) => DateOfMonth;
227
233
  }
228
234
  </script>
229
235
 
@@ -246,6 +252,7 @@
246
252
  type CalendarYearChipProps,
247
253
  type CalendarYearSelectorProps,
248
254
  type ComponentColor,
255
+ type CreateDatesOfMonthSettings,
249
256
  type DateOfMonth,
250
257
  type DynamicInputFocusEvent,
251
258
  type PaperProps,
@@ -364,6 +371,8 @@
364
371
  calendarProps,
365
372
  calendarTopContent,
366
373
  calendarBottomContent,
374
+
375
+ manipulateDate,
367
376
  }: DatePickerProps = $props();
368
377
 
369
378
  const formatEditable = $derived(formatEditableRaw || format);
@@ -656,6 +665,7 @@
656
665
  onselect={onselectMod}
657
666
  {calendarTopContent}
658
667
  {calendarBottomContent}
668
+ {manipulateDate}
659
669
  {...calendarProps}
660
670
  />
661
671
  </div>
@@ -137,8 +137,11 @@
137
137
  /** calendar Bottom Content*/
138
138
  calendarBottomContent?: (activeSection: CalendarActiveSection) => Snippet;
139
139
 
140
- /** Range value */
141
- rangeValue?: [Date, Date];
140
+ /** manipulate date callback */
141
+ manipulateDate?: (
142
+ dateToModify: DateOfMonth,
143
+ settings?: CreateDatesOfMonthSettings,
144
+ ) => DateOfMonth;
142
145
  }
143
146
  </script>
144
147
 
@@ -164,6 +167,7 @@
164
167
  MONTHS,
165
168
  type CalendarMonthChipProps,
166
169
  type CalendarYearChipProps,
170
+ type CreateDatesOfMonthSettings,
167
171
  } from '$lib/index.js';
168
172
  import CalendarMonthList from './SubComponents/CalendarMonthList/CalendarMonthList.svelte';
169
173
  import CalendarYearList from './SubComponents/CalendarYearList/CalendarYearList.svelte';
@@ -233,6 +237,7 @@
233
237
  showControlsYearList = true,
234
238
  calendarTopContent: calendarTopContentInternal,
235
239
  calendarBottomContent: calendarBottomContentInternal,
240
+ manipulateDate,
236
241
  }: CalendarProps = $props();
237
242
 
238
243
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -399,6 +404,7 @@
399
404
  {size}
400
405
  {weekendDays}
401
406
  {weekendDaysColorDays}
407
+ {manipulateDate}
402
408
  />
403
409
  {/snippet}
404
410
 
@@ -20,13 +20,6 @@
20
20
  selected?: boolean;
21
21
  /** onselect event handler */
22
22
  onselect?: (value: Date, dayOfMonth: DateOfMonth, e: ButtonClickEvent) => void;
23
- /** onselectRange event handler */
24
- onselectRange?: (
25
- value: Date,
26
- type: DateRangeType,
27
- dayOfMonth: DateOfMonth,
28
- e: ButtonClickEvent,
29
- ) => void;
30
23
  /** Custom Calendar Chip Content */
31
24
  customCalendarDateChipContent?: (dayOfMonth: DateOfMonth) => Snippet;
32
25
  /** Custom Calendar Chip Content */
@@ -39,11 +32,6 @@
39
32
  timezone?: string;
40
33
  /** Whether to return the time in UTC. If true, overrides timezone. */
41
34
  utc?: boolean;
42
-
43
- /** Show Value Range */
44
- showValueRange?: boolean;
45
- /** Date Range Type */
46
- rangeType?: DateRangeType;
47
35
  }
48
36
  </script>
49
37
 
@@ -55,7 +43,7 @@
55
43
  import type { Snippet } from 'svelte';
56
44
  import type { ButtonClickEvent } from '$lib/stories/components/Form/Button/Button.svelte';
57
45
  import type { ComponentSize } from '$lib/types/size.js';
58
- import type { DateOfMonth, DateRangeType } from '../../../utils/types.js';
46
+ import type { DateOfMonth } from '../../../utils/types.js';
59
47
 
60
48
  let {
61
49
  class: className = '',
@@ -70,21 +58,15 @@
70
58
  customCalendarDateChipContent: customCalendarDateChipContentInternal,
71
59
  customCalendarDateChip: customCalendarDateChipInternal,
72
60
  onselect,
73
- onselectRange,
74
61
  size = 'normal',
75
62
  weekend,
76
63
  timezone,
77
64
  utc,
78
- showValueRange = false,
79
- rangeType,
80
65
  }: CalendarDateChipProps = $props();
81
66
 
82
67
  const dayNumber = Number(getMoment(dayOfMonth.date, undefined, { timezone, utc }).format('D'));
83
68
  const disabled = dayOfMonth.disabled || false;
84
69
  const today = showToday && dayOfMonth.today ? true : false;
85
- const isRangeStart = rangeType === 'start' || false;
86
- const isRangeEnd = rangeType === 'end' || false;
87
- const inRange = dayOfMonth.inRange || false;
88
70
 
89
71
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
90
72
  let customCalendarDateChipContentTyped = customCalendarDateChipContentInternal as any;
@@ -93,9 +75,7 @@
93
75
  let customCalendarDateChipTyped = customCalendarDateChipInternal as any;
94
76
 
95
77
  function onselectMod(e: ButtonClickEvent) {
96
- if (showValueRange && onselectRange) {
97
- onselectRange(dayOfMonth.date, rangeType || 'start', dayOfMonth, e);
98
- } else if (onselect) {
78
+ if (onselect) {
99
79
  onselect(dayOfMonth.date, dayOfMonth, e);
100
80
  }
101
81
  }
@@ -121,9 +101,6 @@
121
101
  class:showNextMonth
122
102
  class:today
123
103
  class:selected
124
- class:isRangeStart
125
- class:isRangeEnd
126
- class:inRange
127
104
  class:weekend
128
105
  class={[
129
106
  'dodo-ui-CalendarDateChip',
@@ -56,22 +56,6 @@
56
56
  --dodo-ui-CalendarDateChip-selected-#{$color-name}-active-bg: var(
57
57
  --dodo-color-#{$color-name}-100
58
58
  );
59
-
60
- --dodo-ui-CalendarDateChip-isRangeStart-#{$color-name}-bg: var(--dodo-color-#{$color-name}-300);
61
- --dodo-ui-CalendarDateChip-isRangeStart-#{$color-name}-hover-bg: var(
62
- --dodo-color-#{$color-name}-200
63
- );
64
- --dodo-ui-CalendarDateChip-isRangeStart-#{$color-name}-active-bg: var(
65
- --dodo-color-#{$color-name}-100
66
- );
67
-
68
- --dodo-ui-CalendarDateChip-isRangeEnd-#{$color-name}-bg: var(--dodo-color-#{$color-name}-300);
69
- --dodo-ui-CalendarDateChip-isRangeEnd-#{$color-name}-hover-bg: var(
70
- --dodo-color-#{$color-name}-200
71
- );
72
- --dodo-ui-CalendarDateChip-isRangeEnd-#{$color-name}-active-bg: var(
73
- --dodo-color-#{$color-name}-100
74
- );
75
59
  }
76
60
 
77
61
  /// Mixin: generate-dodo-ui-calendarDateChip-color
@@ -119,35 +103,5 @@
119
103
  }
120
104
  }
121
105
  }
122
-
123
- &.isRangeStart {
124
- .chip:not([disabled]) {
125
- color: var(--dodo-color-constant-white);
126
- background-color: var(--dodo-ui-CalendarDateChip-isRangeStart-#{$theme}-bg);
127
-
128
- &:hover {
129
- background-color: var(--dodo-ui-CalendarDateChip-isRangeStart-#{$theme}-hover-bg);
130
- }
131
-
132
- &:active {
133
- background-color: var(--dodo-ui-CalendarDateChip-isRangeStart-#{$theme}-active-bg);
134
- }
135
- }
136
- }
137
-
138
- &.isRangeEnd {
139
- .chip:not([disabled]) {
140
- color: var(--dodo-color-constant-white);
141
- background-color: var(--dodo-ui-CalendarDateChip-isRangeEnd-#{$theme}-bg);
142
-
143
- &:hover {
144
- background-color: var(--dodo-ui-CalendarDateChip-isRangeEnd-#{$theme}-hover-bg);
145
- }
146
-
147
- &:active {
148
- background-color: var(--dodo-ui-CalendarDateChip-isRangeEnd-#{$theme}-active-bg);
149
- }
150
- }
151
- }
152
106
  }
153
107
  }
@@ -40,13 +40,6 @@
40
40
  includeDates?: Date[];
41
41
  /** onselect event handler */
42
42
  onselect?: (value: Date, dayOfMonth: DateOfMonth, e: ButtonClickEvent) => void;
43
- /** onselectRange event handler */
44
- onselectRange?: (
45
- value: Date,
46
- type: DateRangeType,
47
- dayOfMonth: DateOfMonth,
48
- e: ButtonClickEvent,
49
- ) => void;
50
43
  /** Custom Calendar Chip Content */
51
44
  customCalendarDateChipContent?: (dayOfMonth: DateOfMonth) => Snippet;
52
45
  /** Custom Calendar Chip */
@@ -64,8 +57,11 @@
64
57
  /** Color Weekend days */
65
58
  weekendDaysColorDays?: boolean;
66
59
 
67
- /** Range value */
68
- rangeValue?: [Date, Date];
60
+ /** manipulate date callback */
61
+ manipulateDate?: (
62
+ dateToModify: DateOfMonth,
63
+ settings?: CreateDatesOfMonthSettings,
64
+ ) => DateOfMonth;
69
65
  }
70
66
  </script>
71
67
 
@@ -73,8 +69,7 @@
73
69
  import getMoment from '$lib/stories/developer tools/helpers/Time/getMoment/getMoment.js';
74
70
  import type { ComponentColor } from '$lib/types/colors.js';
75
71
  import type { Snippet } from 'svelte';
76
- import getDatesOfMonth from '../../utils/getDatesOfMonth.js';
77
- import type { DateOfMonth, DateRangeType } from '../../utils/types.js';
72
+ import type { DateOfMonth } from '../../utils/types.js';
78
73
  import CalendarDateChip, {
79
74
  type CalendarDateChipProps,
80
75
  } from './CalendarDateChip/CalendarDateChip.svelte';
@@ -85,6 +80,8 @@
85
80
  CalendarWeekNames,
86
81
  } from './CalendarWeek/CalendarWeek.svelte';
87
82
  import type { ComponentSize } from '$lib/types/size.js';
83
+ import { getDatesOfMonth } from '$lib/index.js';
84
+ import type { CreateDatesOfMonthSettings } from '../../utils/createDateOfMonth/createDateOfMonth.js';
88
85
 
89
86
  let {
90
87
  class: className = '',
@@ -114,52 +111,28 @@
114
111
  size = 'normal',
115
112
  weekendDays,
116
113
  weekendDaysColorDays = true,
117
- rangeValue,
118
- onselectRange,
114
+ manipulateDate,
119
115
  }: CalendarDatesChartProps = $props();
120
116
 
121
117
  let monthToPick = $state<Date | undefined>(undefined);
122
118
 
123
119
  const daysGroup = $derived(
124
- getDatesOfMonth(monthToPick, {
125
- startOfWeek,
126
- timezone,
127
- utc,
128
- today,
129
- minDate,
130
- maxDate,
131
- excludeDates,
132
- includeDates,
133
- rangeValue,
134
- }) || [],
120
+ getDatesOfMonth(
121
+ monthToPick,
122
+ {
123
+ startOfWeek,
124
+ timezone,
125
+ utc,
126
+ today,
127
+ minDate,
128
+ maxDate,
129
+ excludeDates,
130
+ includeDates,
131
+ },
132
+ manipulateDate,
133
+ ) || [],
135
134
  );
136
135
 
137
- function getRangeType(day: DateOfMonth, rangeValue?: [Date, Date]): DateRangeType | undefined {
138
- if (!rangeValue) {
139
- return undefined;
140
- }
141
-
142
- const [range1, range2] = rangeValue;
143
-
144
- if (!range1 || !range2) {
145
- return undefined;
146
- }
147
-
148
- if (
149
- getMoment(range1, undefined, { timezone, utc }).format('MMM YYYY') ===
150
- getMoment(day.date, undefined, { timezone, utc }).format('DD-MM-YYY')
151
- ) {
152
- return 'start';
153
- } else if (
154
- getMoment(range2, undefined, { timezone, utc }).format('MMM YYYY') ===
155
- getMoment(day.date, undefined, { timezone, utc }).format('DD-MM-YYY')
156
- ) {
157
- return 'end';
158
- }
159
-
160
- return undefined;
161
- }
162
-
163
136
  $effect(() => {
164
137
  if (!value) {
165
138
  monthToPick = activeMonth;
@@ -218,9 +191,6 @@
218
191
  )
219
192
  ? true
220
193
  : false}
221
- showValueRange={rangeValue ? true : false}
222
- rangeType={getRangeType(day, rangeValue)}
223
- {onselectRange}
224
194
  {...calendarDateChipProps}
225
195
  />
226
196
  {/each}
@@ -0,0 +1,120 @@
1
+ import getMoment from '$lib/stories/developer tools/helpers/Time/getMoment/getMoment.js';
2
+ import type dayjs from 'dayjs';
3
+ import type { DateOfMonth } from '../types.js';
4
+ import type { CalendarWeekNames } from '$lib/index.js';
5
+
6
+ /** Settings for generating calendar dates */
7
+ export interface CreateDatesOfMonthSettings {
8
+ startOfWeek?: CalendarWeekNames;
9
+ showLastMonth?: boolean;
10
+ showNextMonth?: boolean;
11
+ today?: Date;
12
+ minDate?: Date;
13
+ maxDate?: Date;
14
+ excludeDates?: Date[];
15
+ includeDates?: Date[];
16
+ timezone?: string;
17
+ utc?: boolean;
18
+ }
19
+
20
+ export type CreateDateOfMonthType = 'currentMonth' | 'nextMonth' | 'lastMonth';
21
+
22
+ /**
23
+ * Creates a moment object from a Date with optional timezone and UTC settings.
24
+ */
25
+ function dateMoment(
26
+ date?: Date,
27
+ settings?: CreateDatesOfMonthSettings,
28
+ ): ReturnType<typeof getMoment> {
29
+ return getMoment(date, undefined, {
30
+ timezone: settings?.timezone,
31
+ utc: settings?.utc,
32
+ });
33
+ }
34
+
35
+ /**
36
+ * Determines if the given day matches "today" (manual or actual).
37
+ */
38
+ function getIsToday(dayMoment: dayjs.Dayjs, todayDate: string, todayManual?: string): boolean {
39
+ const dayDateFormat = dayMoment.format('DD-MM-YYYY');
40
+ return todayManual === dayDateFormat || todayDate === dayDateFormat;
41
+ }
42
+
43
+ /**
44
+ * Determines if a date should be disabled based on limits and included/excluded lists.
45
+ */
46
+ function getIsDateDisabled(
47
+ dayMoment: dayjs.Dayjs,
48
+ minDate?: dayjs.Dayjs,
49
+ maxDate?: dayjs.Dayjs,
50
+ excludeDates?: string[],
51
+ includeDates?: string[],
52
+ ): boolean {
53
+ const dayDateFormat = dayMoment.format('DD-MM-YYYY');
54
+
55
+ if (minDate?.isValid() && dayMoment.isBefore(minDate)) return true;
56
+ if (maxDate?.isValid() && dayMoment.isAfter(maxDate)) return true;
57
+ if (excludeDates?.includes(dayDateFormat)) return true;
58
+ if (includeDates && !includeDates.includes(dayDateFormat)) return true;
59
+
60
+ return false;
61
+ }
62
+
63
+ /**
64
+ * Generates a DateOfMonth object with metadata for a specific day, including
65
+ * whether it's part of the current month, disabled, or today.
66
+ *
67
+ * @param date - The day to convert.
68
+ * @param settings - Optional configuration settings.
69
+ * @param monthType - Specifies if the day belongs to the current, previous, or next month.
70
+ * @param manipulateDate - Optional function to customize the resulting date object.
71
+ * @returns A DateOfMonth object representing the day.
72
+ */
73
+ export default function createDateOfMonth(
74
+ date?: Date,
75
+ settings?: CreateDatesOfMonthSettings,
76
+ monthType: CreateDateOfMonthType = 'currentMonth',
77
+ manipulateDate?: (
78
+ dateToModify: DateOfMonth,
79
+ settings?: CreateDatesOfMonthSettings,
80
+ ) => DateOfMonth,
81
+ ): DateOfMonth {
82
+ const minDate = settings?.minDate ? dateMoment(settings.minDate, settings) : undefined;
83
+ const maxDate = settings?.maxDate ? dateMoment(settings.maxDate, settings) : undefined;
84
+
85
+ const excludeDates = settings?.excludeDates?.map((item) =>
86
+ dateMoment(item, settings).format('DD-MM-YYYY'),
87
+ );
88
+ const includeDates = settings?.includeDates?.map((item) =>
89
+ dateMoment(item, settings).format('DD-MM-YYYY'),
90
+ );
91
+
92
+ const todayDate = dateMoment(undefined, settings).format('DD-MM-YYYY');
93
+ const todayManual = settings?.today
94
+ ? dateMoment(settings.today, settings).format('DD-MM-YYYY')
95
+ : undefined;
96
+
97
+ const dayMoment = dateMoment(date, settings);
98
+
99
+ let dataToExport: DateOfMonth = {
100
+ id: `${dayMoment.valueOf()}`,
101
+ date: dayMoment.toDate(),
102
+ isCurrentMonth: true,
103
+ disabled: getIsDateDisabled(dayMoment, minDate, maxDate, excludeDates, includeDates),
104
+ today: getIsToday(dayMoment, todayDate, todayManual),
105
+ };
106
+
107
+ if (monthType === 'lastMonth') {
108
+ dataToExport.isLastMonth = true;
109
+ dataToExport.isCurrentMonth = false;
110
+ } else if (monthType === 'nextMonth') {
111
+ dataToExport.isNextMonth = true;
112
+ dataToExport.isCurrentMonth = false;
113
+ }
114
+
115
+ if (manipulateDate) {
116
+ dataToExport = manipulateDate(dataToExport, settings);
117
+ }
118
+
119
+ return dataToExport;
120
+ }
@@ -1,16 +1,18 @@
1
1
  import getMoment from '$lib/stories/developer tools/helpers/Time/getMoment/getMoment.js';
2
-
3
- import type { DateOfMonth } from './types.js';
4
- import { calendarWeekOptions } from '$lib/index.js';
5
- import createDateOfMonth, { type CreateDatesOfMonthSettings } from './createDateOfMonth.js';
2
+ import {
3
+ calendarWeekOptions,
4
+ createDateOfMonth,
5
+ type CreateDatesOfMonthSettings,
6
+ type DateOfMonth,
7
+ } from '$lib/index.js';
6
8
 
7
9
  /**
8
10
  * Divides an array into chunks of a given size.
9
11
  *
10
12
  * @template T - The type of elements in the array.
11
- * @param {T[]} arr - The array to be chunked.
12
- * @param {number} size - The chunk size.
13
- * @returns {T[][]} - An array of chunks.
13
+ * @param arr - The array to be chunked.
14
+ * @param size - The chunk size.
15
+ * @returns An array of chunks.
14
16
  */
15
17
  function chunkArray<T>(arr: T[], size: number): T[][] {
16
18
  const result: T[][] = [];
@@ -20,6 +22,13 @@ function chunkArray<T>(arr: T[], size: number): T[][] {
20
22
  return result;
21
23
  }
22
24
 
25
+ /**
26
+ * Creates a moment object from a Date with optional timezone and UTC settings.
27
+ *
28
+ * @param date - The date to convert.
29
+ * @param settings - Optional settings for timezone and UTC.
30
+ * @returns A moment object with the applied settings.
31
+ */
23
32
  function dateMoment(date?: Date, settings?: CreateDatesOfMonthSettings) {
24
33
  return getMoment(date, undefined, {
25
34
  timezone: settings?.timezone,
@@ -30,13 +39,18 @@ function dateMoment(date?: Date, settings?: CreateDatesOfMonthSettings) {
30
39
  /**
31
40
  * Generates a calendar grid of dates for a given month.
32
41
  *
33
- * @param {Date} date - The base date for the month to generate.
34
- * @param {GetDatesOfMonthSettings} [settings] - Optional settings for formatting and display.
35
- * @returns {(DateOfMonth[][] | null)} - A 2D array of DateOfMonth objects representing the calendar, or null if invalid.
42
+ * @param date - The base date for the month to generate.
43
+ * @param settings - Optional settings for formatting and display.
44
+ * @param manipulateDate - Optional function to modify each generated DateOfMonth.
45
+ * @returns A 2D array of DateOfMonth objects representing the calendar, or null if invalid.
36
46
  */
37
47
  export default function getDatesOfMonth(
38
48
  date?: Date,
39
49
  settings?: CreateDatesOfMonthSettings,
50
+ manipulateDate?: (
51
+ dateToModify: DateOfMonth,
52
+ settings?: CreateDatesOfMonthSettings,
53
+ ) => DateOfMonth,
40
54
  ): DateOfMonth[][] | null {
41
55
  if (!date) {
42
56
  return null;
@@ -54,6 +68,7 @@ export default function getDatesOfMonth(
54
68
  const startOfWeek =
55
69
  calendarWeekOptions.find((item) => item.abr3 === settings?.startOfWeek) ||
56
70
  calendarWeekOptions[0];
71
+
57
72
  const rawStartOfMonthDay = monthMoment.day();
58
73
  const startOfMonthDay = (rawStartOfMonthDay - startOfWeek.value + 7) % 7;
59
74
 
@@ -66,15 +81,13 @@ export default function getDatesOfMonth(
66
81
  if (showLastMonth) {
67
82
  for (let gap = 0; gap < startOfMonthDay; gap++) {
68
83
  const dayMoment = lastMonth.clone().add(gap, 'days');
69
-
70
- dates.push(createDateOfMonth(dayMoment.toDate(), settings, 'lastMonth'));
84
+ dates.push(createDateOfMonth(dayMoment.toDate(), settings, 'lastMonth', manipulateDate));
71
85
  }
72
86
  }
73
87
 
74
88
  for (let day = 1; day <= daysInMonth; day++) {
75
89
  const dayMoment = monthMoment.clone().set('date', day);
76
-
77
- dates.push(createDateOfMonth(dayMoment.toDate(), settings, 'currentMonth'));
90
+ dates.push(createDateOfMonth(dayMoment.toDate(), settings, 'currentMonth', manipulateDate));
78
91
  }
79
92
 
80
93
  const datesDivided = chunkArray<DateOfMonth>(dates, 7);
@@ -88,8 +101,9 @@ export default function getDatesOfMonth(
88
101
 
89
102
  for (let gap = 0; gap < nextMonthDaysRequired; gap++) {
90
103
  const dayMoment = nextMonth.clone().add(gap, 'days');
91
-
92
- nextMonthDates.push(createDateOfMonth(dayMoment.toDate(), settings, 'nextMonth'));
104
+ nextMonthDates.push(
105
+ createDateOfMonth(dayMoment.toDate(), settings, 'nextMonth', manipulateDate),
106
+ );
93
107
  }
94
108
 
95
109
  datesDivided[datesDivided.length - 1] = [...lastRow, ...nextMonthDates];
@@ -31,9 +31,4 @@ export type DateOfMonth = {
31
31
  isNextMonth?: boolean;
32
32
  disabled?: boolean;
33
33
  today?: boolean;
34
- isRangeStart?: boolean;
35
- isRangeEnd?: boolean;
36
- inRange?: boolean;
37
34
  };
38
-
39
- export type DateRangeType = 'start' | 'end';
@@ -1,5 +1,5 @@
1
1
  import type { ConfigType, OptionType } from 'dayjs';
2
- import dayjs from 'dayjs';
2
+ import dayjs, { Dayjs } from 'dayjs';
3
3
  import utc from 'dayjs/plugin/utc.js';
4
4
  import timezone from 'dayjs/plugin/timezone.js';
5
5
  import customParseFormat from 'dayjs/plugin/customParseFormat.js';
@@ -15,14 +15,13 @@ export type GetMomentDate = ConfigType;
15
15
 
16
16
  /**
17
17
  * Optional formatting string used to parse the date.
18
- * Refer to dayjs customParseFormat plugin for supported formats.
19
18
  */
20
19
  export type GetMomentFormat = OptionType;
21
20
 
22
21
  /**
23
22
  * Settings to control how the moment is returned (UTC, timezone, or local).
24
23
  */
25
- export type GetMomentSettings = {
24
+ export interface GetMomentSettings {
26
25
  /**
27
26
  * Timezone string (e.g., "America/New_York").
28
27
  */
@@ -32,28 +31,28 @@ export type GetMomentSettings = {
32
31
  * Whether to return the time in UTC. If true, overrides timezone.
33
32
  */
34
33
  utc?: boolean;
35
- };
34
+ }
36
35
 
37
36
  /**
38
37
  * A wrapper around dayjs to return a moment-like object with optional formatting,
39
38
  * timezone, or UTC handling.
40
39
  *
41
- * @param {GetMomentDate} [date] - The input date, time, or string to be parsed.
42
- * @param {format} [format] - A custom format string for parsing the input date.
43
- * @param {GetMomentSettings} [settings] - Optional settings for format, timezone, and UTC.
44
- * @returns {dayjs.Dayjs} - A dayjs object in local, UTC, or specified timezone.
40
+ * @param date - The input date, time, or string to be parsed.
41
+ * @param format - A custom format string for parsing the input date.
42
+ * @param settings - Optional settings for timezone or UTC output.
43
+ * @returns A dayjs object in local, UTC, or specified timezone.
45
44
  *
46
45
  * @example
47
- * getMoment('2025-01-01T12:00:00Z', { utc: true }).format()
48
- * getMoment('01-01-2025', { format: 'DD-MM-YYYY', timezone: 'Asia/Kolkata' }).format()
46
+ * getMoment('2025-01-01T12:00:00Z', undefined, { utc: true }).format()
47
+ * getMoment('01-01-2025', 'DD-MM-YYYY', { timezone: 'Asia/Kolkata' }).format()
49
48
  */
50
49
  export default function getMoment(
51
50
  date?: GetMomentDate,
52
51
  format?: GetMomentFormat,
53
52
  settings?: GetMomentSettings,
54
- ): dayjs.Dayjs {
53
+ ): Dayjs {
55
54
  const timezone = settings?.timezone;
56
- const utc = settings?.utc ? true : false;
55
+ const utc = settings?.utc ?? false;
57
56
 
58
57
  if (utc) {
59
58
  return dayjs.utc(dayjs(date, format));
@@ -1,28 +0,0 @@
1
- import type { DateOfMonth } from './types.js';
2
- import type { CalendarWeekNames } from '../SubComponents/CalendarDatesChart/CalendarWeek/CalendarWeek.svelte';
3
- export interface CreateDatesOfMonthSettings {
4
- /** Day considered as start of the week */
5
- startOfWeek?: CalendarWeekNames;
6
- /** Include leading days from the previous month */
7
- showLastMonth?: boolean;
8
- /** Include trailing days from the next month */
9
- showNextMonth?: boolean;
10
- /** Set today manually */
11
- today?: Date;
12
- /** Minimum allowed date, rest of the dates will be disabled */
13
- minDate?: Date;
14
- /** Maxium allowed date, rest of the dates will be disabled */
15
- maxDate?: Date;
16
- /** Exclude Dates, these dates will be disabled */
17
- excludeDates?: Date[];
18
- /** Include Dates, rest of the dates will be disabled */
19
- includeDates?: Date[];
20
- /** Optional IANA timezone */
21
- timezone?: string;
22
- /** Use UTC time */
23
- utc?: boolean;
24
- /** Range value */
25
- rangeValue?: [Date, Date];
26
- }
27
- export type CreateDateOfMonthType = 'currentMonth' | 'nextMonth' | 'lastMonth';
28
- export default function createDateOfMonth(date?: Date, settings?: CreateDatesOfMonthSettings, monthType?: CreateDateOfMonthType): DateOfMonth;