mapa-library-ui 1.5.0 → 1.5.2

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.
@@ -22,7 +22,7 @@ import * as i3$1 from '@angular/router';
22
22
  import { RouterModule } from '@angular/router';
23
23
  import * as i1$1 from '@angular/platform-browser';
24
24
  import * as i1$2 from '@angular/common/http';
25
- import { getMapaUiTexts, getIntlLocale, getStoredAppLanguage } from 'mapa-frontend-i18n';
25
+ import { getMapaUiTexts, getStoredAppLanguage, getIntlLocale } from 'mapa-frontend-i18n';
26
26
 
27
27
  class BubblePaginationDirective {
28
28
  constructor(matPag, elementRef, ren) {
@@ -490,6 +490,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.21", ngImpo
490
490
  }] }] });
491
491
 
492
492
  const DAY_MONTH_YEAR_PATTERN = /^(\d{2})\/(\d{2})\/(\d{4})$/;
493
+ const MONTH_DAY_YEAR_PATTERN = /^(\d{2})\/(\d{2})\/(\d{4})$/;
494
+ const DOCS_LANGUAGE_STORAGE_KEY = "mapa-library-ui-docs-language";
493
495
  function isValidDate(date) {
494
496
  return !Number.isNaN(date.getTime());
495
497
  }
@@ -502,7 +504,93 @@ function formatDateAsDayMonthYear(date) {
502
504
  const year = `${date.getFullYear()}`;
503
505
  return `${day}/${month}/${year}`;
504
506
  }
