@povio/ui 3.3.0-rc.2 → 3.3.0-rc.4

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 (33) hide show
  1. package/dist/components/buttons/Button/button.cva.d.ts +1 -1
  2. package/dist/components/inputs/Checkbox/CheckboxGroup.d.ts +5 -1
  3. package/dist/components/inputs/Checkbox/CheckboxGroup.js +234 -201
  4. package/dist/components/inputs/DateTime/DateRangePicker/DateRangePicker.d.ts +1 -0
  5. package/dist/components/inputs/DateTime/DateRangePicker/DateRangePicker.js +142 -127
  6. package/dist/components/inputs/DateTime/DateTimePicker/DateTimePicker.js +2 -17
  7. package/dist/components/inputs/DateTime/shared/DateField.js +92 -87
  8. package/dist/components/inputs/DateTime/shared/DatePickerInput.js +2 -0
  9. package/dist/components/inputs/DateTime/shared/TimePickerInput.js +144 -134
  10. package/dist/components/inputs/DateTime/shared/useFirefoxDateSegmentSelectionGuard.d.ts +2 -0
  11. package/dist/components/inputs/DateTime/shared/useFirefoxDateSegmentSelectionGuard.js +33 -0
  12. package/dist/components/inputs/Input/NumberInput/NumberInput.js +2 -1
  13. package/dist/components/inputs/Input/NumberRangeInput/NumberRangeInput.js +2 -1
  14. package/dist/components/inputs/Selection/Autocomplete/QueryAutocomplete.js +56 -2
  15. package/dist/components/inputs/Selection/Select/QuerySelect.js +69 -15
  16. package/dist/components/inputs/Selection/Select/Select.js +3 -3
  17. package/dist/components/inputs/Selection/shared/querySelect.utils.d.ts +1 -0
  18. package/dist/components/inputs/Selection/shared/querySelect.utils.js +1 -0
  19. package/dist/components/inputs/Selection/shared/select.context.js +19 -9
  20. package/dist/components/inputs/Skeleton/InputFrame.js +156 -154
  21. package/dist/components/inputs/shared/input.cva.js +1 -1
  22. package/dist/components/shared/pagination/minWidth.cva.d.ts +1 -1
  23. package/dist/config/uiConfig.context.d.ts +1 -0
  24. package/dist/config/uiConfig.context.js +2 -1
  25. package/dist/helpers/dynamicColumns.js +2 -1
  26. package/dist/index.d.ts +1 -0
  27. package/dist/index.js +2 -1
  28. package/dist/utils/date-time.utils.d.ts +0 -1
  29. package/dist/utils/date-time.utils.js +21 -45
  30. package/dist/utils/intl.utils.d.ts +7 -0
  31. package/dist/utils/intl.utils.js +38 -0
  32. package/dist/utils/intl.utils.spec.d.ts +1 -0
  33. package/package.json +1 -1
@@ -1,3 +1,4 @@
1
+ import { IntlUtils } from "./intl.utils.js";
1
2
  import { CalendarDate, CalendarDateTime, DateFormatter, fromDate, getLocalTimeZone, parseAbsolute } from "@internationalized/date";
2
3
  import { DateTime } from "luxon";
3
4
  //#region src/utils/date-time.utils.ts
