@webamoki/web-svelte 0.7.4 → 1.0.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.
- package/README.md +83 -3
- package/dist/components/form/Button.svelte +24 -23
- package/dist/components/form/Button.svelte.d.ts +2 -2
- package/dist/components/form/Errors.svelte +13 -13
- package/dist/components/form/FieldWrapper.svelte +57 -55
- package/dist/components/form/FieldWrapper.svelte.d.ts +4 -4
- package/dist/components/form/Form.svelte +18 -14
- package/dist/components/form/Form.svelte.d.ts +31 -22
- package/dist/components/form/IconInputWrapper.svelte +30 -29
- package/dist/components/form/IconInputWrapper.svelte.d.ts +7 -7
- package/dist/components/form/fields/ChoiceField.svelte +45 -43
- package/dist/components/form/fields/ChoiceField.svelte.d.ts +28 -23
- package/dist/components/form/fields/ChoiceMultiField.svelte +44 -42
- package/dist/components/form/fields/ChoiceMultiField.svelte.d.ts +28 -23
- package/dist/components/form/fields/DateField.svelte +42 -40
- package/dist/components/form/fields/DateField.svelte.d.ts +29 -22
- package/dist/components/form/fields/HexColorField.svelte +21 -19
- package/dist/components/form/fields/HexColorField.svelte.d.ts +24 -19
- package/dist/components/form/fields/MessageField.svelte +39 -60
- package/dist/components/form/fields/MessageField.svelte.d.ts +33 -24
- package/dist/components/form/fields/NumberField.svelte +38 -36
- package/dist/components/form/fields/NumberField.svelte.d.ts +32 -23
- package/dist/components/form/fields/PasswordField.svelte +45 -39
- package/dist/components/form/fields/PasswordField.svelte.d.ts +28 -21
- package/dist/components/form/fields/SelectField.svelte +84 -79
- package/dist/components/form/fields/SelectField.svelte.d.ts +39 -26
- package/dist/components/form/fields/SelectMultiField.svelte +90 -85
- package/dist/components/form/fields/SelectMultiField.svelte.d.ts +38 -25
- package/dist/components/form/fields/TextField.svelte +31 -29
- package/dist/components/form/fields/TextField.svelte.d.ts +32 -23
- package/dist/components/form/fields/TextFieldNullable.svelte +49 -47
- package/dist/components/form/fields/TextFieldNullable.svelte.d.ts +32 -23
- package/dist/components/form/fields/TimeField.svelte +66 -64
- package/dist/components/form/fields/TimeField.svelte.d.ts +33 -24
- package/dist/components/form/fields/WeekdayChoiceField.svelte +37 -35
- package/dist/components/form/fields/WeekdayChoiceField.svelte.d.ts +27 -22
- package/dist/components/form/fields/WeekdayChoiceMultiField.svelte +37 -35
- package/dist/components/form/fields/WeekdayChoiceMultiField.svelte.d.ts +27 -22
- package/dist/components/showcase/CodeBlock.svelte +41 -41
- package/dist/components/showcase/Container.svelte +7 -7
- package/dist/components/showcase/Preview.svelte +4 -4
- package/dist/components/showcase/Sidebar.svelte +4 -4
- package/dist/components/showcase/SidebarLink.svelte +3 -3
- package/dist/components/ui/choice/Choice.svelte +25 -22
- package/dist/components/ui/choice/Choice.svelte.d.ts +7 -7
- package/dist/components/ui/choice/ChoiceInternal.svelte +73 -69
- package/dist/components/ui/choice/ChoiceInternal.svelte.d.ts +9 -9
- package/dist/components/ui/choice/ChoiceMulti.svelte +59 -53
- package/dist/components/ui/choice/ChoiceMulti.svelte.d.ts +7 -7
- package/dist/components/ui/choice/WeekdayChoice.svelte +22 -21
- package/dist/components/ui/choice/WeekdayChoice.svelte.d.ts +6 -6
- package/dist/components/ui/choice/WeekdayChoiceMulti.svelte +24 -22
- package/dist/components/ui/choice/WeekdayChoiceMulti.svelte.d.ts +6 -6
- package/dist/components/ui/context-menu/ContextMenu.svelte +51 -50
- package/dist/components/ui/context-menu/ContextMenu.svelte.d.ts +1 -1
- package/dist/components/ui/context-menu/ContextMenuContent.svelte +92 -91
- package/dist/components/ui/context-menu/ContextMenuItem.svelte +26 -25
- package/dist/components/ui/context-menu/ContextMenuItem.svelte.d.ts +1 -1
- package/dist/components/ui/context-menu/ContextMenuTrigger.svelte +16 -15
- package/dist/components/ui/context-menu/context-menu-state.svelte.d.ts +3 -3
- package/dist/components/ui/context-menu/context-menu-state.svelte.js +15 -15
- package/dist/components/ui/drag-drop/Draggable.svelte +73 -72
- package/dist/components/ui/drag-drop/Draggable.svelte.d.ts +2 -2
- package/dist/components/ui/drag-drop/Dropzone.svelte +56 -54
- package/dist/components/ui/drag-drop/Dropzone.svelte.d.ts +3 -3
- package/dist/components/ui/drag-drop/drag-manager.d.ts +2 -2
- package/dist/components/ui/drag-drop/drag-manager.js +9 -9
- package/dist/components/ui/index.d.ts +2 -2
- package/dist/components/ui/index.js +5 -5
- package/dist/components/ui/search/SearchBar.svelte +18 -18
- package/dist/components/ui/search/SearchBar.svelte.d.ts +2 -2
- package/dist/highlight.js +2 -2
- package/dist/server/form-handler.d.ts +12 -12
- package/dist/server/form-handler.js +17 -17
- package/dist/server/form-processor.d.ts +1 -1
- package/dist/server/form-processor.js +0 -1
- package/dist/shadcn/components/ui/button/button.svelte +72 -71
- package/dist/shadcn/components/ui/button/button.svelte.d.ts +23 -23
- package/dist/shadcn/components/ui/button/index.d.ts +1 -1
- package/dist/shadcn/components/ui/button/index.js +2 -2
- package/dist/shadcn/components/ui/input/index.d.ts +1 -1
- package/dist/shadcn/components/ui/input/index.js +2 -2
- package/dist/shadcn/components/ui/input/input.svelte +35 -32
- package/dist/shadcn/components/ui/input/input.svelte.d.ts +2 -2
- package/dist/shadcn/components/ui/select/index.d.ts +6 -6
- package/dist/shadcn/components/ui/select/index.js +7 -7
- package/dist/shadcn/components/ui/select/select-content.svelte +35 -34
- package/dist/shadcn/components/ui/select/select-content.svelte.d.ts +1 -1
- package/dist/shadcn/components/ui/select/select-group-heading.svelte +15 -14
- package/dist/shadcn/components/ui/select/select-group.svelte +2 -2
- package/dist/shadcn/components/ui/select/select-item.svelte +31 -31
- package/dist/shadcn/components/ui/select/select-label.svelte +14 -13
- package/dist/shadcn/components/ui/select/select-label.svelte.d.ts +1 -1
- package/dist/shadcn/components/ui/select/select-scroll-down-button.svelte +13 -13
- package/dist/shadcn/components/ui/select/select-scroll-up-button.svelte +13 -13
- package/dist/shadcn/components/ui/select/select-separator.svelte +13 -12
- package/dist/shadcn/components/ui/select/select-trigger.svelte +26 -26
- package/dist/shadcn/components/ui/select/select-trigger.svelte.d.ts +2 -2
- package/dist/shadcn/components/ui/separator/separator.svelte +14 -14
- package/dist/shadcn/components/ui/textarea/textarea.svelte +22 -21
- package/dist/shadcn/components/ui/textarea/textarea.svelte.d.ts +1 -1
- package/dist/shadcn/utils.d.ts +4 -4
- package/dist/utils/datetime/index.d.ts +68 -68
- package/dist/utils/datetime/index.js +124 -124
- package/dist/utils/email/README.md +60 -60
- package/dist/utils/email/aws-signer.d.ts +1 -1
- package/dist/utils/email/aws-signer.js +39 -39
- package/dist/utils/email/ses.d.ts +8 -10
- package/dist/utils/email/ses.js +15 -23
- package/dist/utils/form/index.d.ts +11 -11
- package/dist/utils/form/index.js +23 -24
- package/dist/utils/form/virtual-form.d.ts +5 -5
- package/dist/utils/form/virtual-form.js +58 -58
- package/dist/utils/search.d.ts +1 -1
- package/dist/utils/search.js +22 -22
- package/dist/utils/types/arktype.d.ts +2 -2
- package/dist/utils/types/arktype.js +3 -3
- package/dist/utils/types/db.d.ts +2 -1
- package/dist/utils/types/db.js +7 -7
- package/package.json +69 -54
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
|
|
3
|
-
import type { HTMLTextareaAttributes } from 'svelte/elements';
|
|
2
|
+
import type { HTMLTextareaAttributes } from 'svelte/elements';
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
import { cn, type WithElementRef, type WithoutChildren } from '../../../utils.js';
|
|
5
|
+
|
|
6
|
+
let {
|
|
7
|
+
class: className,
|
|
8
|
+
'data-slot': dataSlot = 'textarea',
|
|
9
|
+
ref = $bindable(null),
|
|
10
|
+
value = $bindable(),
|
|
11
|
+
...restProps
|
|
12
|
+
}: WithoutChildren<WithElementRef<HTMLTextareaAttributes>> = $props();
|
|
12
13
|
</script>
|
|
13
14
|
|
|
14
15
|
<textarea
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
16
|
+
bind:this={ref}
|
|
17
|
+
class={cn(
|
|
18
|
+
'w-full resize-y rounded-lg border border-gray-300 px-4 py-3 outline-none',
|
|
19
|
+
'transition-[border-color,box-shadow,opacity]',
|
|
20
|
+
'focus:border-transparent focus:ring-2 focus:ring-primary',
|
|
21
|
+
'disabled:cursor-not-allowed disabled:opacity-50',
|
|
22
|
+
'aria-invalid:border-red-500 aria-invalid:focus:ring-red-300',
|
|
23
|
+
className
|
|
24
|
+
)}
|
|
25
|
+
data-slot={dataSlot}
|
|
26
|
+
bind:value
|
|
27
|
+
{...restProps}
|
|
27
28
|
></textarea>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type WithElementRef } from '../../../utils.js';
|
|
2
1
|
import type { HTMLTextareaAttributes } from 'svelte/elements';
|
|
2
|
+
import { type WithElementRef } from '../../../utils.js';
|
|
3
3
|
declare const Textarea: import("svelte").Component<Omit<WithElementRef<HTMLTextareaAttributes>, "children">, {}, "ref" | "value">;
|
|
4
4
|
type Textarea = ReturnType<typeof Textarea>;
|
|
5
5
|
export default Textarea;
|
package/dist/shadcn/utils.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { type ClassValue } from 'clsx';
|
|
2
|
-
export
|
|
2
|
+
export type WithElementRef<T, U extends HTMLElement = HTMLElement> = T & {
|
|
3
|
+
ref?: null | U;
|
|
4
|
+
};
|
|
3
5
|
export type WithoutChild<T> = T extends {
|
|
4
6
|
child?: any;
|
|
5
7
|
} ? Omit<T, 'child'> : T;
|
|
@@ -7,6 +9,4 @@ export type WithoutChildren<T> = T extends {
|
|
|
7
9
|
children?: any;
|
|
8
10
|
} ? Omit<T, 'children'> : T;
|
|
9
11
|
export type WithoutChildrenOrChild<T> = WithoutChildren<WithoutChild<T>>;
|
|
10
|
-
export
|
|
11
|
-
ref?: U | null;
|
|
12
|
-
};
|
|
12
|
+
export declare function cn(...inputs: ClassValue[]): string;
|
|
@@ -1,29 +1,8 @@
|
|
|
1
|
-
import { CalendarDate, Time, ZonedDateTime, type DateDuration } from '@internationalized/date';
|
|
2
1
|
import type { Transport } from '@sveltejs/kit';
|
|
2
|
+
import { CalendarDate, type DateDuration, Time, ZonedDateTime } from '@internationalized/date';
|
|
3
3
|
import type { Day } from '../types/arktype.js';
|
|
4
4
|
export declare const Days: readonly ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
|
|
5
5
|
export declare const DayIndex: Record<Day, number>;
|
|
6
|
-
/** Gets the day index of the date */
|
|
7
|
-
export declare function getDayIndex(date: CalendarDate): number;
|
|
8
|
-
/**
|
|
9
|
-
* Gets the day of the week for a given date.
|
|
10
|
-
* @param date - The date to get the day of the week for.
|
|
11
|
-
* @returns The day of the week
|
|
12
|
-
*/
|
|
13
|
-
export declare function getDayOfDate(date: CalendarDate): Day;
|
|
14
|
-
/**
|
|
15
|
-
* Checks if a given date is a specific day of the week.
|
|
16
|
-
* @param date - The date to check.
|
|
17
|
-
* @param dayOfWeek - The day of the week to check against.
|
|
18
|
-
* @returns True if the date is the specified day, false otherwise.
|
|
19
|
-
*/
|
|
20
|
-
export declare function isDateDay(date: CalendarDate, dayOfWeek: Day): boolean;
|
|
21
|
-
/**
|
|
22
|
-
* Checks if a given date is today.
|
|
23
|
-
* @param date - The date to check.
|
|
24
|
-
* @returns True if the date is today, false otherwise.
|
|
25
|
-
*/
|
|
26
|
-
export declare function isDateToday(date: CalendarDate, timezone: string): boolean;
|
|
27
6
|
/**
|
|
28
7
|
* Calculates the age from a date of birth.
|
|
29
8
|
* @param dob - The date of birth.
|
|
@@ -32,12 +11,30 @@ export declare function isDateToday(date: CalendarDate, timezone: string): boole
|
|
|
32
11
|
*/
|
|
33
12
|
export declare function ageFromDob(dob: CalendarDate, timezone: string): number;
|
|
34
13
|
/**
|
|
35
|
-
*
|
|
36
|
-
* @param
|
|
37
|
-
* @param
|
|
38
|
-
* @
|
|
14
|
+
* Checks if two time ranges overlap, boundaries are not considered overlapping.
|
|
15
|
+
* @param start1 - The start time of the first range.
|
|
16
|
+
* @param end1 - The end time of the first range.
|
|
17
|
+
* @param start2 - The start time of the second range.
|
|
18
|
+
* @param end2 - The end time of the second range.
|
|
19
|
+
* @returns True if the ranges overlap, false otherwise.
|
|
39
20
|
*/
|
|
40
|
-
export declare function
|
|
21
|
+
export declare function checkOverlap(start1: Time, end1: Time, start2: Time, end2: Time): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Determines if the given dates are within the given duration of each other.
|
|
24
|
+
* @param date1 - The first date in order.
|
|
25
|
+
* @param date2 - The second date in order.
|
|
26
|
+
* @param duration - The duration to check against. Inclusive of boundaries.
|
|
27
|
+
* @returns True if the dates are within duration, false otherwise.
|
|
28
|
+
*/
|
|
29
|
+
export declare function datesWithin(date1: CalendarDate, date2: CalendarDate, duration: DateDuration): boolean;
|
|
30
|
+
/** Gets the day index of the date */
|
|
31
|
+
export declare function getDayIndex(date: CalendarDate): number;
|
|
32
|
+
/**
|
|
33
|
+
* Gets the day of the week for a given date.
|
|
34
|
+
* @param date - The date to get the day of the week for.
|
|
35
|
+
* @returns The day of the week
|
|
36
|
+
*/
|
|
37
|
+
export declare function getDayOfDate(date: CalendarDate): Day;
|
|
41
38
|
/**
|
|
42
39
|
* Gets the most recent occurrence of a day of the week.
|
|
43
40
|
* @param dayOfWeek - The day of the week
|
|
@@ -63,22 +60,25 @@ export declare function getLastDatesOfDay(dayOfWeek: Day, count: number, startDa
|
|
|
63
60
|
*/
|
|
64
61
|
export declare function getLastMonths(count: number, startDate: CalendarDate): CalendarDate[];
|
|
65
62
|
/**
|
|
66
|
-
*
|
|
67
|
-
* @param
|
|
68
|
-
* @param
|
|
69
|
-
* @
|
|
70
|
-
* @param end2 - The end time of the second range.
|
|
71
|
-
* @returns True if the ranges overlap, false otherwise.
|
|
63
|
+
* Gets the date of the next occurrence of a day of the week.
|
|
64
|
+
* @param dayOfWeek - The day of the week to get the next occurrence for.
|
|
65
|
+
* @param startDate - The date to check from. Inclusive.
|
|
66
|
+
* @returns The date of the next occurrence of the specified day.
|
|
72
67
|
*/
|
|
73
|
-
export declare function
|
|
68
|
+
export declare function getNextDateOfDay(dayOfWeek: Day, startDate: CalendarDate): CalendarDate;
|
|
74
69
|
/**
|
|
75
|
-
*
|
|
76
|
-
* @param
|
|
77
|
-
* @param
|
|
78
|
-
* @
|
|
79
|
-
* @returns True if the dates are within duration, false otherwise.
|
|
70
|
+
* Checks if a given date is a specific day of the week.
|
|
71
|
+
* @param date - The date to check.
|
|
72
|
+
* @param dayOfWeek - The day of the week to check against.
|
|
73
|
+
* @returns True if the date is the specified day, false otherwise.
|
|
80
74
|
*/
|
|
81
|
-
export declare function
|
|
75
|
+
export declare function isDateDay(date: CalendarDate, dayOfWeek: Day): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Checks if a given date is today.
|
|
78
|
+
* @param date - The date to check.
|
|
79
|
+
* @returns True if the date is today, false otherwise.
|
|
80
|
+
*/
|
|
81
|
+
export declare function isDateToday(date: CalendarDate, timezone: string): boolean;
|
|
82
82
|
/**
|
|
83
83
|
* Calculates the difference in weeks between two dates.
|
|
84
84
|
* @param date1 - The first date in order.
|
|
@@ -88,23 +88,24 @@ export declare function dateDiffWeeks(date1: CalendarDate, date2: CalendarDate):
|
|
|
88
88
|
/**
|
|
89
89
|
* Formats a day of the week.
|
|
90
90
|
* @param day - The day of the week to format.
|
|
91
|
-
* @example "Monday" -> "
|
|
92
|
-
* @returns Formatted
|
|
91
|
+
* @example "Monday" -> "M"
|
|
92
|
+
* @returns Formatted letter of the day of the week.
|
|
93
93
|
*/
|
|
94
|
-
export declare function
|
|
94
|
+
export declare function formatDayLetter(day: Day): string;
|
|
95
95
|
/**
|
|
96
96
|
* Formats a day of the week.
|
|
97
97
|
* @param day - The day of the week to format.
|
|
98
|
-
* @example "Monday" -> "
|
|
99
|
-
* @returns Formatted
|
|
98
|
+
* @example "Monday" -> "Mon"
|
|
99
|
+
* @returns Formatted string of the day of the week.
|
|
100
100
|
*/
|
|
101
|
-
export declare function
|
|
101
|
+
export declare function formatDayShort(day: Day): string;
|
|
102
102
|
/**
|
|
103
|
-
*
|
|
104
|
-
* @
|
|
105
|
-
* @
|
|
103
|
+
* Formats a full date and time.
|
|
104
|
+
* @param datetime The ZonedDateTime object to format.
|
|
105
|
+
* @returns The formatted date and time string.
|
|
106
|
+
* @example "05/10/2023 14:30:00"
|
|
106
107
|
*/
|
|
107
|
-
export declare function
|
|
108
|
+
export declare function formatAbsolute(datetime: ZonedDateTime): string;
|
|
108
109
|
/**
|
|
109
110
|
* @param date The CalendarDate object to format.
|
|
110
111
|
* @returns The formatted date string.
|
|
@@ -124,6 +125,12 @@ export declare function formatDateISO(date: CalendarDate): string;
|
|
|
124
125
|
* @example "05/10/2023"
|
|
125
126
|
*/
|
|
126
127
|
export declare function formatDateNum(date: CalendarDate): string;
|
|
128
|
+
/**
|
|
129
|
+
* @param date The CalendarDate object to format.
|
|
130
|
+
* @returns string of date in shortened format
|
|
131
|
+
* @example "Oct 5"
|
|
132
|
+
*/
|
|
133
|
+
export declare function formatDateShort(date: CalendarDate): string;
|
|
127
134
|
/**
|
|
128
135
|
* Formats the month only.
|
|
129
136
|
* @param date - The date to format.
|
|
@@ -132,11 +139,12 @@ export declare function formatDateNum(date: CalendarDate): string;
|
|
|
132
139
|
*/
|
|
133
140
|
export declare function formatMonth(date: CalendarDate): string;
|
|
134
141
|
/**
|
|
135
|
-
*
|
|
136
|
-
* @param time
|
|
137
|
-
* @
|
|
142
|
+
* Calculates the end time given a starting time and duration.
|
|
143
|
+
* @param timeStart starting time
|
|
144
|
+
* @param durationMinutes duration in minutes
|
|
145
|
+
* @returns end time in HH:MM format
|
|
138
146
|
*/
|
|
139
|
-
export declare function
|
|
147
|
+
export declare function formatTimeEnd(timeStart: Time, durationMinutes: number): string;
|
|
140
148
|
/**
|
|
141
149
|
* Gives time in HH:MM:SS format
|
|
142
150
|
* @param time
|
|
@@ -144,29 +152,21 @@ export declare function formatTimeShort(time: Time): string;
|
|
|
144
152
|
*/
|
|
145
153
|
export declare function formatTimeFull(time: Time): string;
|
|
146
154
|
/**
|
|
147
|
-
*
|
|
148
|
-
* @param
|
|
149
|
-
* @
|
|
150
|
-
* @returns end time in HH:MM format
|
|
151
|
-
*/
|
|
152
|
-
export declare function formatTimeEnd(timeStart: Time, durationMinutes: number): string;
|
|
153
|
-
/**
|
|
154
|
-
* Formats a full date and time.
|
|
155
|
-
* @param datetime The ZonedDateTime object to format.
|
|
156
|
-
* @returns The formatted date and time string.
|
|
157
|
-
* @example "05/10/2023 14:30:00"
|
|
155
|
+
* Gives time in HH:MM format
|
|
156
|
+
* @param time
|
|
157
|
+
* @returns string of time in that format
|
|
158
158
|
*/
|
|
159
|
-
export declare function
|
|
159
|
+
export declare function formatTimeShort(time: Time): string;
|
|
160
160
|
/**
|
|
161
161
|
* Unfreezes a CalendarDate object from a snapshot.
|
|
162
162
|
* @param raw - The snapshot of the CalendarDate object.
|
|
163
163
|
* @returns The unfrozen CalendarDate object.
|
|
164
164
|
*/
|
|
165
|
-
export declare function unfreezeDate(raw: $state.
|
|
165
|
+
export declare function unfreezeDate(raw: ReturnType<typeof $state.snapshot<CalendarDate>>): CalendarDate;
|
|
166
166
|
/**
|
|
167
167
|
* Unfreezes a Time object from a snapshot.
|
|
168
168
|
* @param raw - The snapshot of the Time object.
|
|
169
169
|
* @returns The unfrozen Time object.
|
|
170
170
|
*/
|
|
171
|
-
export declare function unfreezeTime(raw: $state.
|
|
171
|
+
export declare function unfreezeTime(raw: ReturnType<typeof $state.snapshot<Time>>): Time;
|
|
172
172
|
export declare const dateTransport: Transport;
|
|
@@ -13,37 +13,6 @@ export const Days = [
|
|
|
13
13
|
'Sunday'
|
|
14
14
|
];
|
|
15
15
|
export const DayIndex = Object.fromEntries(Days.map((day, index) => [day, index]));
|
|
16
|
-
/** Gets the day index of the date */
|
|
17
|
-
export function getDayIndex(date) {
|
|
18
|
-
// Always start 0 on Monday
|
|
19
|
-
return getDayOfWeek(date, DEFAULT_LOCALE, 'mon');
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Gets the day of the week for a given date.
|
|
23
|
-
* @param date - The date to get the day of the week for.
|
|
24
|
-
* @returns The day of the week
|
|
25
|
-
*/
|
|
26
|
-
export function getDayOfDate(date) {
|
|
27
|
-
return Days[getDayIndex(date)];
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Checks if a given date is a specific day of the week.
|
|
31
|
-
* @param date - The date to check.
|
|
32
|
-
* @param dayOfWeek - The day of the week to check against.
|
|
33
|
-
* @returns True if the date is the specified day, false otherwise.
|
|
34
|
-
*/
|
|
35
|
-
export function isDateDay(date, dayOfWeek) {
|
|
36
|
-
const dateDay = getDayOfDate(date);
|
|
37
|
-
return dateDay === dayOfWeek;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Checks if a given date is today.
|
|
41
|
-
* @param date - The date to check.
|
|
42
|
-
* @returns True if the date is today, false otherwise.
|
|
43
|
-
*/
|
|
44
|
-
export function isDateToday(date, timezone) {
|
|
45
|
-
return today(timezone).compare(date) === 0;
|
|
46
|
-
}
|
|
47
16
|
/**
|
|
48
17
|
* Calculates the age from a date of birth.
|
|
49
18
|
* @param dob - The date of birth.
|
|
@@ -65,20 +34,41 @@ export function ageFromDob(dob, timezone) {
|
|
|
65
34
|
return years;
|
|
66
35
|
}
|
|
67
36
|
/**
|
|
68
|
-
*
|
|
69
|
-
* @param
|
|
70
|
-
* @param
|
|
71
|
-
* @
|
|
37
|
+
* Checks if two time ranges overlap, boundaries are not considered overlapping.
|
|
38
|
+
* @param start1 - The start time of the first range.
|
|
39
|
+
* @param end1 - The end time of the first range.
|
|
40
|
+
* @param start2 - The start time of the second range.
|
|
41
|
+
* @param end2 - The end time of the second range.
|
|
42
|
+
* @returns True if the ranges overlap, false otherwise.
|
|
72
43
|
*/
|
|
73
|
-
export function
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
44
|
+
export function checkOverlap(start1, end1, start2, end2) {
|
|
45
|
+
return start1.compare(end2) < 0 && start2.compare(end1) < 0;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Determines if the given dates are within the given duration of each other.
|
|
49
|
+
* @param date1 - The first date in order.
|
|
50
|
+
* @param date2 - The second date in order.
|
|
51
|
+
* @param duration - The duration to check against. Inclusive of boundaries.
|
|
52
|
+
* @returns True if the dates are within duration, false otherwise.
|
|
53
|
+
*/
|
|
54
|
+
export function datesWithin(date1, date2, duration) {
|
|
55
|
+
// reject invalid order
|
|
56
|
+
if (date1.compare(date2) > 0)
|
|
57
|
+
return false;
|
|
58
|
+
return date1.add(duration).compare(date2) >= 0;
|
|
59
|
+
}
|
|
60
|
+
/** Gets the day index of the date */
|
|
61
|
+
export function getDayIndex(date) {
|
|
62
|
+
// Always start 0 on Monday
|
|
63
|
+
return getDayOfWeek(date, DEFAULT_LOCALE, 'mon');
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Gets the day of the week for a given date.
|
|
67
|
+
* @param date - The date to get the day of the week for.
|
|
68
|
+
* @returns The day of the week
|
|
69
|
+
*/
|
|
70
|
+
export function getDayOfDate(date) {
|
|
71
|
+
return Days[getDayIndex(date)];
|
|
82
72
|
}
|
|
83
73
|
/**
|
|
84
74
|
* Gets the most recent occurrence of a day of the week.
|
|
@@ -128,30 +118,40 @@ export function getLastMonths(count, startDate) {
|
|
|
128
118
|
// Calculate the previous dates
|
|
129
119
|
return map((i) => latestDate.subtract({ months: count - 1 - i }), range(0, count));
|
|
130
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Gets the date of the next occurrence of a day of the week.
|
|
123
|
+
* @param dayOfWeek - The day of the week to get the next occurrence for.
|
|
124
|
+
* @param startDate - The date to check from. Inclusive.
|
|
125
|
+
* @returns The date of the next occurrence of the specified day.
|
|
126
|
+
*/
|
|
127
|
+
export function getNextDateOfDay(dayOfWeek, startDate) {
|
|
128
|
+
const dayIndex = DayIndex[dayOfWeek];
|
|
129
|
+
const startIndex = getDayIndex(startDate);
|
|
130
|
+
// Already on the day
|
|
131
|
+
if (startIndex === dayIndex)
|
|
132
|
+
return startDate;
|
|
133
|
+
// Calculate how many days to add to get to the next occurrence
|
|
134
|
+
const addition = (dayIndex - startIndex + 7) % 7;
|
|
135
|
+
return startDate.add({ days: addition });
|
|
136
|
+
}
|
|
131
137
|
/* Intervals */
|
|
132
138
|
/**
|
|
133
|
-
* Checks if
|
|
134
|
-
* @param
|
|
135
|
-
* @param
|
|
136
|
-
* @
|
|
137
|
-
* @param end2 - The end time of the second range.
|
|
138
|
-
* @returns True if the ranges overlap, false otherwise.
|
|
139
|
+
* Checks if a given date is a specific day of the week.
|
|
140
|
+
* @param date - The date to check.
|
|
141
|
+
* @param dayOfWeek - The day of the week to check against.
|
|
142
|
+
* @returns True if the date is the specified day, false otherwise.
|
|
139
143
|
*/
|
|
140
|
-
export function
|
|
141
|
-
|
|
144
|
+
export function isDateDay(date, dayOfWeek) {
|
|
145
|
+
const dateDay = getDayOfDate(date);
|
|
146
|
+
return dateDay === dayOfWeek;
|
|
142
147
|
}
|
|
143
148
|
/**
|
|
144
|
-
*
|
|
145
|
-
* @param
|
|
146
|
-
* @
|
|
147
|
-
* @param duration - The duration to check against. Inclusive of boundaries.
|
|
148
|
-
* @returns True if the dates are within duration, false otherwise.
|
|
149
|
+
* Checks if a given date is today.
|
|
150
|
+
* @param date - The date to check.
|
|
151
|
+
* @returns True if the date is today, false otherwise.
|
|
149
152
|
*/
|
|
150
|
-
export function
|
|
151
|
-
|
|
152
|
-
if (date1.compare(date2) > 0)
|
|
153
|
-
return false;
|
|
154
|
-
return date1.add(duration).compare(date2) >= 0;
|
|
153
|
+
export function isDateToday(date, timezone) {
|
|
154
|
+
return today(timezone).compare(date) === 0;
|
|
155
155
|
}
|
|
156
156
|
const msPerWeek = 7 * 24 * 60 * 60 * 1000;
|
|
157
157
|
/**
|
|
@@ -166,16 +166,6 @@ export function dateDiffWeeks(date1, date2) {
|
|
|
166
166
|
}
|
|
167
167
|
/* Formatting */
|
|
168
168
|
/* Day of the week*/
|
|
169
|
-
/**
|
|
170
|
-
* Formats a day of the week.
|
|
171
|
-
* @param day - The day of the week to format.
|
|
172
|
-
* @example "Monday" -> "Mon"
|
|
173
|
-
* @returns Formatted string of the day of the week.
|
|
174
|
-
*/
|
|
175
|
-
export function formatDayShort(day) {
|
|
176
|
-
// Use the first three letters of the day
|
|
177
|
-
return day.slice(0, 3);
|
|
178
|
-
}
|
|
179
169
|
/**
|
|
180
170
|
* Formats a day of the week.
|
|
181
171
|
* @param day - The day of the week to format.
|
|
@@ -186,6 +176,16 @@ export function formatDayLetter(day) {
|
|
|
186
176
|
// Use the first letters of the day
|
|
187
177
|
return day.slice(0, 1);
|
|
188
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* Formats a day of the week.
|
|
181
|
+
* @param day - The day of the week to format.
|
|
182
|
+
* @example "Monday" -> "Mon"
|
|
183
|
+
* @returns Formatted string of the day of the week.
|
|
184
|
+
*/
|
|
185
|
+
export function formatDayShort(day) {
|
|
186
|
+
// Use the first three letters of the day
|
|
187
|
+
return day.slice(0, 3);
|
|
188
|
+
}
|
|
189
189
|
/* Calendar Dates */
|
|
190
190
|
const FullDateFormatter = new DateFormatter(DEFAULT_LOCALE, {
|
|
191
191
|
day: 'numeric',
|
|
@@ -193,8 +193,8 @@ const FullDateFormatter = new DateFormatter(DEFAULT_LOCALE, {
|
|
|
193
193
|
year: 'numeric'
|
|
194
194
|
});
|
|
195
195
|
const ShortDateFormatter = new DateFormatter(DEFAULT_LOCALE, {
|
|
196
|
-
|
|
197
|
-
|
|
196
|
+
day: 'numeric',
|
|
197
|
+
month: 'short'
|
|
198
198
|
});
|
|
199
199
|
const MonthFormatter = new DateFormatter(DEFAULT_LOCALE, {
|
|
200
200
|
month: 'short',
|
|
@@ -205,17 +205,16 @@ const NumFormatter = new DateFormatter(DEFAULT_LOCALE, {
|
|
|
205
205
|
month: '2-digit',
|
|
206
206
|
year: 'numeric'
|
|
207
207
|
});
|
|
208
|
-
function formatDate(date, formatter) {
|
|
209
|
-
const nativeDate = date.toDate(getLocalTimeZone());
|
|
210
|
-
return formatter.format(nativeDate);
|
|
211
|
-
}
|
|
212
208
|
/**
|
|
213
|
-
*
|
|
214
|
-
* @
|
|
215
|
-
* @
|
|
209
|
+
* Formats a full date and time.
|
|
210
|
+
* @param datetime The ZonedDateTime object to format.
|
|
211
|
+
* @returns The formatted date and time string.
|
|
212
|
+
* @example "05/10/2023 14:30:00"
|
|
216
213
|
*/
|
|
217
|
-
export function
|
|
218
|
-
|
|
214
|
+
export function formatAbsolute(datetime) {
|
|
215
|
+
const date = toCalendarDate(datetime);
|
|
216
|
+
const time = toTime(datetime);
|
|
217
|
+
return `${formatDateNum(date)} ${formatTimeFull(time)}`;
|
|
219
218
|
}
|
|
220
219
|
/**
|
|
221
220
|
* @param date The CalendarDate object to format.
|
|
@@ -242,6 +241,14 @@ export function formatDateISO(date) {
|
|
|
242
241
|
export function formatDateNum(date) {
|
|
243
242
|
return formatDate(date, NumFormatter);
|
|
244
243
|
}
|
|
244
|
+
/**
|
|
245
|
+
* @param date The CalendarDate object to format.
|
|
246
|
+
* @returns string of date in shortened format
|
|
247
|
+
* @example "Oct 5"
|
|
248
|
+
*/
|
|
249
|
+
export function formatDateShort(date) {
|
|
250
|
+
return formatDate(date, ShortDateFormatter);
|
|
251
|
+
}
|
|
245
252
|
/**
|
|
246
253
|
* Formats the month only.
|
|
247
254
|
* @param date - The date to format.
|
|
@@ -252,22 +259,15 @@ export function formatMonth(date) {
|
|
|
252
259
|
return formatDate(date, MonthFormatter);
|
|
253
260
|
}
|
|
254
261
|
/* Times */
|
|
255
|
-
// Pad number with zeroes to the left
|
|
256
|
-
function padNum(num, len) {
|
|
257
|
-
if (isNaN(num)) {
|
|
258
|
-
return '0'.repeat(len);
|
|
259
|
-
}
|
|
260
|
-
return num.toString().padStart(len, '0');
|
|
261
|
-
}
|
|
262
262
|
/**
|
|
263
|
-
*
|
|
264
|
-
* @param time
|
|
265
|
-
* @
|
|
263
|
+
* Calculates the end time given a starting time and duration.
|
|
264
|
+
* @param timeStart starting time
|
|
265
|
+
* @param durationMinutes duration in minutes
|
|
266
|
+
* @returns end time in HH:MM format
|
|
266
267
|
*/
|
|
267
|
-
export function
|
|
268
|
-
const
|
|
269
|
-
|
|
270
|
-
return `${hours}:${minutes}`;
|
|
268
|
+
export function formatTimeEnd(timeStart, durationMinutes) {
|
|
269
|
+
const timeEnd = timeStart.add({ minutes: durationMinutes });
|
|
270
|
+
return formatTimeShort(timeEnd);
|
|
271
271
|
}
|
|
272
272
|
/**
|
|
273
273
|
* Gives time in HH:MM:SS format
|
|
@@ -281,27 +281,15 @@ export function formatTimeFull(time) {
|
|
|
281
281
|
return `${hours}:${minutes}:${seconds}`;
|
|
282
282
|
}
|
|
283
283
|
/**
|
|
284
|
-
*
|
|
285
|
-
* @param
|
|
286
|
-
* @
|
|
287
|
-
* @returns end time in HH:MM format
|
|
288
|
-
*/
|
|
289
|
-
export function formatTimeEnd(timeStart, durationMinutes) {
|
|
290
|
-
const timeEnd = timeStart.add({ minutes: durationMinutes });
|
|
291
|
-
return formatTimeShort(timeEnd);
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* Formats a full date and time.
|
|
295
|
-
* @param datetime The ZonedDateTime object to format.
|
|
296
|
-
* @returns The formatted date and time string.
|
|
297
|
-
* @example "05/10/2023 14:30:00"
|
|
284
|
+
* Gives time in HH:MM format
|
|
285
|
+
* @param time
|
|
286
|
+
* @returns string of time in that format
|
|
298
287
|
*/
|
|
299
|
-
export function
|
|
300
|
-
const
|
|
301
|
-
const
|
|
302
|
-
return `${
|
|
288
|
+
export function formatTimeShort(time) {
|
|
289
|
+
const hours = padNum(time.hour, 2);
|
|
290
|
+
const minutes = padNum(time.minute, 2);
|
|
291
|
+
return `${hours}:${minutes}`;
|
|
303
292
|
}
|
|
304
|
-
/* State handling */
|
|
305
293
|
/**
|
|
306
294
|
* Unfreezes a CalendarDate object from a snapshot.
|
|
307
295
|
* @param raw - The snapshot of the CalendarDate object.
|
|
@@ -318,21 +306,33 @@ export function unfreezeDate(raw) {
|
|
|
318
306
|
export function unfreezeTime(raw) {
|
|
319
307
|
return new Time(raw.hour, raw.minute, raw.second, raw.millisecond);
|
|
320
308
|
}
|
|
309
|
+
/* State handling */
|
|
310
|
+
function formatDate(date, formatter) {
|
|
311
|
+
const nativeDate = date.toDate(getLocalTimeZone());
|
|
312
|
+
return formatter.format(nativeDate);
|
|
313
|
+
}
|
|
314
|
+
// Pad number with zeroes to the left
|
|
315
|
+
function padNum(num, len) {
|
|
316
|
+
if (isNaN(num)) {
|
|
317
|
+
return '0'.repeat(len);
|
|
318
|
+
}
|
|
319
|
+
return num.toString().padStart(len, '0');
|
|
320
|
+
}
|
|
321
321
|
// SerDe
|
|
322
322
|
export const dateTransport = {
|
|
323
|
-
Time: {
|
|
324
|
-
encode: (t) => t instanceof Time && [t.hour, t.minute, t.second, t.millisecond],
|
|
325
|
-
decode: ([hour, minute, second, millisecond]) => new Time(hour, minute, second, millisecond)
|
|
326
|
-
},
|
|
327
323
|
CalendarDate: {
|
|
328
|
-
|
|
329
|
-
|
|
324
|
+
decode: ([year, month, day]) => new CalendarDate(year, month, day),
|
|
325
|
+
encode: (d) => d instanceof CalendarDate && [d.year, d.month, d.day]
|
|
326
|
+
},
|
|
327
|
+
Time: {
|
|
328
|
+
decode: ([hour, minute, second, millisecond]) => new Time(hour, minute, second, millisecond),
|
|
329
|
+
encode: (t) => t instanceof Time && [t.hour, t.minute, t.second, t.millisecond]
|
|
330
330
|
},
|
|
331
331
|
ZonedDateTime: {
|
|
332
|
-
encode: (value) => value instanceof ZonedDateTime && [value.toAbsoluteString(), value.timeZone],
|
|
333
332
|
decode: ([absoluteString, timezone]) => {
|
|
334
333
|
const nativeDate = new Date(absoluteString);
|
|
335
334
|
return fromDate(nativeDate, timezone);
|
|
336
|
-
}
|
|
335
|
+
},
|
|
336
|
+
encode: (value) => value instanceof ZonedDateTime && [value.toAbsoluteString(), value.timeZone]
|
|
337
337
|
}
|
|
338
338
|
};
|