@dloizides/ui-forms 1.44.1 → 1.45.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/dist/index.mjs CHANGED
@@ -2694,8 +2694,86 @@ function monthStart(iso) {
2694
2694
  return `${iso.slice(0, MONTH_PREFIX)}-01`;
2695
2695
  }
2696
2696
 
2697
- // src/DatePicker/utils/weekStart.ts
2697
+ // src/DatePicker/utils/formatDate.ts
2698
+ var SAMPLE_UTC = Date.UTC(2027, 5, 12);
2699
+ var TWO_DIGIT_YEAR = 100;
2700
+ var CENTURY = 2e3;
2701
+ var PART_COUNT = 3;
2702
+ var PAD3 = 2;
2698
2703
  var MONDAY2 = 1;
2704
+ var ISO_LIKE = /^\d{4}-\d{1,2}-\d{1,2}$/;
2705
+ var MONTH_INDEXES = Array.from({ length: 12 }, (_unused, index) => index);
2706
+ var WEEK_OFFSETS = Array.from({ length: 7 }, (_unused, index) => index);
2707
+ var UTC = "UTC";
2708
+ var PART_OF = { day: "day" /* Day */, month: "month" /* Month */, year: "year" /* Year */ };
2709
+ function utcOf(iso) {
2710
+ const parts = parseIso(iso);
2711
+ return parts === null ? null : new Date(Date.UTC(parts.year, parts.month - 1, parts.day));
2712
+ }
2713
+ function formatWith(iso, locale, options) {
2714
+ const date = utcOf(iso);
2715
+ if (date === null) return iso;
2716
+ return new Intl.DateTimeFormat(locale, { ...options, timeZone: UTC }).format(date).replace(/,/g, "");
2717
+ }
2718
+ function formatDisplay(iso, locale) {
2719
+ return formatWith(iso, locale, { weekday: "short", day: "numeric", month: "short", year: "numeric" });
2720
+ }
2721
+ function formatShort(iso, locale, withYear = true) {
2722
+ return formatWith(iso, locale, withYear ? { day: "numeric", month: "short", year: "numeric" } : { day: "numeric", month: "short" });
2723
+ }
2724
+ function formatMonthYear(iso, locale) {
2725
+ return formatWith(iso, locale, { month: "long", year: "numeric" });
2726
+ }
2727
+ function monthNames(locale) {
2728
+ const format = new Intl.DateTimeFormat(locale, { month: "long", timeZone: UTC });
2729
+ return MONTH_INDEXES.map((month) => format.format(new Date(Date.UTC(2024, month, 1))));
2730
+ }
2731
+ function weekdayNames(locale, firstDay = MONDAY2) {
2732
+ const format = new Intl.DateTimeFormat(locale, { weekday: "short", timeZone: UTC });
2733
+ return WEEK_OFFSETS.map((offset) => format.format(new Date(Date.UTC(2024, 0, firstDay + offset))));
2734
+ }
2735
+ function typedOrder(locale) {
2736
+ const parts = new Intl.DateTimeFormat(locale, { day: "numeric", month: "numeric", year: "numeric", timeZone: UTC }).formatToParts(new Date(SAMPLE_UTC));
2737
+ return parts.map((part) => PART_OF[part.type]).filter((part) => part !== void 0);
2738
+ }
2739
+ function formatTyped(iso, locale) {
2740
+ const parts = parseIso(iso);
2741
+ if (parts === null) return iso;
2742
+ const text = {
2743
+ ["day" /* Day */]: String(parts.day).padStart(PAD3, "0"),
2744
+ ["month" /* Month */]: String(parts.month).padStart(PAD3, "0"),
2745
+ ["year" /* Year */]: String(parts.year)
2746
+ };
2747
+ return typedOrder(locale).map((part) => text[part]).join("/");
2748
+ }
2749
+ function parseTyped(text, locale) {
2750
+ const trimmed = text.trim();
2751
+ if (ISO_LIKE.test(trimmed)) {
2752
+ const [year = 0, month = 0, day = 0] = trimmed.split("-").map(Number);
2753
+ const parts2 = { year, month, day };
2754
+ return isValidParts(parts2) ? toIso(parts2) : null;
2755
+ }
2756
+ const numbers2 = trimmed.split(/\D+/).filter((piece) => piece !== "").map(Number);
2757
+ if (numbers2.length !== PART_COUNT) return null;
2758
+ const order = typedOrder(locale);
2759
+ const read = (part) => numbers2[order.indexOf(part)] ?? 0;
2760
+ const rawYear = read("year" /* Year */);
2761
+ const parts = { year: rawYear < TWO_DIGIT_YEAR ? CENTURY + rawYear : rawYear, month: read("month" /* Month */), day: read("day" /* Day */) };
2762
+ return isValidParts(parts) ? toIso(parts) : null;
2763
+ }
2764
+
2765
+ // src/DatePicker/utils/DateDisplay.ts
2766
+ var DateDisplay = /* @__PURE__ */ ((DateDisplay2) => {
2767
+ DateDisplay2["Long"] = "long";
2768
+ DateDisplay2["Numeric"] = "numeric";
2769
+ return DateDisplay2;
2770
+ })(DateDisplay || {});
2771
+ function displayFormatter(display) {
2772
+ return display === "numeric" /* Numeric */ ? formatTyped : formatDisplay;
2773
+ }
2774
+
2775
+ // src/DatePicker/utils/weekStart.ts
2776
+ var MONDAY3 = 1;
2699
2777
  var SUNDAY2 = 7;