505
- function parseDateValue(value) {
507
+ function formatDateAsMonthDayYear(date) {
508
+ const day = `${date.getDate()}`.padStart(2, "0");
509
+ const month = `${date.getMonth() + 1}`.padStart(2, "0");
510
+ const year = `${date.getFullYear()}`;
511
+ return `${month}/${day}/${year}`;
512
+ }
513
+ function normalizeDateLocale(value) {
514
+ if (typeof value !== "string") {
515
+ return "pt-BR";
516
+ }
517
+ const normalizedValue = value.trim().toLowerCase();
518
+ if (normalizedValue.startsWith("en")) {
519
+ return "en";
520
+ }
521
+ if (normalizedValue.startsWith("es")) {
522
+ return "es";
523
+ }
524
+ return "pt-BR";
525
+ }
526
+ function getDocsStoredLanguage() {
527
+ if (typeof window === "undefined") {
528
+ return null;
529
+ }
530
+ try {
531
+ return window.localStorage.getItem(DOCS_LANGUAGE_STORAGE_KEY);
532
+ }
533
+ catch {
534
+ return null;
535
+ }
536
+ }
537
+ function getActiveDateLocale() {
538
+ return normalizeDateLocale(getDocsStoredLanguage() ?? getStoredAppLanguage());
539
+ }
540
+ function isMonthFirstDateLocale(locale = getActiveDateLocale()) {
541
+ return normalizeDateLocale(locale) === "en";
542
+ }
543
+ function getActiveDateFormat(locale = getActiveDateLocale()) {
544
+ return isMonthFirstDateLocale(locale) ? "MM/DD/YYYY" : "DD/MM/YYYY";
545
+ }
546
+ function getActiveMaterialDateFormat(locale = getActiveDateLocale()) {
547
+ return isMonthFirstDateLocale(locale) ? "MM/dd/yyyy" : "dd/MM/yyyy";
548
+ }
549
+ function getDateInputMask(_locale = getActiveDateLocale()) {
550
+ return "00/00/0000";
551
+ }
552
+ function formatDateForLocale(date, locale = getActiveDateLocale()) {
553
+ return isMonthFirstDateLocale(locale)
554
+ ? formatDateAsMonthDayYear(date)
555
+ : formatDateAsDayMonthYear(date);
556
+ }
557
+ function parseOrderedDate(value, pattern, order) {
558
+ const match = pattern.exec(value.trim());
559
+ if (!match) {
560
+ return null;
561
+ }
562
+ const [, firstValue, secondValue, yearValue] = match;
563
+ const year = Number(yearValue);
564
+ const month = Number(order === "month-first" ? firstValue : secondValue);
565
+ const day = Number(order === "month-first" ? secondValue : firstValue);
566
+ const parsedDate = new Date(year, month - 1, day);
567
+ if (parsedDate.getFullYear() !== year ||
568
+ parsedDate.getMonth() !== month - 1 ||
569
+ parsedDate.getDate() !== day) {
570
+ return null;
571
+ }
572
+ return parsedDate;
573
+ }
574
+ function parseLocaleDateValue(value, locale = getActiveDateLocale()) {
575
+ const normalizedLocale = normalizeDateLocale(locale);
576
+ const parsers = normalizedLocale === "en"
577
+ ? [
578
+ () => parseOrderedDate(value, MONTH_DAY_YEAR_PATTERN, "month-first"),
579
+ () => parseOrderedDate(value, DAY_MONTH_YEAR_PATTERN, "day-first"),
580
+ ]
581
+ : [
582
+ () => parseOrderedDate(value, DAY_MONTH_YEAR_PATTERN, "day-first"),
583
+ () => parseOrderedDate(value, MONTH_DAY_YEAR_PATTERN, "month-first"),
584
+ ];
585
+ for (const parse of parsers) {
586
+ const parsedDate = parse();
587
+ if (parsedDate) {
588
+ return parsedDate;
589
+ }
590
+ }
591
+ return null;
592
+ }
593
+ function parseDateValue(value, locale = getActiveDateLocale()) {
506
594
  if (value instanceof Date) {
507
595
  return isValidDate(value) ? new Date(value.getTime()) : null;
508
596
  }
@@ -517,11 +605,11 @@ function parseDateValue(value) {
517
605
  if (!trimmedValue) {
518
606
  return null;
519
607
  }
520
- const brazilianDate = parseBrazilianDate(trimmedValue);
521
- if (brazilianDate) {
522
- return brazilianDate;
608
+ const localeDate = parseLocaleDateValue(trimmedValue, locale);
609
+ if (localeDate) {
610
+ return localeDate;
523
611
  }
524
- if (DAY_MONTH_YEAR_PATTERN.test(trimmedValue)) {
612
+ if (DAY_MONTH_YEAR_PATTERN.test(trimmedValue) || MONTH_DAY_YEAR_PATTERN.test(trimmedValue)) {
525
613
  return null;
526
614
  }
527
615
  const parsedDate = new Date(trimmedValue);
@@ -531,21 +619,7 @@ function isDateValue(value) {
531
619
  return parseDateValue(value) !== null;
532
620
  }
533
621
  function parseBrazilianDate(value) {
534
- const match = DAY_MONTH_YEAR_PATTERN.exec(value.trim());
535
- if (!match) {
536
- return null;
537
- }
538
- const [, dayValue, monthValue, yearValue] = match;
539
- const day = Number(dayValue);
540
- const month = Number(monthValue);
541
- const year = Number(yearValue);
542
- const parsedDate = new Date(year, month - 1, day);
543
- if (parsedDate.getFullYear() !== year ||
544
- parsedDate.getMonth() !== month - 1 ||
545
- parsedDate.getDate() !== day) {
546
- return null;
547
- }
548
- return parsedDate;
622
+ return parseOrderedDate(value, DAY_MONTH_YEAR_PATTERN, "day-first");
549
623
  }
550
624
  function normalizeDateInput(value) {
551
625
  return parseDateValue(value);
@@ -564,7 +638,7 @@ function formatLocaleDate(value, dateStyle = "short") {
564
638
  if (!date) {
565
639
  return "";
566
640
  }
567
- return new Intl.DateTimeFormat(getIntlLocale(getStoredAppLanguage()), {
641
+ return new Intl.DateTimeFormat(getIntlLocale(getActiveDateLocale()), {
568
642
  dateStyle,
569
643
  }).format(date);
570
644
  }
@@ -574,7 +648,7 @@ function formatLocaleDateTime(value, options = {}) {
574
648
  return "";
575
649
  }
576
650
  const { dateStyle = "short", timeStyle = "short" } = options;
577
- return new Intl.DateTimeFormat(getIntlLocale(getStoredAppLanguage()), {
651
+ return new Intl.DateTimeFormat(getIntlLocale(getActiveDateLocale()), {
578
652
  dateStyle,
579
653
  timeStyle,
580
654
  }).format(date);