@cute-widgets/base 20.0.1
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/CHANGELOG.md +1 -0
- package/LICENSE.md +191 -0
- package/README.md +190 -0
- package/abstract/index.d.ts +327 -0
- package/alert/index.d.ts +68 -0
- package/autocomplete/index.d.ts +442 -0
- package/badge/index.d.ts +26 -0
- package/bottom-sheet/index.d.ts +231 -0
- package/button/index.d.ts +182 -0
- package/button-toggle/index.d.ts +225 -0
- package/card/index.d.ts +163 -0
- package/checkbox/index.d.ts +174 -0
- package/chips/index.d.ts +963 -0
- package/collapse/index.d.ts +97 -0
- package/core/animation/index.d.ts +43 -0
- package/core/datetime/index.d.ts +404 -0
- package/core/directives/index.d.ts +168 -0
- package/core/error/index.d.ts +74 -0
- package/core/index.d.ts +1039 -0
- package/core/interfaces/index.d.ts +114 -0
- package/core/layout/index.d.ts +53 -0
- package/core/line/index.d.ts +37 -0
- package/core/nav/index.d.ts +321 -0
- package/core/observers/index.d.ts +124 -0
- package/core/option/index.d.ts +185 -0
- package/core/pipes/index.d.ts +53 -0
- package/core/ripple/index.d.ts +66 -0
- package/core/testing/index.d.ts +154 -0
- package/core/theming/index.d.ts +118 -0
- package/core/types/index.d.ts +53 -0
- package/core/utils/index.d.ts +129 -0
- package/cute-widgets-base-20.0.1.tgz +0 -0
- package/datepicker/index.d.ts +1817 -0
- package/dialog/index.d.ts +484 -0
- package/divider/index.d.ts +24 -0
- package/expansion/README.md +8 -0
- package/expansion/index.d.ts +308 -0
- package/fesm2022/cute-widgets-base-abstract.mjs +547 -0
- package/fesm2022/cute-widgets-base-abstract.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-alert.mjs +198 -0
- package/fesm2022/cute-widgets-base-alert.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-autocomplete.mjs +1217 -0
- package/fesm2022/cute-widgets-base-autocomplete.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-badge.mjs +75 -0
- package/fesm2022/cute-widgets-base-badge.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-bottom-sheet.mjs +416 -0
- package/fesm2022/cute-widgets-base-bottom-sheet.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-button-toggle.mjs +640 -0
- package/fesm2022/cute-widgets-base-button-toggle.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-button.mjs +546 -0
- package/fesm2022/cute-widgets-base-button.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-card.mjs +471 -0
- package/fesm2022/cute-widgets-base-card.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-checkbox.mjs +390 -0
- package/fesm2022/cute-widgets-base-checkbox.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-chips.mjs +2360 -0
- package/fesm2022/cute-widgets-base-chips.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-collapse.mjs +259 -0
- package/fesm2022/cute-widgets-base-collapse.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-animation.mjs +53 -0
- package/fesm2022/cute-widgets-base-core-animation.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-datetime.mjs +568 -0
- package/fesm2022/cute-widgets-base-core-datetime.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-directives.mjs +404 -0
- package/fesm2022/cute-widgets-base-core-directives.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-error.mjs +105 -0
- package/fesm2022/cute-widgets-base-core-error.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-interfaces.mjs +22 -0
- package/fesm2022/cute-widgets-base-core-interfaces.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-layout.mjs +74 -0
- package/fesm2022/cute-widgets-base-core-layout.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-line.mjs +87 -0
- package/fesm2022/cute-widgets-base-core-line.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-nav.mjs +863 -0
- package/fesm2022/cute-widgets-base-core-nav.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-observers.mjs +304 -0
- package/fesm2022/cute-widgets-base-core-observers.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-option.mjs +373 -0
- package/fesm2022/cute-widgets-base-core-option.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-pipes.mjs +97 -0
- package/fesm2022/cute-widgets-base-core-pipes.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-ripple.mjs +172 -0
- package/fesm2022/cute-widgets-base-core-ripple.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-testing.mjs +210 -0
- package/fesm2022/cute-widgets-base-core-testing.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-theming.mjs +314 -0
- package/fesm2022/cute-widgets-base-core-theming.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-types.mjs +22 -0
- package/fesm2022/cute-widgets-base-core-types.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-utils.mjs +257 -0
- package/fesm2022/cute-widgets-base-core-utils.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core.mjs +1600 -0
- package/fesm2022/cute-widgets-base-core.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-datepicker.mjs +4827 -0
- package/fesm2022/cute-widgets-base-datepicker.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-dialog.mjs +1046 -0
- package/fesm2022/cute-widgets-base-dialog.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-divider.mjs +86 -0
- package/fesm2022/cute-widgets-base-divider.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-expansion.mjs +623 -0
- package/fesm2022/cute-widgets-base-expansion.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-form-field.mjs +969 -0
- package/fesm2022/cute-widgets-base-form-field.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-grid-list.mjs +715 -0
- package/fesm2022/cute-widgets-base-grid-list.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-icon.mjs +1105 -0
- package/fesm2022/cute-widgets-base-icon.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-input.mjs +726 -0
- package/fesm2022/cute-widgets-base-input.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-layout-container.mjs +95 -0
- package/fesm2022/cute-widgets-base-layout-container.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-layout-stack.mjs +166 -0
- package/fesm2022/cute-widgets-base-layout-stack.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-layout.mjs +250 -0
- package/fesm2022/cute-widgets-base-layout.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-list.mjs +1557 -0
- package/fesm2022/cute-widgets-base-list.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-menu.mjs +1283 -0
- package/fesm2022/cute-widgets-base-menu.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-navbar.mjs +359 -0
- package/fesm2022/cute-widgets-base-navbar.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-paginator.mjs +485 -0
- package/fesm2022/cute-widgets-base-paginator.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-progress.mjs +321 -0
- package/fesm2022/cute-widgets-base-progress.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-radio.mjs +637 -0
- package/fesm2022/cute-widgets-base-radio.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-select.mjs +1208 -0
- package/fesm2022/cute-widgets-base-select.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-sidenav.mjs +1095 -0
- package/fesm2022/cute-widgets-base-sidenav.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-slider.mjs +99 -0
- package/fesm2022/cute-widgets-base-slider.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-snack-bar.mjs +897 -0
- package/fesm2022/cute-widgets-base-snack-bar.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-sort.mjs +639 -0
- package/fesm2022/cute-widgets-base-sort.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-spinner.mjs +154 -0
- package/fesm2022/cute-widgets-base-spinner.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-stepper.mjs +673 -0
- package/fesm2022/cute-widgets-base-stepper.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-table.mjs +1023 -0
- package/fesm2022/cute-widgets-base-table.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-tabs.mjs +729 -0
- package/fesm2022/cute-widgets-base-tabs.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-timepicker.mjs +965 -0
- package/fesm2022/cute-widgets-base-timepicker.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-toolbar.mjs +120 -0
- package/fesm2022/cute-widgets-base-toolbar.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-tooltip.mjs +947 -0
- package/fesm2022/cute-widgets-base-tooltip.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-tree.mjs +598 -0
- package/fesm2022/cute-widgets-base-tree.mjs.map +1 -0
- package/fesm2022/cute-widgets-base.mjs +68 -0
- package/fesm2022/cute-widgets-base.mjs.map +1 -0
- package/form-field/index.d.ts +401 -0
- package/grid-list/index.d.ts +361 -0
- package/icon/index.d.ts +477 -0
- package/index.d.ts +3 -0
- package/input/index.d.ts +256 -0
- package/layout/container/index.d.ts +31 -0
- package/layout/index.d.ts +78 -0
- package/layout/stack/index.d.ts +52 -0
- package/list/index.d.ts +659 -0
- package/menu/index.d.ts +497 -0
- package/navbar/index.d.ts +91 -0
- package/package.json +279 -0
- package/paginator/index.d.ts +216 -0
- package/progress/index.d.ts +130 -0
- package/radio/index.d.ts +259 -0
- package/select/index.d.ts +426 -0
- package/sidenav/index.d.ts +369 -0
- package/slider/index.d.ts +48 -0
- package/snack-bar/index.d.ts +374 -0
- package/sort/index.d.ts +334 -0
- package/spinner/index.d.ts +70 -0
- package/stepper/index.d.ts +295 -0
- package/table/index.d.ts +395 -0
- package/tabs/index.d.ts +307 -0
- package/timepicker/index.d.ts +350 -0
- package/toolbar/index.d.ts +36 -0
- package/tooltip/index.d.ts +299 -0
- package/tree/index.d.ts +314 -0
|
@@ -0,0 +1,568 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { InjectionToken, inject, LOCALE_ID, isDevMode, Injectable, NgModule } from '@angular/core';
|
|
3
|
+
import { Subject } from 'rxjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @license Apache-2.0
|
|
7
|
+
*
|
|
8
|
+
* Copyright (c) 2025 CuteWidgets Team. All Rights Reserved.
|
|
9
|
+
*
|
|
10
|
+
* You may not use this file except in compliance with the License
|
|
11
|
+
* that can be found at http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* This code is a modification of the `@angular/material` original
|
|
14
|
+
* code licensed under MIT-style License (https://angular.dev/license).
|
|
15
|
+
*/
|
|
16
|
+
/** InjectionToken for datepicker that can be used to override default locale code. */
|
|
17
|
+
const CUTE_DATE_LOCALE = new InjectionToken('CUTE_DATE_LOCALE', {
|
|
18
|
+
providedIn: 'root',
|
|
19
|
+
factory: CUTE_DATE_LOCALE_FACTORY,
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* @docs-private
|
|
23
|
+
* @deprecated No longer used, will be removed.
|
|
24
|
+
* @breaking-change 21.0.0
|
|
25
|
+
*/
|
|
26
|
+
function CUTE_DATE_LOCALE_FACTORY() {
|
|
27
|
+
return inject(LOCALE_ID);
|
|
28
|
+
}
|
|
29
|
+
const NOT_IMPLEMENTED = 'Method not implemented';
|
|
30
|
+
/** Adapts type `D` to be usable as a date by cdk-based components that work with dates. */
|
|
31
|
+
class DateAdapter {
|
|
32
|
+
constructor() {
|
|
33
|
+
this._localeChanges = new Subject();
|
|
34
|
+
/** A stream that emits when the locale changes. */
|
|
35
|
+
this.localeChanges = this._localeChanges;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Sets the time of one date to the time of another.
|
|
39
|
+
* @param target Date whose time will be set.
|
|
40
|
+
* @param hours New hours to set on the date object.
|
|
41
|
+
* @param minutes New minutes to set on the date object.
|
|
42
|
+
* @param seconds New seconds to set on the date object.
|
|
43
|
+
*/
|
|
44
|
+
setTime(target, hours, minutes, seconds) {
|
|
45
|
+
throw new Error(NOT_IMPLEMENTED);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Gets the hours component of the given date.
|
|
49
|
+
* @param date The date to extract the hours from.
|
|
50
|
+
*/
|
|
51
|
+
getHours(date) {
|
|
52
|
+
throw new Error(NOT_IMPLEMENTED);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Gets the minutes component of the given date.
|
|
56
|
+
* @param date The date to extract the minutes from.
|
|
57
|
+
*/
|
|
58
|
+
getMinutes(date) {
|
|
59
|
+
throw new Error(NOT_IMPLEMENTED);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Gets the seconds component of the given date.
|
|
63
|
+
* @param date The date to extract the seconds from.
|
|
64
|
+
*/
|
|
65
|
+
getSeconds(date) {
|
|
66
|
+
throw new Error(NOT_IMPLEMENTED);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Parses a date with a specific time from a user-provided value.
|
|
70
|
+
* @param value The value to parse.
|
|
71
|
+
* @param parseFormat The expected format of the value being parsed
|
|
72
|
+
* (type is implementation-dependent).
|
|
73
|
+
*/
|
|
74
|
+
parseTime(value, parseFormat) {
|
|
75
|
+
throw new Error(NOT_IMPLEMENTED);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Adds an amount of seconds to the specified date.
|
|
79
|
+
* @param date Date to which to add the seconds.
|
|
80
|
+
* @param amount Amount of seconds to add to the date.
|
|
81
|
+
*/
|
|
82
|
+
addSeconds(date, amount) {
|
|
83
|
+
throw new Error(NOT_IMPLEMENTED);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Given a potential date object, returns that same date object if it is
|
|
87
|
+
* a valid date, or `null` if it's not a valid date.
|
|
88
|
+
* @param obj The object to check.
|
|
89
|
+
* @returns A date or `null`.
|
|
90
|
+
*/
|
|
91
|
+
getValidDateOrNull(obj) {
|
|
92
|
+
return this.isDateInstance(obj) && this.isValid(obj) ? obj : null;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Attempts to deserialize a value to a valid date object. This is different from parsing in that
|
|
96
|
+
* deserialize should only accept non-ambiguous, locale-independent formats (e.g. a ISO 8601
|
|
97
|
+
* string). The default implementation does not allow any deserialization, it simply checks that
|
|
98
|
+
* the given value is already a valid date object or null. The `<mat-datepicker>` will call this
|
|
99
|
+
* method on all of its `@Input()` properties that accept dates. It is therefore possible to
|
|
100
|
+
* support passing values from your backend directly to these properties by overriding this method
|
|
101
|
+
* to also deserialize the format used by your backend.
|
|
102
|
+
* @param value The value to be deserialized into a date object.
|
|
103
|
+
* @returns The deserialized date object, either a valid date, null if the value can be
|
|
104
|
+
* deserialized into a null date (e.g. the empty string), or an invalid date.
|
|
105
|
+
*/
|
|
106
|
+
deserialize(value) {
|
|
107
|
+
if (value == null || (this.isDateInstance(value) && this.isValid(value))) {
|
|
108
|
+
return value;
|
|
109
|
+
}
|
|
110
|
+
return this.invalid();
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Sets the locale used for all dates.
|
|
114
|
+
* @param locale The new locale.
|
|
115
|
+
*/
|
|
116
|
+
setLocale(locale) {
|
|
117
|
+
this.locale = locale;
|
|
118
|
+
this._localeChanges.next();
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Compares two dates.
|
|
122
|
+
* @param first The first date to compare.
|
|
123
|
+
* @param second The second date to compare.
|
|
124
|
+
* @returns 0 if the dates are equal, a number less than 0 if the first date is earlier,
|
|
125
|
+
* a number greater than 0 if the first date is later.
|
|
126
|
+
*/
|
|
127
|
+
compareDate(first, second) {
|
|
128
|
+
return (this.getYear(first) - this.getYear(second) ||
|
|
129
|
+
this.getMonth(first) - this.getMonth(second) ||
|
|
130
|
+
this.getDate(first) - this.getDate(second));
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Compares the time values of two dates.
|
|
134
|
+
* @param first First date to compare.
|
|
135
|
+
* @param second Second date to compare.
|
|
136
|
+
* @returns 0 if the times are equal, a number less than 0 if the first time is earlier,
|
|
137
|
+
* a number greater than 0 if the first time is later.
|
|
138
|
+
*/
|
|
139
|
+
compareTime(first, second) {
|
|
140
|
+
return (this.getHours(first) - this.getHours(second) ||
|
|
141
|
+
this.getMinutes(first) - this.getMinutes(second) ||
|
|
142
|
+
this.getSeconds(first) - this.getSeconds(second));
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Checks if two dates are equal.
|
|
146
|
+
* @param first The first date to check.
|
|
147
|
+
* @param second The second date to check.
|
|
148
|
+
* @returns Whether the two dates are equal.
|
|
149
|
+
* Null dates are considered equal to other null dates.
|
|
150
|
+
*/
|
|
151
|
+
sameDate(first, second) {
|
|
152
|
+
if (first && second) {
|
|
153
|
+
let firstValid = this.isValid(first);
|
|
154
|
+
let secondValid = this.isValid(second);
|
|
155
|
+
if (firstValid && secondValid) {
|
|
156
|
+
return !this.compareDate(first, second);
|
|
157
|
+
}
|
|
158
|
+
return firstValid == secondValid;
|
|
159
|
+
}
|
|
160
|
+
return first == second;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Checks if the times of two dates are equal.
|
|
164
|
+
* @param first The first date to check.
|
|
165
|
+
* @param second The second date to check.
|
|
166
|
+
* @returns Whether the times of the two dates are equal.
|
|
167
|
+
* Null dates are considered equal to other null dates.
|
|
168
|
+
*/
|
|
169
|
+
sameTime(first, second) {
|
|
170
|
+
if (first && second) {
|
|
171
|
+
const firstValid = this.isValid(first);
|
|
172
|
+
const secondValid = this.isValid(second);
|
|
173
|
+
if (firstValid && secondValid) {
|
|
174
|
+
return !this.compareTime(first, second);
|
|
175
|
+
}
|
|
176
|
+
return firstValid == secondValid;
|
|
177
|
+
}
|
|
178
|
+
return first == second;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Clamp the given date between min and max dates.
|
|
182
|
+
* @param date The date to clamp.
|
|
183
|
+
* @param min The minimum value to allow. If null or omitted, no min is enforced.
|
|
184
|
+
* @param max The maximum value to allow. If null or omitted, no max is enforced.
|
|
185
|
+
* @returns `min` if `date` is less than `min`, `max` if date is greater than `max`,
|
|
186
|
+
* otherwise `date`.
|
|
187
|
+
*/
|
|
188
|
+
clampDate(date, min, max) {
|
|
189
|
+
if (min && this.compareDate(date, min) < 0) {
|
|
190
|
+
return min;
|
|
191
|
+
}
|
|
192
|
+
if (max && this.compareDate(date, max) > 0) {
|
|
193
|
+
return max;
|
|
194
|
+
}
|
|
195
|
+
return date;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* @license Apache-2.0
|
|
201
|
+
*
|
|
202
|
+
* Copyright (c) 2025 CuteWidgets Team. All Rights Reserved.
|
|
203
|
+
*
|
|
204
|
+
* You may not use this file except in compliance with the License
|
|
205
|
+
* that can be found at http://www.apache.org/licenses/LICENSE-2.0
|
|
206
|
+
*
|
|
207
|
+
* This code is a modification of the `@angular/material` original
|
|
208
|
+
* code licensed under MIT-style License (https://angular.dev/license).
|
|
209
|
+
*/
|
|
210
|
+
const CUTE_DATE_FORMATS = new InjectionToken('cute-date-formats');
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* @license Apache-2.0
|
|
214
|
+
*
|
|
215
|
+
* Copyright (c) 2025 CuteWidgets Team. All Rights Reserved.
|
|
216
|
+
*
|
|
217
|
+
* You may not use this file except in compliance with the License
|
|
218
|
+
* that can be found at http://www.apache.org/licenses/LICENSE-2.0
|
|
219
|
+
*
|
|
220
|
+
* This code is a modification of the `@angular/material` original
|
|
221
|
+
* code licensed under MIT-style License (https://angular.dev/license).
|
|
222
|
+
*/
|
|
223
|
+
/**
|
|
224
|
+
* Matches strings that have the form of a valid RFC 3339 string
|
|
225
|
+
* (https://tools.ietf.org/html/rfc3339). Note that the string may not actually be a valid date
|
|
226
|
+
* because the regex will match strings and without of bounds month, date, etc.
|
|
227
|
+
*/
|
|
228
|
+
const ISO_8601_REGEX = /^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|(?:(?:\+|-)\d{2}:\d{2}))?)?$/;
|
|
229
|
+
/**
|
|
230
|
+
* Matches a time string. Supported formats:
|
|
231
|
+
* - {{hours}}:{{minutes}}
|
|
232
|
+
* - {{hours}}:{{minutes}}:{{seconds}}
|
|
233
|
+
* - {{hours}}:{{minutes}} AM/PM
|
|
234
|
+
* - {{hours}}:{{minutes}}:{{seconds}} AM/PM
|
|
235
|
+
* - {{hours}}.{{minutes}}
|
|
236
|
+
* - {{hours}}.{{minutes}}.{{seconds}}
|
|
237
|
+
* - {{hours}}.{{minutes}} AM/PM
|
|
238
|
+
* - {{hours}}.{{minutes}}.{{seconds}} AM/PM
|
|
239
|
+
*/
|
|
240
|
+
const TIME_REGEX = /^(\d?\d)[:.](\d?\d)(?:[:.](\d?\d))?\s*(AM|PM)?$/i;
|
|
241
|
+
/** Creates an array and fills it with values. */
|
|
242
|
+
function range(length, valueFunction) {
|
|
243
|
+
const valuesArray = Array(length);
|
|
244
|
+
for (let i = 0; i < length; i++) {
|
|
245
|
+
valuesArray[i] = valueFunction(i);
|
|
246
|
+
}
|
|
247
|
+
return valuesArray;
|
|
248
|
+
}
|
|
249
|
+
/** Adapts the native JS Date for use with cdk-based components that work with dates. */
|
|
250
|
+
class NativeDateAdapter extends DateAdapter {
|
|
251
|
+
constructor() {
|
|
252
|
+
super();
|
|
253
|
+
/** The injected locale. */
|
|
254
|
+
this._cuteDateLocale = inject(CUTE_DATE_LOCALE, { optional: true });
|
|
255
|
+
const cuteDateLocale = inject(CUTE_DATE_LOCALE, { optional: true });
|
|
256
|
+
if (cuteDateLocale !== undefined) {
|
|
257
|
+
this._cuteDateLocale = cuteDateLocale;
|
|
258
|
+
}
|
|
259
|
+
super.setLocale(this._cuteDateLocale);
|
|
260
|
+
}
|
|
261
|
+
getYear(date) { return date.getFullYear(); }
|
|
262
|
+
getMonth(date) { return date.getMonth(); }
|
|
263
|
+
getDate(date) { return date.getDate(); }
|
|
264
|
+
getDayOfWeek(date) { return date.getDay(); }
|
|
265
|
+
getMonthNames(style) {
|
|
266
|
+
const dtf = new Intl.DateTimeFormat(this.locale, { month: style, timeZone: 'utc' });
|
|
267
|
+
return range(12, i => this._format(dtf, new Date(2017, i, 1)));
|
|
268
|
+
}
|
|
269
|
+
getDateNames() {
|
|
270
|
+
const dtf = new Intl.DateTimeFormat(this.locale, { day: 'numeric', timeZone: 'utc' });
|
|
271
|
+
return range(31, i => this._format(dtf, new Date(2017, 0, i + 1)));
|
|
272
|
+
}
|
|
273
|
+
getDayOfWeekNames(style) {
|
|
274
|
+
const dtf = new Intl.DateTimeFormat(this.locale, { weekday: style, timeZone: 'utc' });
|
|
275
|
+
return range(7, i => this._format(dtf, new Date(2017, 0, i + 1)));
|
|
276
|
+
}
|
|
277
|
+
getYearName(date) {
|
|
278
|
+
const dtf = new Intl.DateTimeFormat(this.locale, { year: 'numeric', timeZone: 'utc' });
|
|
279
|
+
return this._format(dtf, date);
|
|
280
|
+
}
|
|
281
|
+
getFirstDayOfWeek() {
|
|
282
|
+
// At the time of writing `Intl.Locale` isn't available
|
|
283
|
+
// in the internal types, so we need to cast to `any`.
|
|
284
|
+
if (typeof Intl !== 'undefined' && Intl.Locale) {
|
|
285
|
+
const locale = new Intl.Locale(this.locale);
|
|
286
|
+
// Some browsers implement a `getWeekInfo` method while others have a `weekInfo` getter.
|
|
287
|
+
// Note that this isn't supported in all browsers, so we need to null check it.
|
|
288
|
+
const firstDay = (locale.getWeekInfo?.() || locale.weekInfo)?.firstDay ?? 0;
|
|
289
|
+
// `weekInfo.firstDay` is a number between 1 and 7 where, starting from Monday,
|
|
290
|
+
// whereas our representation is 0 to 6 where 0 is Sunday, so we need to normalize it.
|
|
291
|
+
return firstDay === 7 ? 0 : firstDay;
|
|
292
|
+
}
|
|
293
|
+
// Default to Sunday if the browser doesn't provide the week information.
|
|
294
|
+
return 0;
|
|
295
|
+
}
|
|
296
|
+
getNumDaysInMonth(date) {
|
|
297
|
+
return this.getDate(this._createDateWithOverflow(this.getYear(date), this.getMonth(date) + 1, 0));
|
|
298
|
+
}
|
|
299
|
+
clone(date) {
|
|
300
|
+
return new Date(date.getTime());
|
|
301
|
+
}
|
|
302
|
+
createDate(year, month, date) {
|
|
303
|
+
if (isDevMode()) {
|
|
304
|
+
// Check for invalid month and date (except upper bound on date which we have to check after
|
|
305
|
+
// creating the Date).
|
|
306
|
+
if (month < 0 || month > 11) {
|
|
307
|
+
throw Error(`Invalid month index "${month}". Month index has to be between 0 and 11.`);
|
|
308
|
+
}
|
|
309
|
+
if (date < 1) {
|
|
310
|
+
throw Error(`Invalid date "${date}". Date has to be greater than 0.`);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
let result = this._createDateWithOverflow(year, month, date);
|
|
314
|
+
// Check that the date wasn't above the upper bound for the month, causing the month to overflow
|
|
315
|
+
if (result.getMonth() != month && isDevMode()) {
|
|
316
|
+
throw Error(`Invalid date "${date}" for month with index "${month}".`);
|
|
317
|
+
}
|
|
318
|
+
return result;
|
|
319
|
+
}
|
|
320
|
+
today() {
|
|
321
|
+
return new Date();
|
|
322
|
+
}
|
|
323
|
+
parse(value, parseFormat) {
|
|
324
|
+
// We have no way using the native JS Date to set the parse format or locale, so we ignore these
|
|
325
|
+
// parameters.
|
|
326
|
+
if (typeof value == 'number') {
|
|
327
|
+
return new Date(value);
|
|
328
|
+
}
|
|
329
|
+
return value ? new Date(Date.parse(value)) : null;
|
|
330
|
+
}
|
|
331
|
+
format(date, displayFormat) {
|
|
332
|
+
if (!this.isValid(date)) {
|
|
333
|
+
throw Error('NativeDateAdapter: Cannot format invalid date.');
|
|
334
|
+
}
|
|
335
|
+
const dtf = new Intl.DateTimeFormat(this.locale, { ...displayFormat, timeZone: 'utc' });
|
|
336
|
+
return this._format(dtf, date);
|
|
337
|
+
}
|
|
338
|
+
addCalendarYears(date, years) {
|
|
339
|
+
return this.addCalendarMonths(date, years * 12);
|
|
340
|
+
}
|
|
341
|
+
addCalendarMonths(date, months) {
|
|
342
|
+
let newDate = this._createDateWithOverflow(this.getYear(date), this.getMonth(date) + months, this.getDate(date));
|
|
343
|
+
// It's possible to wind up in the wrong month if the original month has more days than the new
|
|
344
|
+
// month. In this case we want to go to the last day of the desired month.
|
|
345
|
+
// Note: the additional + 12 % 12 ensures we end up with a positive number, since JS % doesn't
|
|
346
|
+
// guarantee this.
|
|
347
|
+
if (this.getMonth(newDate) != (((this.getMonth(date) + months) % 12) + 12) % 12) {
|
|
348
|
+
newDate = this._createDateWithOverflow(this.getYear(newDate), this.getMonth(newDate), 0);
|
|
349
|
+
}
|
|
350
|
+
return newDate;
|
|
351
|
+
}
|
|
352
|
+
addCalendarDays(date, days) {
|
|
353
|
+
return this._createDateWithOverflow(this.getYear(date), this.getMonth(date), this.getDate(date) + days);
|
|
354
|
+
}
|
|
355
|
+
toIso8601(date) {
|
|
356
|
+
return [
|
|
357
|
+
date.getUTCFullYear(),
|
|
358
|
+
this._2digit(date.getUTCMonth() + 1),
|
|
359
|
+
this._2digit(date.getUTCDate()),
|
|
360
|
+
].join('-');
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Returns the given value if given a valid Date or null. Deserializes valid ISO 8601 strings
|
|
364
|
+
* (https://www.ietf.org/rfc/rfc3339.txt) into valid Dates and empty string into null. Returns an
|
|
365
|
+
* invalid date for all other values.
|
|
366
|
+
*/
|
|
367
|
+
deserialize(value) {
|
|
368
|
+
if (typeof value === 'string') {
|
|
369
|
+
if (!value) {
|
|
370
|
+
return null;
|
|
371
|
+
}
|
|
372
|
+
// The `Date` constructor accepts formats other than ISO 8601, so we need to make sure the
|
|
373
|
+
// string is the right format first.
|
|
374
|
+
if (ISO_8601_REGEX.test(value)) {
|
|
375
|
+
let date = new Date(value);
|
|
376
|
+
if (this.isValid(date)) {
|
|
377
|
+
return date;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
return super.deserialize(value);
|
|
382
|
+
}
|
|
383
|
+
isDateInstance(obj) {
|
|
384
|
+
return obj instanceof Date;
|
|
385
|
+
}
|
|
386
|
+
isValid(date) {
|
|
387
|
+
return !isNaN(date.getTime());
|
|
388
|
+
}
|
|
389
|
+
invalid() {
|
|
390
|
+
return new Date(NaN);
|
|
391
|
+
}
|
|
392
|
+
setTime(target, hours, minutes, seconds) {
|
|
393
|
+
if (isDevMode()) {
|
|
394
|
+
if (!inRange(hours, 0, 23)) {
|
|
395
|
+
throw Error(`Invalid hours "${hours}". Hours value must be between 0 and 23.`);
|
|
396
|
+
}
|
|
397
|
+
if (!inRange(minutes, 0, 59)) {
|
|
398
|
+
throw Error(`Invalid minutes "${minutes}". Minutes value must be between 0 and 59.`);
|
|
399
|
+
}
|
|
400
|
+
if (!inRange(seconds, 0, 59)) {
|
|
401
|
+
throw Error(`Invalid seconds "${seconds}". Seconds value must be between 0 and 59.`);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
const clone = this.clone(target);
|
|
405
|
+
clone.setHours(hours, minutes, seconds, 0);
|
|
406
|
+
return clone;
|
|
407
|
+
}
|
|
408
|
+
getHours(date) {
|
|
409
|
+
return date.getHours();
|
|
410
|
+
}
|
|
411
|
+
getMinutes(date) {
|
|
412
|
+
return date.getMinutes();
|
|
413
|
+
}
|
|
414
|
+
getSeconds(date) {
|
|
415
|
+
return date.getSeconds();
|
|
416
|
+
}
|
|
417
|
+
parseTime(userValue, parseFormat) {
|
|
418
|
+
if (typeof userValue !== 'string') {
|
|
419
|
+
return userValue instanceof Date ? new Date(userValue.getTime()) : null;
|
|
420
|
+
}
|
|
421
|
+
const value = userValue.trim();
|
|
422
|
+
if (value.length === 0) {
|
|
423
|
+
return null;
|
|
424
|
+
}
|
|
425
|
+
// Attempt to parse the value directly.
|
|
426
|
+
let result = this._parseTimeString(value);
|
|
427
|
+
// Some locales add extra characters around the time, but are otherwise parseable
|
|
428
|
+
// (e.g. `00:05 ч.` in bg-BG). Try replacing all non-number and non-colon characters.
|
|
429
|
+
if (result === null) {
|
|
430
|
+
const withoutExtras = value.replace(/[^0-9:(AM|PM)]/gi, '').trim();
|
|
431
|
+
if (withoutExtras.length > 0) {
|
|
432
|
+
result = this._parseTimeString(withoutExtras);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
return result || this.invalid();
|
|
436
|
+
}
|
|
437
|
+
addSeconds(date, amount) {
|
|
438
|
+
return new Date(date.getTime() + amount * 1000);
|
|
439
|
+
}
|
|
440
|
+
/** Creates a date but allows the month and date to overflow. */
|
|
441
|
+
_createDateWithOverflow(year, month, date) {
|
|
442
|
+
// Passing the year to the constructor causes year numbers <100 to be converted to 19xx.
|
|
443
|
+
// To work around this, we use `setFullYear` and `setHours` instead.
|
|
444
|
+
const d = new Date();
|
|
445
|
+
d.setFullYear(year, month, date);
|
|
446
|
+
d.setHours(0, 0, 0, 0);
|
|
447
|
+
return d;
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Pads a number to make it two digits.
|
|
451
|
+
* @param n The number to pad.
|
|
452
|
+
* @returns The padded number.
|
|
453
|
+
*/
|
|
454
|
+
_2digit(n) {
|
|
455
|
+
return ('00' + n).slice(-2);
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* When converting a Date object to string, javascript built-in functions may return wrong
|
|
459
|
+
* results because it applies its internal DST rules. The DST rules around the world change
|
|
460
|
+
* very frequently, and the current valid rule is not always valid in previous years though.
|
|
461
|
+
* We work around this problem building a new Date object which has its internal UTC
|
|
462
|
+
* representation with the local date and time.
|
|
463
|
+
* @param dtf Intl.DateTimeFormat object, containing the desired string format. It must have
|
|
464
|
+
* timeZone set to 'utc' to work fine.
|
|
465
|
+
* @param date Date from which we want to get the string representation according to dtf
|
|
466
|
+
* @returns A Date object with its UTC representation based on the passed in date info
|
|
467
|
+
*/
|
|
468
|
+
_format(dtf, date) {
|
|
469
|
+
// Passing the year to the constructor causes year numbers <100 to be converted to 19xx.
|
|
470
|
+
// To work around this, we use `setUTCFullYear` and `setUTCHours` instead.
|
|
471
|
+
const d = new Date();
|
|
472
|
+
d.setUTCFullYear(date.getFullYear(), date.getMonth(), date.getDate());
|
|
473
|
+
d.setUTCHours(date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
|
|
474
|
+
return dtf.format(d);
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Attempts to parse a time string into a date object. Returns null if it cannot be parsed.
|
|
478
|
+
* @param value Time string to parse.
|
|
479
|
+
*/
|
|
480
|
+
_parseTimeString(value) {
|
|
481
|
+
// Note: we can technically rely on the browser for the time parsing by generating
|
|
482
|
+
// an ISO string and appending the string to the end of it. We don't do it, because
|
|
483
|
+
// browsers aren't consistent in what they support. Some examples:
|
|
484
|
+
// - Safari doesn't support AM/PM.
|
|
485
|
+
// - Firefox produces a valid date object if the time string has overflows (e.g. 12:75) while
|
|
486
|
+
// other browsers produce an invalid date.
|
|
487
|
+
// - Safari doesn't allow padded numbers.
|
|
488
|
+
const parsed = value.toUpperCase().match(TIME_REGEX);
|
|
489
|
+
if (parsed) {
|
|
490
|
+
let hours = parseInt(parsed[1]);
|
|
491
|
+
const minutes = parseInt(parsed[2]);
|
|
492
|
+
let seconds = parsed[3] == null ? undefined : parseInt(parsed[3]);
|
|
493
|
+
const amPm = parsed[4];
|
|
494
|
+
if (hours === 12) {
|
|
495
|
+
hours = amPm === 'AM' ? 0 : hours;
|
|
496
|
+
}
|
|
497
|
+
else if (amPm === 'PM') {
|
|
498
|
+
hours += 12;
|
|
499
|
+
}
|
|
500
|
+
if (inRange(hours, 0, 23) &&
|
|
501
|
+
inRange(minutes, 0, 59) &&
|
|
502
|
+
(seconds == null || inRange(seconds, 0, 59))) {
|
|
503
|
+
return this.setTime(this.today(), hours, minutes, seconds || 0);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
return null;
|
|
507
|
+
}
|
|
508
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: NativeDateAdapter, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
509
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: NativeDateAdapter }); }
|
|
510
|
+
}
|
|
511
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: NativeDateAdapter, decorators: [{
|
|
512
|
+
type: Injectable
|
|
513
|
+
}], ctorParameters: () => [] });
|
|
514
|
+
/** Checks whether a number is within a certain range. */
|
|
515
|
+
function inRange(value, min, max) {
|
|
516
|
+
return !isNaN(value) && value >= min && value <= max;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
const CUTE_NATIVE_DATE_FORMATS = {
|
|
520
|
+
parse: {
|
|
521
|
+
dateInput: null,
|
|
522
|
+
timeInput: null,
|
|
523
|
+
},
|
|
524
|
+
display: {
|
|
525
|
+
dateInput: { year: 'numeric', month: 'numeric', day: 'numeric' },
|
|
526
|
+
timeInput: { hour: 'numeric', minute: 'numeric' },
|
|
527
|
+
monthYearLabel: { year: 'numeric', month: 'short' },
|
|
528
|
+
dateA11yLabel: { year: 'numeric', month: 'long', day: 'numeric' },
|
|
529
|
+
monthYearA11yLabel: { year: 'numeric', month: 'long' },
|
|
530
|
+
timeOptionLabel: { hour: 'numeric', minute: 'numeric' },
|
|
531
|
+
},
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
class NativeDateModule {
|
|
535
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: NativeDateModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
536
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.15", ngImport: i0, type: NativeDateModule }); }
|
|
537
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: NativeDateModule, providers: [{ provide: DateAdapter, useClass: NativeDateAdapter }] }); }
|
|
538
|
+
}
|
|
539
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: NativeDateModule, decorators: [{
|
|
540
|
+
type: NgModule,
|
|
541
|
+
args: [{
|
|
542
|
+
providers: [{ provide: DateAdapter, useClass: NativeDateAdapter }],
|
|
543
|
+
}]
|
|
544
|
+
}] });
|
|
545
|
+
class CuteNativeDateModule {
|
|
546
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: CuteNativeDateModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
547
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.15", ngImport: i0, type: CuteNativeDateModule }); }
|
|
548
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: CuteNativeDateModule, providers: [provideNativeDateAdapter()] }); }
|
|
549
|
+
}
|
|
550
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: CuteNativeDateModule, decorators: [{
|
|
551
|
+
type: NgModule,
|
|
552
|
+
args: [{
|
|
553
|
+
providers: [provideNativeDateAdapter()],
|
|
554
|
+
}]
|
|
555
|
+
}] });
|
|
556
|
+
function provideNativeDateAdapter(formats = CUTE_NATIVE_DATE_FORMATS) {
|
|
557
|
+
return [
|
|
558
|
+
{ provide: DateAdapter, useClass: NativeDateAdapter },
|
|
559
|
+
{ provide: CUTE_DATE_FORMATS, useValue: formats },
|
|
560
|
+
];
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* Generated bundle index. Do not edit.
|
|
565
|
+
*/
|
|
566
|
+
|
|
567
|
+
export { CUTE_DATE_FORMATS, CUTE_DATE_LOCALE, CUTE_DATE_LOCALE_FACTORY, CUTE_NATIVE_DATE_FORMATS, CuteNativeDateModule, DateAdapter, NativeDateAdapter, NativeDateModule, provideNativeDateAdapter };
|
|
568
|
+
//# sourceMappingURL=cute-widgets-base-core-datetime.mjs.map
|