@@ -5,33 +6,42 @@ var DateTimeUtils;
5
6
  (function(_DateTimeUtils) {
6
7
  const DATE_SAMPLE_DATE_UTC = new Date(Date.UTC(2e3, 10, 22));
7
8
  const TIME_SAMPLE_DATE_UTC = new Date(Date.UTC(2e3, 10, 22, 6, 45));
9
+ const timeFormatters = /* @__PURE__ */ new Map();
8
10
  const getDayMonthFormat = (shouldForceLeadingZeros = false) => shouldForceLeadingZeros ? "2-digit" : "numeric";
9
11
  const getTimeHourFormat = (shouldForceLeadingZeros = false) => shouldForceLeadingZeros ? "2-digit" : "numeric";
10
- const getDatePlaceholderFormatter = (locale, options) => new Intl.DateTimeFormat(locale, {
12
+ const getDatePlaceholderFormatter = (locale, options) => IntlUtils.getDateTimeFormatter(locale, {
11
13
  day: getDayMonthFormat(options?.shouldForceLeadingZeros),
12
14
  month: getDayMonthFormat(options?.shouldForceLeadingZeros),
13
15
  year: "numeric"
14
16
  });
15
- const getTimePlaceholderFormatter = (locale) => new Intl.DateTimeFormat(locale, {
17
+ const getTimePlaceholderFormatter = (locale) => IntlUtils.getDateTimeFormatter(locale, {
16
18
  hour: "2-digit",
17
19
  minute: "2-digit"
18
20
  });
19
21
  const getResolvedLocale = (locale) => {
20
22
  if (locale) return locale;
21
- return new Intl.DateTimeFormat().resolvedOptions().locale;
23
+ return IntlUtils.getDateTimeFormatter().resolvedOptions().locale;
22
24
  };
23
- const getDateFormatter = (locale, options) => new Intl.DateTimeFormat(getResolvedLocale(locale), {
25
+ const getDateFormatter = (locale, options) => IntlUtils.getDateTimeFormatter(getResolvedLocale(locale), {
24
26
  day: getDayMonthFormat(options?.shouldForceLeadingZeros),
25
27
  month: getDayMonthFormat(options?.shouldForceLeadingZeros),
26
28
  year: "numeric",
27
29
  timeZone: "UTC"
28
30
  });
29
- const getTimeFormatter = (locale, options) => new DateFormatter(getResolvedLocale(locale), {
30
- hour: getTimeHourFormat(options?.shouldForceLeadingZeros),
31
- minute: "2-digit",
32
- timeZone: "UTC"
33
- });
34
- const getDateTimeFormatter = (locale, options) => new Intl.DateTimeFormat(getResolvedLocale(locale), {
31
+ const getTimeFormatter = (locale, options) => {
32
+ const resolvedLocale = getResolvedLocale(locale);
33
+ const key = `${resolvedLocale}|${options?.shouldForceLeadingZeros ?? false}`;
34
+ const cachedFormatter = timeFormatters.get(key);
35
+ if (cachedFormatter) return cachedFormatter;
36
+ const formatter = new DateFormatter(resolvedLocale, {
37
+ hour: getTimeHourFormat(options?.shouldForceLeadingZeros),
38
+ minute: "2-digit",
39
+ timeZone: "UTC"
40
+ });
41
+ timeFormatters.set(key, formatter);
42
+ return formatter;
43
+ };
44
+ const getDateTimeFormatter = (locale, options) => IntlUtils.getDateTimeFormatter(getResolvedLocale(locale), {
35
45
  day: getDayMonthFormat(options?.shouldForceLeadingZeros),
36
46
  month: getDayMonthFormat(options?.shouldForceLeadingZeros),
37
47
  year: "numeric",
@@ -39,22 +49,8 @@ var DateTimeUtils;
39
49
  minute: "2-digit",
40
50
  timeZone: "UTC"
41
51
  });
42
- const getLocaleDateFormat = (locale) => {
43
- const sampleDate = new Date(Date.UTC(2e3, 10, 22));
44
- return new Intl.DateTimeFormat(locale, {
45
- day: "2-digit",
46
- month: "2-digit",
47
- year: "numeric",
48
- timeZone: "UTC"
49
- }).formatToParts(sampleDate).map((part) => {
50
- if (part.type === "day") return "dd";
51
- if (part.type === "month") return "MM";
52
- if (part.type === "year") return "yyyy";
53
- return part.value;
54
- }).join("");
55
- };
56
52
  const repeatLocalizedFieldLabel = (type, length, locale) => {
57
- const placeholderChar = new Intl.DisplayNames(getResolvedLocale(locale), { type: "dateTimeField" }).of(type)?.trim().charAt(0).toLocaleLowerCase(getResolvedLocale(locale));
53
+ const placeholderChar = IntlUtils.getDisplayNamesFormatter(getResolvedLocale(locale), { type: "dateTimeField" }).of(type)?.trim().charAt(0).toLocaleLowerCase(getResolvedLocale(locale));
58
54
  if (!placeholderChar) return null;
59
55
  return placeholderChar.repeat(length);
60
56
  };
@@ -191,26 +187,6 @@ var DateTimeUtils;
191
187
  return new CalendarDateTime(zonedDateTime.year, zonedDateTime.month, zonedDateTime.day, zonedDateTime.hour, zonedDateTime.minute, zonedDateTime.second, zonedDateTime.millisecond);
192
188
  }
193
189
  _DateTimeUtils.fromUTCISOToCalendarDateTime = fromUTCISOToCalendarDateTime;
194
- function formatTextDateToCalendarDateTime(textDate, timeZone, locale) {
195
- if (!textDate?.includes("hh")) return null;
196
- const datePart = textDate.split(",").at(0)?.trim();
197
- if (!datePart) return null;
198
- const resolvedTimeZone = resolveTimeZone(timeZone);
199
- const resolvedLocale = locale || Intl.DateTimeFormat().resolvedOptions().locale;
200
- const localeDateFormat = getLocaleDateFormat(resolvedLocale);
201
- const parseOptions = {
202
- zone: resolvedTimeZone,
203
- locale: resolvedLocale
204
- };
205
- let parsedDateTime = DateTime.fromFormat(datePart, localeDateFormat, parseOptions);
206
- if (!parsedDateTime.isValid && localeDateFormat.includes("yyyy")) {
207
- const shortYearFormat = localeDateFormat.replace("yyyy", "yy");
208
- parsedDateTime = DateTime.fromFormat(datePart, shortYearFormat, parseOptions);
209
- }
210
- if (!parsedDateTime.isValid) return null;
211
- return new CalendarDateTime(parsedDateTime.year, parsedDateTime.month, parsedDateTime.day, 0, 0, 0, 0);
212
- }
213
- _DateTimeUtils.formatTextDateToCalendarDateTime = formatTextDateToCalendarDateTime;
214
190
  })(DateTimeUtils || (DateTimeUtils = {}));
215
191
  //#endregion
216
192
  export { DateTimeUtils };
@@ -0,0 +1,7 @@
1
+ type IntlLocale = Intl.LocalesArgument;
2
+ export declare namespace IntlUtils {
3
+ const getDateTimeFormatter: (locale?: IntlLocale, options?: Intl.DateTimeFormatOptions) => Intl.DateTimeFormat;
4
+ const getDisplayNamesFormatter: (locale: IntlLocale, options: Intl.DisplayNamesOptions) => Intl.DisplayNames;
5
+ const getNumberFormatter: (locale?: IntlLocale, options?: Intl.NumberFormatOptions) => Intl.NumberFormat;
6
+ }
7
+ export {};
@@ -0,0 +1,38 @@
1
+ //#region src/utils/intl.utils.ts
2
+ var formatterCacheKey = (locale, options) => {
3
+ const locales = Array.isArray(locale) ? locale.map(String) : locale ? [String(locale)] : [];
4
+ const normalizedOptions = Object.entries(options ?? {}).sort(([left], [right]) => left.localeCompare(right));
5
+ return JSON.stringify([locales, normalizedOptions]);
6
+ };
7
+ var IntlUtils;
8
+ (function(_IntlUtils) {
9
+ const dateTimeFormatters = /* @__PURE__ */ new Map();
10
+ const displayNamesFormatters = /* @__PURE__ */ new Map();
11
+ const numberFormatters = /* @__PURE__ */ new Map();
12
+ _IntlUtils.getDateTimeFormatter = (locale, options) => {
13
+ const key = formatterCacheKey(locale, options);
14
+ const cachedFormatter = dateTimeFormatters.get(key);
15
+ if (cachedFormatter) return cachedFormatter;
16
+ const formatter = new Intl.DateTimeFormat(locale, options);
17
+ dateTimeFormatters.set(key, formatter);
18
+ return formatter;
19
+ };
20
+ _IntlUtils.getDisplayNamesFormatter = (locale, options) => {
21
+ const key = formatterCacheKey(locale, options);
22
+ const cachedFormatter = displayNamesFormatters.get(key);
23
+ if (cachedFormatter) return cachedFormatter;
24
+ const formatter = new Intl.DisplayNames(locale, options);
25
+ displayNamesFormatters.set(key, formatter);
26
+ return formatter;
27
+ };
28
+ _IntlUtils.getNumberFormatter = (locale, options) => {
29
+ const key = formatterCacheKey(locale, options);
30
+ const cachedFormatter = numberFormatters.get(key);
31
+ if (cachedFormatter) return cachedFormatter;
32
+ const formatter = new Intl.NumberFormat(locale, options);
33
+ numberFormatters.set(key, formatter);
34
+ return formatter;
35
+ };
36
+ })(IntlUtils || (IntlUtils = {}));
37
+ //#endregion
38
+ export { IntlUtils };
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@povio/ui",
3
- "version": "3.3.0-rc.2",
3
+ "version": "3.3.0-rc.4",
4
4
  "type": "module",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",