2700
2778
  var SUNDAY_REGIONS = /* @__PURE__ */ new Set(["US", "CA", "MX", "BR", "JP", "KR", "TW", "HK", "IL", "PH", "IN", "ZA", "SA", "PE", "CO", "VE", "GT", "HN", "PA", "PR", "DO", "SV", "TH", "ID"]);
2701
2779
  function weekFirstDay(locale) {
@@ -2704,20 +2782,20 @@ function weekFirstDay(locale) {
2704
2782
  const info = resolved;
2705
2783
  const first = info.getWeekInfo?.().firstDay ?? info.weekInfo?.firstDay;
2706
2784
  if (first !== void 0) return first;
2707
- return SUNDAY_REGIONS.has(resolved.maximize().region ?? "") ? SUNDAY2 : MONDAY2;
2785
+ return SUNDAY_REGIONS.has(resolved.maximize().region ?? "") ? SUNDAY2 : MONDAY3;
2708
2786
  } catch {
2709
- return MONDAY2;
2787
+ return MONDAY3;
2710
2788
  }
2711
2789
  }
2712
2790
  var DatePickerContext = createContext({ labels: DEFAULT_DATE_PICKER_LABELS });
2713
- function DatePickerProvider({ labels, locale, today, children }) {
2714
- const value = useMemo(() => ({ labels: { ...DEFAULT_DATE_PICKER_LABELS, ...labels }, locale, today }), [labels, locale, today]);
2791
+ function DatePickerProvider({ labels, locale, today, display, children }) {
2792
+ const value = useMemo(() => ({ labels: { ...DEFAULT_DATE_PICKER_LABELS, ...labels }, locale, today, display }), [labels, locale, today, display]);
2715
2793
  return /* @__PURE__ */ jsx(DatePickerContext.Provider, { value, children });
2716
2794
  }
2717
2795
  function useDatePickerConfig() {
2718
2796
  const config = useContext(DatePickerContext);
2719
2797
  const firstDay = useMemo(() => weekFirstDay(config.locale), [config.locale]);
2720
- return { labels: config.labels, locale: config.locale, today: config.today ?? todayIso(), firstDay };
2798
+ return { labels: config.labels, locale: config.locale, today: config.today ?? todayIso(), firstDay, display: config.display ?? "long" /* Long */ };
2721
2799
  }
2722
2800
 
2723
2801
  // src/DatePicker/utils/motionStyles.ts
@@ -2762,14 +2840,14 @@ function PickerSurface({ anchorRef, phone, minWidth, label, testID, onDismiss, c
2762
2840
  // src/DatePicker/utils/calendarKeys.ts
2763
2841
  var DAYS_IN_WEEK2 = 7;
2764
2842
  var MONTHS_IN_YEAR2 = 12;
2765
- var MONDAY3 = 1;
2843
+ var MONDAY4 = 1;
2766
2844
  var DAY_STEPS = {
2767
2845
  ArrowLeft: -1,
2768
2846
  ArrowRight: 1,
2769
2847
  ArrowUp: -DAYS_IN_WEEK2,
2770
2848
  ArrowDown: DAYS_IN_WEEK2
2771
2849
  };
2772
- function nextFocusDay(iso, key, shiftKey = false, firstDay = MONDAY3) {
2850
+ function nextFocusDay(iso, key, shiftKey = false, firstDay = MONDAY4) {
2773
2851
  const step = DAY_STEPS[key];
2774
2852
  if (step !== void 0) return addDays(iso, step);
2775
2853
  const monthStep = shiftKey ? MONTHS_IN_YEAR2 : 1;
@@ -2857,74 +2935,6 @@ function DayCell({ iso, state, testID, label, hint, onPick, onKey }) {
2857
2935
  ) });
2858
2936
  }
2859
2937
 
2860
- // src/DatePicker/utils/formatDate.ts
2861
- var SAMPLE_UTC = Date.UTC(2027, 5, 12);
2862
- var TWO_DIGIT_YEAR = 100;
2863
- var CENTURY = 2e3;
2864
- var PART_COUNT = 3;
2865
- var PAD3 = 2;
2866
- var MONDAY4 = 1;
2867
- var ISO_LIKE = /^\d{4}-\d{1,2}-\d{1,2}$/;
2868
- var MONTH_INDEXES = Array.from({ length: 12 }, (_unused, index) => index);
2869
- var WEEK_OFFSETS = Array.from({ length: 7 }, (_unused, index) => index);
2870
- var UTC = "UTC";
2871
- var PART_OF = { day: "day" /* Day */, month: "month" /* Month */, year: "year" /* Year */ };
2872
- function utcOf(iso) {
2873
- const parts = parseIso(iso);
2874
- return parts === null ? null : new Date(Date.UTC(parts.year, parts.month - 1, parts.day));
2875
- }
2876
- function formatWith(iso, locale, options) {
2877
- const date = utcOf(iso);
2878
- if (date === null) return iso;
2879
- return new Intl.DateTimeFormat(locale, { ...options, timeZone: UTC }).format(date).replace(/,/g, "");
2880
- }
2881
- function formatDisplay(iso, locale) {
2882
- return formatWith(iso, locale, { weekday: "short", day: "numeric", month: "short", year: "numeric" });
2883
- }
2884
- function formatShort(iso, locale, withYear = true) {
2885
- return formatWith(iso, locale, withYear ? { day: "numeric", month: "short", year: "numeric" } : { day: "numeric", month: "short" });
2886
- }
2887
- function formatMonthYear(iso, locale) {
2888
- return formatWith(iso, locale, { month: "long", year: "numeric" });
2889
- }
2890
- function monthNames(locale) {
2891
- const format = new Intl.DateTimeFormat(locale, { month: "long", timeZone: UTC });
2892
- return MONTH_INDEXES.map((month) => format.format(new Date(Date.UTC(2024, month, 1))));
2893
- }
2894
- function weekdayNames(locale, firstDay = MONDAY4) {
2895
- const format = new Intl.DateTimeFormat(locale, { weekday: "short", timeZone: UTC });
2896
- return WEEK_OFFSETS.map((offset) => format.format(new Date(Date.UTC(2024, 0, firstDay + offset))));
2897
- }
2898
- function typedOrder(locale) {
2899
- const parts = new Intl.DateTimeFormat(locale, { day: "numeric", month: "numeric", year: "numeric", timeZone: UTC }).formatToParts(new Date(SAMPLE_UTC));
2900
- return parts.map((part) => PART_OF[part.type]).filter((part) => part !== void 0);
2901
- }
2902
- function formatTyped(iso, locale) {
2903
- const parts = parseIso(iso);
2904
- if (parts === null) return iso;
2905
- const text = {
2906
- ["day" /* Day */]: String(parts.day).padStart(PAD3, "0"),
2907
- ["month" /* Month */]: String(parts.month).padStart(PAD3, "0"),
2908
- ["year" /* Year */]: String(parts.year)
2909
- };
2910
- return typedOrder(locale).map((part) => text[part]).join("/");
2911
- }
2912
- function parseTyped(text, locale) {
2913
- const trimmed = text.trim();
2914
- if (ISO_LIKE.test(trimmed)) {
2915
- const [year = 0, month = 0, day = 0] = trimmed.split("-").map(Number);
2916
- const parts2 = { year, month, day };
2917
- return isValidParts(parts2) ? toIso(parts2) : null;
2918
- }
2919
- const numbers2 = trimmed.split(/\D+/).filter((piece) => piece !== "").map(Number);
2920
- if (numbers2.length !== PART_COUNT) return null;
2921
- const order = typedOrder(locale);
2922
- const read = (part) => numbers2[order.indexOf(part)] ?? 0;
2923
- const rawYear = read("year" /* Year */);
2924
- const parts = { year: rawYear < TWO_DIGIT_YEAR ? CENTURY + rawYear : rawYear, month: read("month" /* Month */), day: read("day" /* Day */) };
2925
- return isValidParts(parts) ? toIso(parts) : null;
2926
- }
2927
-
2928
2938
  // src/DatePicker/utils/monthGrid.ts
2929
2939
  var DAYS_IN_WEEK3 = 7;
2930
2940
  var MONDAY5 = 1;
@@ -3190,13 +3200,13 @@ var ICON_SLOT = { position: "absolute", right: 2, top: 0, bottom: 0, display: "f
3190
3200
  var anchorStyles = StyleSheet.create({ wrap: { position: "relative", width: "100%" } });
3191
3201
  function DatePickerInput({ fieldProps, context, onTypedError }) {
3192
3202
  const { label, value, onChange, onSubmit, accessibilityHint, testID, required, disabled = false, min, max } = fieldProps;
3193
- const { labels } = useDatePickerConfig();
3203
+ const { labels, display } = useDatePickerConfig();
3194
3204
  const phone = useIsPhone();
3195
3205
  const [open, setOpen] = useState(false);
3196
3206
  const anchorRef = useRef(null);
3197
3207
  const inputRef = useRef(null);
3198
3208
  const bounds = { min, max };
3199
- const typed = useTypedDate({ value, onChange, bounds, format: formatDisplay, onError: onTypedError, editOnType: true });
3209
+ const typed = useTypedDate({ value, onChange, bounds, format: displayFormatter(display), onError: onTypedError, editOnType: true });
3200
3210
  const edit = typedEditBind(typed);
3201
3211
  const { style, focusBind, hoverBind } = useThemedInput({ hasError: context.hasError, editable: !disabled });
3202
3212
  const focus = focusBind;
@@ -5736,6 +5746,6 @@ function DecisionPanel(props) {
5736
5746
  ] });
5737
5747
  }
5738
5748
 
5739
- export { ActionBar, AddOnRequest, AlignToControl, AnchoredMenu, BicInput, BicRejection, COUNTRIES, ChipLabelWrap, ChipSelector, CountryField, CountryFlag, DEFAULT_DATE_PICKER_LABELS, DEFAULT_MAX_RECENTS, DEFAULT_OPTIONAL_LABEL, DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, DEFAULT_TYPEAHEAD_MIN_CHARS, DateField, DateInput, DatePickerProvider, DateRangeControl, DateTimeField, DecisionPanel, DropdownPlacement, FLAG_HEIGHT, FLAG_WIDTH, Field, FileInput, FixBar, FlagShapeKind, FormActions, FormCell, FormCheckbox, FormField, FormGrid, FormSection, FormStack, FormStatusLine, FormSwitch, GatedChecklist, IBAN_MAX_LENGTH, IBAN_REGISTERED_COUNTRY_COUNT, INLINE_FIELD_ROW_MIN_WIDTH, IbanInput, IbanRejection, InlineFieldRow, LINE_ITEMS_WIDE_MIN_WIDTH, LineItems, PHONE_MAX_WIDTH, RESPONSIVE_FORM_DEFAULT_BREAKPOINT, RadioList, ResponsiveFormLayout, SEGMENT_BESIDE_FIELD, SEGMENT_BESIDE_TEXT_INPUT, SearchSelect, SelectControl, SelectField, SelectSurface, StepperNav, StepperTabs, ThemedTextInput, TypeaheadControl, UploadWithLinkField, actionBarPosition, buildSearchSelectSections, canRemoveLine, controlStyles, countryFieldOptions, countryFlag, countryOptions, defaultDecisionVariant, draftBic, draftIban, dropdownFrame, findOption, fitDropdownWidth, flagShapes, groupAriaChecked, groupInFours, highlightAfterQuery, ibanCounter, ibanLengthFor, inlineFieldRowLayout, isAddOnOpen, isChecklistComplete, isFallbackFlag, isFixBarVisible, isLineItemsWide, isOutside, isUnmatched, isWideFormLayout, leadFirst, lineItemColumnFlex, lineNumberOf, moveHighlight, nextHighlight, placeDropdown, radioRowIdentity, rejectionMessage, resolveGroupSelection, resolveSelectMotion, resolveStepNeighbours, rowsForText, suggestOptions, toCountryValue, toggleGroupSelection, useAutoGrowRows, useBlurVerdict, useDeferredFocus, useFocusFirstInvalid, useKeepInView, useOutsidePress, useRecentValues, useReducedMotion, useSearchSelectState, useThemedInput, validateBic, validateDecision, validateIban };
5749
+ export { ActionBar, AddOnRequest, AlignToControl, AnchoredMenu, BicInput, BicRejection, COUNTRIES, ChipLabelWrap, ChipSelector, CountryField, CountryFlag, DEFAULT_DATE_PICKER_LABELS, DEFAULT_MAX_RECENTS, DEFAULT_OPTIONAL_LABEL, DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, DEFAULT_TYPEAHEAD_MIN_CHARS, DateDisplay, DateField, DateInput, DatePickerProvider, DateRangeControl, DateTimeField, DecisionPanel, DropdownPlacement, FLAG_HEIGHT, FLAG_WIDTH, Field, FileInput, FixBar, FlagShapeKind, FormActions, FormCell, FormCheckbox, FormField, FormGrid, FormSection, FormStack, FormStatusLine, FormSwitch, GatedChecklist, IBAN_MAX_LENGTH, IBAN_REGISTERED_COUNTRY_COUNT, INLINE_FIELD_ROW_MIN_WIDTH, IbanInput, IbanRejection, InlineFieldRow, LINE_ITEMS_WIDE_MIN_WIDTH, LineItems, PHONE_MAX_WIDTH, RESPONSIVE_FORM_DEFAULT_BREAKPOINT, RadioList, ResponsiveFormLayout, SEGMENT_BESIDE_FIELD, SEGMENT_BESIDE_TEXT_INPUT, SearchSelect, SelectControl, SelectField, SelectSurface, StepperNav, StepperTabs, ThemedTextInput, TypeaheadControl, UploadWithLinkField, actionBarPosition, buildSearchSelectSections, canRemoveLine, controlStyles, countryFieldOptions, countryFlag, countryOptions, defaultDecisionVariant, draftBic, draftIban, dropdownFrame, findOption, fitDropdownWidth, flagShapes, groupAriaChecked, groupInFours, highlightAfterQuery, ibanCounter, ibanLengthFor, inlineFieldRowLayout, isAddOnOpen, isChecklistComplete, isFallbackFlag, isFixBarVisible, isLineItemsWide, isOutside, isUnmatched, isWideFormLayout, leadFirst, lineItemColumnFlex, lineNumberOf, moveHighlight, nextHighlight, placeDropdown, radioRowIdentity, rejectionMessage, resolveGroupSelection, resolveSelectMotion, resolveStepNeighbours, rowsForText, suggestOptions, toCountryValue, toggleGroupSelection, useAutoGrowRows, useBlurVerdict, useDeferredFocus, useFocusFirstInvalid, useKeepInView, useOutsidePress, useRecentValues, useReducedMotion, useSearchSelectState, useThemedInput, validateBic, validateDecision, validateIban };
5740
5750
  //# sourceMappingURL=index.mjs.map
5741
5751
  //# sourceMappingURL=index.mjs.map