@dloizides/ui-forms 1.44.1 → 1.46.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/CHANGELOG.md +7 -0
- package/dist/index.d.mts +117 -2
- package/dist/index.d.ts +117 -2
- package/dist/index.js +422 -78
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +413 -81
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -2
package/dist/index.js
CHANGED
|
@@ -8,7 +8,9 @@ var designTokens = require('@dloizides/design-tokens');
|
|
|
8
8
|
var uiButtons = require('@dloizides/ui-buttons');
|
|
9
9
|
var reactDom = require('react-dom');
|
|
10
10
|
var a11y = require('@dloizides/a11y');
|
|
11
|
+
var apiClientBase = require('@dloizides/api-client-base');
|
|
11
12
|
var Svg = require('react-native-svg');
|
|
13
|
+
var uiIcons = require('@dloizides/ui-icons');
|
|
12
14
|
|
|
13
15
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
16
|
|
|
@@ -2701,8 +2703,86 @@ function monthStart(iso) {
|
|
|
2701
2703
|
return `${iso.slice(0, MONTH_PREFIX)}-01`;
|
|
2702
2704
|
}
|
|
2703
2705
|
|
|
2704
|
-
// src/DatePicker/utils/
|
|
2706
|
+
// src/DatePicker/utils/formatDate.ts
|
|
2707
|
+
var SAMPLE_UTC = Date.UTC(2027, 5, 12);
|
|
2708
|
+
var TWO_DIGIT_YEAR = 100;
|
|
2709
|
+
var CENTURY = 2e3;
|
|
2710
|
+
var PART_COUNT = 3;
|
|
2711
|
+
var PAD3 = 2;
|
|
2705
2712
|
var MONDAY2 = 1;
|
|
2713
|
+
var ISO_LIKE = /^\d{4}-\d{1,2}-\d{1,2}$/;
|
|
2714
|
+
var MONTH_INDEXES = Array.from({ length: 12 }, (_unused, index) => index);
|
|
2715
|
+
var WEEK_OFFSETS = Array.from({ length: 7 }, (_unused, index) => index);
|
|
2716
|
+
var UTC = "UTC";
|
|
2717
|
+
var PART_OF = { day: "day" /* Day */, month: "month" /* Month */, year: "year" /* Year */ };
|
|
2718
|
+
function utcOf(iso) {
|
|
2719
|
+
const parts = parseIso(iso);
|
|
2720
|
+
return parts === null ? null : new Date(Date.UTC(parts.year, parts.month - 1, parts.day));
|
|
2721
|
+
}
|
|
2722
|
+
function formatWith(iso, locale, options) {
|
|
2723
|
+
const date = utcOf(iso);
|
|
2724
|
+
if (date === null) return iso;
|
|
2725
|
+
return new Intl.DateTimeFormat(locale, { ...options, timeZone: UTC }).format(date).replace(/,/g, "");
|
|
2726
|
+
}
|
|
2727
|
+
function formatDisplay(iso, locale) {
|
|
2728
|
+
return formatWith(iso, locale, { weekday: "short", day: "numeric", month: "short", year: "numeric" });
|
|
2729
|
+
}
|
|
2730
|
+
function formatShort(iso, locale, withYear = true) {
|
|
2731
|
+
return formatWith(iso, locale, withYear ? { day: "numeric", month: "short", year: "numeric" } : { day: "numeric", month: "short" });
|
|
2732
|
+
}
|
|
2733
|
+
function formatMonthYear(iso, locale) {
|
|
2734
|
+
return formatWith(iso, locale, { month: "long", year: "numeric" });
|
|
2735
|
+
}
|
|
2736
|
+
function monthNames(locale) {
|
|
2737
|
+
const format = new Intl.DateTimeFormat(locale, { month: "long", timeZone: UTC });
|
|
2738
|
+
return MONTH_INDEXES.map((month) => format.format(new Date(Date.UTC(2024, month, 1))));
|
|
2739
|
+
}
|
|
2740
|
+
function weekdayNames(locale, firstDay = MONDAY2) {
|
|
2741
|
+
const format = new Intl.DateTimeFormat(locale, { weekday: "short", timeZone: UTC });
|
|
2742
|
+
return WEEK_OFFSETS.map((offset) => format.format(new Date(Date.UTC(2024, 0, firstDay + offset))));
|
|
2743
|
+
}
|
|
2744
|
+
function typedOrder(locale) {
|
|
2745
|
+
const parts = new Intl.DateTimeFormat(locale, { day: "numeric", month: "numeric", year: "numeric", timeZone: UTC }).formatToParts(new Date(SAMPLE_UTC));
|
|
2746
|
+
return parts.map((part) => PART_OF[part.type]).filter((part) => part !== void 0);
|
|
2747
|
+
}
|
|
2748
|
+
function formatTyped(iso, locale) {
|
|
2749
|
+
const parts = parseIso(iso);
|
|
2750
|
+
if (parts === null) return iso;
|
|
2751
|
+
const text = {
|
|
2752
|
+
["day" /* Day */]: String(parts.day).padStart(PAD3, "0"),
|
|
2753
|
+
["month" /* Month */]: String(parts.month).padStart(PAD3, "0"),
|
|
2754
|
+
["year" /* Year */]: String(parts.year)
|
|
2755
|
+
};
|
|
2756
|
+
return typedOrder(locale).map((part) => text[part]).join("/");
|
|
2757
|
+
}
|
|
2758
|
+
function parseTyped(text, locale) {
|
|
2759
|
+
const trimmed = text.trim();
|
|
2760
|
+
if (ISO_LIKE.test(trimmed)) {
|
|
2761
|
+
const [year = 0, month = 0, day = 0] = trimmed.split("-").map(Number);
|
|
2762
|
+
const parts2 = { year, month, day };
|
|
2763
|
+
return isValidParts(parts2) ? toIso(parts2) : null;
|
|
2764
|
+
}
|
|
2765
|
+
const numbers2 = trimmed.split(/\D+/).filter((piece) => piece !== "").map(Number);
|
|
2766
|
+
if (numbers2.length !== PART_COUNT) return null;
|
|
2767
|
+
const order = typedOrder(locale);
|
|
2768
|
+
const read = (part) => numbers2[order.indexOf(part)] ?? 0;
|
|
2769
|
+
const rawYear = read("year" /* Year */);
|
|
2770
|
+
const parts = { year: rawYear < TWO_DIGIT_YEAR ? CENTURY + rawYear : rawYear, month: read("month" /* Month */), day: read("day" /* Day */) };
|
|
2771
|
+
return isValidParts(parts) ? toIso(parts) : null;
|
|
2772
|
+
}
|
|
2773
|
+
|
|
2774
|
+
// src/DatePicker/utils/DateDisplay.ts
|
|
2775
|
+
var DateDisplay = /* @__PURE__ */ ((DateDisplay2) => {
|
|
2776
|
+
DateDisplay2["Long"] = "long";
|
|
2777
|
+
DateDisplay2["Numeric"] = "numeric";
|
|
2778
|
+
return DateDisplay2;
|
|
2779
|
+
})(DateDisplay || {});
|
|
2780
|
+
function displayFormatter(display) {
|
|
2781
|
+
return display === "numeric" /* Numeric */ ? formatTyped : formatDisplay;
|
|
2782
|
+
}
|
|
2783
|
+
|
|
2784
|
+
// src/DatePicker/utils/weekStart.ts
|
|
2785
|
+
var MONDAY3 = 1;
|
|
2706
2786
|
var SUNDAY2 = 7;
|
|
2707
2787
|
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"]);
|
|
2708
2788
|
function weekFirstDay(locale) {
|
|
@@ -2711,20 +2791,20 @@ function weekFirstDay(locale) {
|
|
|
2711
2791
|
const info = resolved;
|
|
2712
2792
|
const first = info.getWeekInfo?.().firstDay ?? info.weekInfo?.firstDay;
|
|
2713
2793
|
if (first !== void 0) return first;
|
|
2714
|
-
return SUNDAY_REGIONS.has(resolved.maximize().region ?? "") ? SUNDAY2 :
|
|
2794
|
+
return SUNDAY_REGIONS.has(resolved.maximize().region ?? "") ? SUNDAY2 : MONDAY3;
|
|
2715
2795
|
} catch {
|
|
2716
|
-
return
|
|
2796
|
+
return MONDAY3;
|
|
2717
2797
|
}
|
|
2718
2798
|
}
|
|
2719
2799
|
var DatePickerContext = React37.createContext({ labels: DEFAULT_DATE_PICKER_LABELS });
|
|
2720
|
-
function DatePickerProvider({ labels, locale, today, children }) {
|
|
2721
|
-
const value = React37.useMemo(() => ({ labels: { ...DEFAULT_DATE_PICKER_LABELS, ...labels }, locale, today }), [labels, locale, today]);
|
|
2800
|
+
function DatePickerProvider({ labels, locale, today, display, children }) {
|
|
2801
|
+
const value = React37.useMemo(() => ({ labels: { ...DEFAULT_DATE_PICKER_LABELS, ...labels }, locale, today, display }), [labels, locale, today, display]);
|
|
2722
2802
|
return /* @__PURE__ */ jsxRuntime.jsx(DatePickerContext.Provider, { value, children });
|
|
2723
2803
|
}
|
|
2724
2804
|
function useDatePickerConfig() {
|
|
2725
2805
|
const config = React37.useContext(DatePickerContext);
|
|
2726
2806
|
const firstDay = React37.useMemo(() => weekFirstDay(config.locale), [config.locale]);
|
|
2727
|
-
return { labels: config.labels, locale: config.locale, today: config.today ?? todayIso(), firstDay };
|
|
2807
|
+
return { labels: config.labels, locale: config.locale, today: config.today ?? todayIso(), firstDay, display: config.display ?? "long" /* Long */ };
|
|
2728
2808
|
}
|
|
2729
2809
|
|
|
2730
2810
|
// src/DatePicker/utils/motionStyles.ts
|
|
@@ -2769,14 +2849,14 @@ function PickerSurface({ anchorRef, phone, minWidth, label, testID, onDismiss, c
|
|
|
2769
2849
|
// src/DatePicker/utils/calendarKeys.ts
|
|
2770
2850
|
var DAYS_IN_WEEK2 = 7;
|
|
2771
2851
|
var MONTHS_IN_YEAR2 = 12;
|
|
2772
|
-
var
|
|
2852
|
+
var MONDAY4 = 1;
|
|
2773
2853
|
var DAY_STEPS = {
|
|
2774
2854
|
ArrowLeft: -1,
|
|
2775
2855
|
ArrowRight: 1,
|
|
2776
2856
|
ArrowUp: -DAYS_IN_WEEK2,
|
|
2777
2857
|
ArrowDown: DAYS_IN_WEEK2
|
|
2778
2858
|
};
|
|
2779
|
-
function nextFocusDay(iso, key, shiftKey = false, firstDay =
|
|
2859
|
+
function nextFocusDay(iso, key, shiftKey = false, firstDay = MONDAY4) {
|
|
2780
2860
|
const step = DAY_STEPS[key];
|
|
2781
2861
|
if (step !== void 0) return addDays(iso, step);
|
|
2782
2862
|
const monthStep = shiftKey ? MONTHS_IN_YEAR2 : 1;
|
|
@@ -2864,74 +2944,6 @@ function DayCell({ iso, state, testID, label, hint, onPick, onKey }) {
|
|
|
2864
2944
|
) });
|
|
2865
2945
|
}
|
|
2866
2946
|
|
|
2867
|
-
// src/DatePicker/utils/formatDate.ts
|
|
2868
|
-
var SAMPLE_UTC = Date.UTC(2027, 5, 12);
|
|
2869
|
-
var TWO_DIGIT_YEAR = 100;
|
|
2870
|
-
var CENTURY = 2e3;
|
|
2871
|
-
var PART_COUNT = 3;
|
|
2872
|
-
var PAD3 = 2;
|
|
2873
|
-
var MONDAY4 = 1;
|
|
2874
|
-
var ISO_LIKE = /^\d{4}-\d{1,2}-\d{1,2}$/;
|
|
2875
|
-
var MONTH_INDEXES = Array.from({ length: 12 }, (_unused, index) => index);
|
|
2876
|
-
var WEEK_OFFSETS = Array.from({ length: 7 }, (_unused, index) => index);
|
|
2877
|
-
var UTC = "UTC";
|
|
2878
|
-
var PART_OF = { day: "day" /* Day */, month: "month" /* Month */, year: "year" /* Year */ };
|
|
2879
|
-
function utcOf(iso) {
|
|
2880
|
-
const parts = parseIso(iso);
|
|
2881
|
-
return parts === null ? null : new Date(Date.UTC(parts.year, parts.month - 1, parts.day));
|
|
2882
|
-
}
|
|
2883
|
-
function formatWith(iso, locale, options) {
|
|
2884
|
-
const date = utcOf(iso);
|
|
2885
|
-
if (date === null) return iso;
|
|
2886
|
-
return new Intl.DateTimeFormat(locale, { ...options, timeZone: UTC }).format(date).replace(/,/g, "");
|
|
2887
|
-
}
|
|
2888
|
-
function formatDisplay(iso, locale) {
|
|
2889
|
-
return formatWith(iso, locale, { weekday: "short", day: "numeric", month: "short", year: "numeric" });
|
|
2890
|
-
}
|
|
2891
|
-
function formatShort(iso, locale, withYear = true) {
|
|
2892
|
-
return formatWith(iso, locale, withYear ? { day: "numeric", month: "short", year: "numeric" } : { day: "numeric", month: "short" });
|
|
2893
|
-
}
|
|
2894
|
-
function formatMonthYear(iso, locale) {
|
|
2895
|
-
return formatWith(iso, locale, { month: "long", year: "numeric" });
|
|
2896
|
-
}
|
|
2897
|
-
function monthNames(locale) {
|
|
2898
|
-
const format = new Intl.DateTimeFormat(locale, { month: "long", timeZone: UTC });
|
|
2899
|
-
return MONTH_INDEXES.map((month) => format.format(new Date(Date.UTC(2024, month, 1))));
|
|
2900
|
-
}
|
|
2901
|
-
function weekdayNames(locale, firstDay = MONDAY4) {
|
|
2902
|
-
const format = new Intl.DateTimeFormat(locale, { weekday: "short", timeZone: UTC });
|
|
2903
|
-
return WEEK_OFFSETS.map((offset) => format.format(new Date(Date.UTC(2024, 0, firstDay + offset))));
|
|
2904
|
-
}
|
|
2905
|
-
function typedOrder(locale) {
|
|
2906
|
-
const parts = new Intl.DateTimeFormat(locale, { day: "numeric", month: "numeric", year: "numeric", timeZone: UTC }).formatToParts(new Date(SAMPLE_UTC));
|
|
2907
|
-
return parts.map((part) => PART_OF[part.type]).filter((part) => part !== void 0);
|
|
2908
|
-
}
|
|
2909
|
-
function formatTyped(iso, locale) {
|
|
2910
|
-
const parts = parseIso(iso);
|
|
2911
|
-
if (parts === null) return iso;
|
|
2912
|
-
const text = {
|
|
2913
|
-
["day" /* Day */]: String(parts.day).padStart(PAD3, "0"),
|
|
2914
|
-
["month" /* Month */]: String(parts.month).padStart(PAD3, "0"),
|
|
2915
|
-
["year" /* Year */]: String(parts.year)
|
|
2916
|
-
};
|
|
2917
|
-
return typedOrder(locale).map((part) => text[part]).join("/");
|
|
2918
|
-
}
|
|
2919
|
-
function parseTyped(text, locale) {
|
|
2920
|
-
const trimmed = text.trim();
|
|
2921
|
-
if (ISO_LIKE.test(trimmed)) {
|
|
2922
|
-
const [year = 0, month = 0, day = 0] = trimmed.split("-").map(Number);
|
|
2923
|
-
const parts2 = { year, month, day };
|
|
2924
|
-
return isValidParts(parts2) ? toIso(parts2) : null;
|
|
2925
|
-
}
|
|
2926
|
-
const numbers2 = trimmed.split(/\D+/).filter((piece) => piece !== "").map(Number);
|
|
2927
|
-
if (numbers2.length !== PART_COUNT) return null;
|
|
2928
|
-
const order = typedOrder(locale);
|
|
2929
|
-
const read = (part) => numbers2[order.indexOf(part)] ?? 0;
|
|
2930
|
-
const rawYear = read("year" /* Year */);
|
|
2931
|
-
const parts = { year: rawYear < TWO_DIGIT_YEAR ? CENTURY + rawYear : rawYear, month: read("month" /* Month */), day: read("day" /* Day */) };
|
|
2932
|
-
return isValidParts(parts) ? toIso(parts) : null;
|
|
2933
|
-
}
|
|
2934
|
-
|
|
2935
2947
|
// src/DatePicker/utils/monthGrid.ts
|
|
2936
2948
|
var DAYS_IN_WEEK3 = 7;
|
|
2937
2949
|
var MONDAY5 = 1;
|
|
@@ -3197,13 +3209,13 @@ var ICON_SLOT = { position: "absolute", right: 2, top: 0, bottom: 0, display: "f
|
|
|
3197
3209
|
var anchorStyles = reactNative.StyleSheet.create({ wrap: { position: "relative", width: "100%" } });
|
|
3198
3210
|
function DatePickerInput({ fieldProps, context, onTypedError }) {
|
|
3199
3211
|
const { label, value, onChange, onSubmit, accessibilityHint, testID, required, disabled = false, min, max } = fieldProps;
|
|
3200
|
-
const { labels } = useDatePickerConfig();
|
|
3212
|
+
const { labels, display } = useDatePickerConfig();
|
|
3201
3213
|
const phone = useIsPhone();
|
|
3202
3214
|
const [open, setOpen] = React37.useState(false);
|
|
3203
3215
|
const anchorRef = React37.useRef(null);
|
|
3204
3216
|
const inputRef = React37.useRef(null);
|
|
3205
3217
|
const bounds = { min, max };
|
|
3206
|
-
const typed = useTypedDate({ value, onChange, bounds, format:
|
|
3218
|
+
const typed = useTypedDate({ value, onChange, bounds, format: displayFormatter(display), onError: onTypedError, editOnType: true });
|
|
3207
3219
|
const edit = typedEditBind(typed);
|
|
3208
3220
|
const { style, focusBind, hoverBind } = useThemedInput({ hasError: context.hasError, editable: !disabled });
|
|
3209
3221
|
const focus = focusBind;
|
|
@@ -3742,6 +3754,71 @@ function useFocusFirstInvalid(refs) {
|
|
|
3742
3754
|
first?.focus();
|
|
3743
3755
|
}, []);
|
|
3744
3756
|
}
|
|
3757
|
+
|
|
3758
|
+
// src/useServerFieldErrors/assignServerErrors.ts
|
|
3759
|
+
function lastSegment(path) {
|
|
3760
|
+
return path.slice(path.lastIndexOf(".") + 1).toLowerCase();
|
|
3761
|
+
}
|
|
3762
|
+
function matchField(path, fields) {
|
|
3763
|
+
const exact = fields.find((field2) => field2 === path);
|
|
3764
|
+
if (exact !== void 0) {
|
|
3765
|
+
return exact;
|
|
3766
|
+
}
|
|
3767
|
+
const key = lastSegment(path);
|
|
3768
|
+
return key === "" ? null : fields.find((field2) => field2.toLowerCase() === key) ?? null;
|
|
3769
|
+
}
|
|
3770
|
+
function messageOf(error, formatCode) {
|
|
3771
|
+
const formatted = error.code !== void 0 && formatCode !== void 0 ? formatCode(error.code, error) : null;
|
|
3772
|
+
return typeof formatted === "string" && formatted !== "" ? formatted : error.message;
|
|
3773
|
+
}
|
|
3774
|
+
function assignServerErrors(errors, fields, formatCode) {
|
|
3775
|
+
const byField = {};
|
|
3776
|
+
let formError = null;
|
|
3777
|
+
for (const error of errors) {
|
|
3778
|
+
const field2 = matchField(error.path, fields);
|
|
3779
|
+
const message = messageOf(error, formatCode);
|
|
3780
|
+
if (field2 === null) {
|
|
3781
|
+
formError = formError ?? message;
|
|
3782
|
+
} else if (byField[field2] === void 0) {
|
|
3783
|
+
byField[field2] = message;
|
|
3784
|
+
}
|
|
3785
|
+
}
|
|
3786
|
+
const matched = fields.filter((field2) => byField[field2] !== void 0);
|
|
3787
|
+
return { byField, formError, matched };
|
|
3788
|
+
}
|
|
3789
|
+
|
|
3790
|
+
// src/useServerFieldErrors/useServerFieldErrors.ts
|
|
3791
|
+
var EMPTY_STATE = { byField: {}, formError: null };
|
|
3792
|
+
var NO_REFS = {};
|
|
3793
|
+
function withoutField(state, field2) {
|
|
3794
|
+
if (state.byField[field2] === void 0) {
|
|
3795
|
+
return state;
|
|
3796
|
+
}
|
|
3797
|
+
const byField = { ...state.byField };
|
|
3798
|
+
delete byField[field2];
|
|
3799
|
+
return { ...state, byField };
|
|
3800
|
+
}
|
|
3801
|
+
function useServerFieldErrors(options) {
|
|
3802
|
+
const { fields, refs, formatCode } = options;
|
|
3803
|
+
const [state, setState] = React37.useState(EMPTY_STATE);
|
|
3804
|
+
const focusFirst = useFocusFirstInvalid(refs ?? NO_REFS);
|
|
3805
|
+
const hasRefs = refs !== void 0;
|
|
3806
|
+
const apply = React37.useCallback(
|
|
3807
|
+
(error) => {
|
|
3808
|
+
const assigned = assignServerErrors(apiClientBase.parseFieldErrors(error), fields, formatCode);
|
|
3809
|
+
setState({ byField: assigned.byField, formError: assigned.formError });
|
|
3810
|
+
if (hasRefs && assigned.matched.length > 0) {
|
|
3811
|
+
focusFirst(assigned.matched);
|
|
3812
|
+
}
|
|
3813
|
+
return assigned.matched.length > 0;
|
|
3814
|
+
},
|
|
3815
|
+
[fields, formatCode, focusFirst, hasRefs]
|
|
3816
|
+
);
|
|
3817
|
+
const clear = React37.useCallback((field2) => setState((current) => withoutField(current, field2)), []);
|
|
3818
|
+
const reset = React37.useCallback(() => setState(EMPTY_STATE), []);
|
|
3819
|
+
const errorFor = React37.useCallback((field2) => state.byField[field2], [state.byField]);
|
|
3820
|
+
return { errorFor, apply, clear, formError: state.formError, reset };
|
|
3821
|
+
}
|
|
3745
3822
|
function isScrollable(node) {
|
|
3746
3823
|
return "scrollIntoView" in Object(node);
|
|
3747
3824
|
}
|
|
@@ -5743,6 +5820,261 @@ function DecisionPanel(props) {
|
|
|
5743
5820
|
] });
|
|
5744
5821
|
}
|
|
5745
5822
|
|
|
5823
|
+
// src/PasswordField/PasswordRulesDisplay.ts
|
|
5824
|
+
var PasswordRulesDisplay = /* @__PURE__ */ ((PasswordRulesDisplay2) => {
|
|
5825
|
+
PasswordRulesDisplay2["Checklist"] = "checklist";
|
|
5826
|
+
PasswordRulesDisplay2["MeterGrid"] = "meterGrid";
|
|
5827
|
+
PasswordRulesDisplay2["Chips"] = "chips";
|
|
5828
|
+
PasswordRulesDisplay2["Sentence"] = "sentence";
|
|
5829
|
+
return PasswordRulesDisplay2;
|
|
5830
|
+
})(PasswordRulesDisplay || {});
|
|
5831
|
+
|
|
5832
|
+
// src/PasswordField/RuleTone.ts
|
|
5833
|
+
var RuleTone = /* @__PURE__ */ ((RuleTone2) => {
|
|
5834
|
+
RuleTone2["Met"] = "met";
|
|
5835
|
+
RuleTone2["Unmet"] = "unmet";
|
|
5836
|
+
RuleTone2["Refused"] = "refused";
|
|
5837
|
+
return RuleTone2;
|
|
5838
|
+
})(RuleTone || {});
|
|
5839
|
+
function ruleTone(met, flagUnmet) {
|
|
5840
|
+
if (met) return "met" /* Met */;
|
|
5841
|
+
return flagUnmet ? "refused" /* Refused */ : "unmet" /* Unmet */;
|
|
5842
|
+
}
|
|
5843
|
+
var MARK_SIZE = 16;
|
|
5844
|
+
var CHECK_SIZE = 12;
|
|
5845
|
+
var RING_WIDTH = 1.5;
|
|
5846
|
+
var POP_FROM = 0.6;
|
|
5847
|
+
var POP_PEAK = 1.12;
|
|
5848
|
+
var POP_UP_MS = 160;
|
|
5849
|
+
var POP_SETTLE_MS = 100;
|
|
5850
|
+
var styles38 = reactNative.StyleSheet.create({
|
|
5851
|
+
mark: { width: MARK_SIZE, height: MARK_SIZE, borderRadius: MARK_SIZE / 2, alignItems: "center", justifyContent: "center" },
|
|
5852
|
+
ring: { borderWidth: RING_WIDTH }
|
|
5853
|
+
});
|
|
5854
|
+
function RuleMark({ tone, colors }) {
|
|
5855
|
+
const reduced = useReducedMotion();
|
|
5856
|
+
const scale = React37.useRef(new reactNative.Animated.Value(1)).current;
|
|
5857
|
+
const wasMet = React37.useRef(tone === "met" /* Met */);
|
|
5858
|
+
const met = tone === "met" /* Met */;
|
|
5859
|
+
React37.useEffect(() => {
|
|
5860
|
+
const turnedMet = met && !wasMet.current;
|
|
5861
|
+
wasMet.current = met;
|
|
5862
|
+
if (!turnedMet || reduced) return;
|
|
5863
|
+
scale.setValue(POP_FROM);
|
|
5864
|
+
reactNative.Animated.sequence([
|
|
5865
|
+
reactNative.Animated.timing(scale, { toValue: POP_PEAK, duration: POP_UP_MS, easing: reactNative.Easing.out(reactNative.Easing.cubic), useNativeDriver: false }),
|
|
5866
|
+
reactNative.Animated.timing(scale, { toValue: 1, duration: POP_SETTLE_MS, easing: reactNative.Easing.out(reactNative.Easing.cubic), useNativeDriver: false })
|
|
5867
|
+
]).start();
|
|
5868
|
+
}, [met, reduced, scale]);
|
|
5869
|
+
const color = colors.mark[tone];
|
|
5870
|
+
const shape = met ? { backgroundColor: color } : [styles38.ring, { borderColor: color }];
|
|
5871
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactNative.Animated.View, { style: { transform: [{ scale }] }, children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: [styles38.mark, shape], children: met ? /* @__PURE__ */ jsxRuntime.jsx(uiIcons.SvgIcon, { color: colors.onMark, name: "check", size: CHECK_SIZE }) : null }) });
|
|
5872
|
+
}
|
|
5873
|
+
var GAP8 = 6;
|
|
5874
|
+
var ROW_GAP8 = 8;
|
|
5875
|
+
var FONT5 = 14;
|
|
5876
|
+
var LINE = 20;
|
|
5877
|
+
var METER_HEIGHT = 4;
|
|
5878
|
+
var RADIUS3 = 999;
|
|
5879
|
+
var CHIP_PAD_V = 4;
|
|
5880
|
+
var CHIP_PAD_H = 10;
|
|
5881
|
+
var CHIP_BORDER = 1;
|
|
5882
|
+
var HALF4 = "50%";
|
|
5883
|
+
var styles39 = reactNative.StyleSheet.create({
|
|
5884
|
+
column: { gap: GAP8 },
|
|
5885
|
+
row: { flexDirection: "row", alignItems: "center", gap: ROW_GAP8 },
|
|
5886
|
+
text: { fontSize: FONT5, lineHeight: LINE, flexShrink: 1 },
|
|
5887
|
+
meter: { flexDirection: "row", gap: GAP8 },
|
|
5888
|
+
segment: { flex: 1, height: METER_HEIGHT, borderRadius: RADIUS3 },
|
|
5889
|
+
grid: { flexDirection: "row", flexWrap: "wrap", rowGap: GAP8 },
|
|
5890
|
+
cell: { flexBasis: HALF4, maxWidth: HALF4, paddingRight: GAP8 },
|
|
5891
|
+
chips: { flexDirection: "row", flexWrap: "wrap", gap: GAP8 },
|
|
5892
|
+
chip: { borderRadius: RADIUS3, borderWidth: CHIP_BORDER, paddingVertical: CHIP_PAD_V, paddingHorizontal: CHIP_PAD_H },
|
|
5893
|
+
metPhrase: { fontWeight: "700", textDecorationLine: "underline" }
|
|
5894
|
+
});
|
|
5895
|
+
function RuleList({ rules, flagUnmet, colors, testID, listStyle, itemStyle, outlined = false }) {
|
|
5896
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { role: "list", style: listStyle, testID, children: rules.map((rule) => {
|
|
5897
|
+
const tone = ruleTone(rule.met, flagUnmet);
|
|
5898
|
+
const outline = outlined ? { borderColor: colors.mark[tone] } : null;
|
|
5899
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { role: "listitem", style: [styles39.row, itemStyle, outline], testID: `${testID}-${rule.id}`, ...{ dataSet: { tone } }, children: [
|
|
5900
|
+
/* @__PURE__ */ jsxRuntime.jsx(RuleMark, { colors, tone }),
|
|
5901
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles39.text, { color: colors.text[tone] }], children: rule.label })
|
|
5902
|
+
] }, rule.id);
|
|
5903
|
+
}) });
|
|
5904
|
+
}
|
|
5905
|
+
function RulesChecklist(props) {
|
|
5906
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RuleList, { ...props, listStyle: styles39.column });
|
|
5907
|
+
}
|
|
5908
|
+
function RulesChips(props) {
|
|
5909
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RuleList, { ...props, outlined: true, itemStyle: styles39.chip, listStyle: styles39.chips });
|
|
5910
|
+
}
|
|
5911
|
+
function RulesMeterGrid(props) {
|
|
5912
|
+
const { rules, flagUnmet, colors, testID } = props;
|
|
5913
|
+
const metCount = rules.filter((rule) => rule.met).length;
|
|
5914
|
+
const unfilled = flagUnmet ? colors.mark.refused : colors.track;
|
|
5915
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles39.column, children: [
|
|
5916
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: styles39.meter, testID: `${testID}-meter`, children: rules.map((rule, index) => /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: [styles39.segment, { backgroundColor: index < metCount ? colors.mark.met : unfilled }] }, rule.id)) }),
|
|
5917
|
+
/* @__PURE__ */ jsxRuntime.jsx(RuleList, { ...props, itemStyle: styles39.cell, listStyle: styles39.grid })
|
|
5918
|
+
] });
|
|
5919
|
+
}
|
|
5920
|
+
function RulesSentence({ rules, flagUnmet, colors, testID }) {
|
|
5921
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles39.text, { color: colors.text.unmet }], testID, children: rules.map((rule, index) => {
|
|
5922
|
+
const tone = ruleTone(rule.met, flagUnmet);
|
|
5923
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.Text, { style: [{ color: colors.text[tone] }, rule.met ? styles39.metPhrase : null], testID: `${testID}-${rule.id}`, ...{ dataSet: { tone } }, children: [
|
|
5924
|
+
index > 0 ? ", " : "",
|
|
5925
|
+
rule.label
|
|
5926
|
+
] }, rule.id);
|
|
5927
|
+
}) });
|
|
5928
|
+
}
|
|
5929
|
+
function PasswordRules({ display, ...variant }) {
|
|
5930
|
+
switch (display) {
|
|
5931
|
+
case "checklist" /* Checklist */:
|
|
5932
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RulesChecklist, { ...variant });
|
|
5933
|
+
case "chips" /* Chips */:
|
|
5934
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RulesChips, { ...variant });
|
|
5935
|
+
case "sentence" /* Sentence */:
|
|
5936
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RulesSentence, { ...variant });
|
|
5937
|
+
default:
|
|
5938
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RulesMeterGrid, { ...variant });
|
|
5939
|
+
}
|
|
5940
|
+
}
|
|
5941
|
+
var ICON_SIZE = 20;
|
|
5942
|
+
var styles40 = reactNative.StyleSheet.create({
|
|
5943
|
+
button: { width: a11y.MIN_TOUCH_TARGET_PX, height: a11y.MIN_TOUCH_TARGET_PX, alignItems: "center", justifyContent: "center" }
|
|
5944
|
+
});
|
|
5945
|
+
function RevealToggle({ revealed, onToggle, onPressIn, showLabel, hideLabel, color, testID }) {
|
|
5946
|
+
const label = revealed ? hideLabel : showLabel;
|
|
5947
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
5948
|
+
reactNative.Pressable,
|
|
5949
|
+
{
|
|
5950
|
+
accessibilityHint: label,
|
|
5951
|
+
accessibilityLabel: label,
|
|
5952
|
+
accessibilityRole: "button",
|
|
5953
|
+
"aria-pressed": revealed,
|
|
5954
|
+
style: styles40.button,
|
|
5955
|
+
testID,
|
|
5956
|
+
onPress: onToggle,
|
|
5957
|
+
onPressIn,
|
|
5958
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(uiIcons.SvgIcon, { color, name: revealed ? "eyeOff" : "eye", size: ICON_SIZE })
|
|
5959
|
+
}
|
|
5960
|
+
);
|
|
5961
|
+
}
|
|
5962
|
+
|
|
5963
|
+
// src/PasswordField/ruleAnnouncement.ts
|
|
5964
|
+
function changedRules(previous, next) {
|
|
5965
|
+
const before = new Map(previous.map((rule) => [rule.id, rule.met]));
|
|
5966
|
+
return next.filter((rule) => before.has(rule.id) && before.get(rule.id) !== rule.met);
|
|
5967
|
+
}
|
|
5968
|
+
function ruleAnnouncement(changed, labels) {
|
|
5969
|
+
return changed.map((rule) => `${rule.label}: ${rule.met ? labels.met : labels.unmet}`).join(". ");
|
|
5970
|
+
}
|
|
5971
|
+
|
|
5972
|
+
// src/PasswordField/usePasswordRuleAnnouncement.ts
|
|
5973
|
+
function usePasswordRuleAnnouncement(rules, labels) {
|
|
5974
|
+
const previous = React37.useRef(rules);
|
|
5975
|
+
const [message, setMessage] = React37.useState("");
|
|
5976
|
+
React37.useEffect(() => {
|
|
5977
|
+
const changed = changedRules(previous.current, rules);
|
|
5978
|
+
previous.current = rules;
|
|
5979
|
+
if (changed.length > 0) setMessage(ruleAnnouncement(changed, labels));
|
|
5980
|
+
}, [rules, labels]);
|
|
5981
|
+
return message;
|
|
5982
|
+
}
|
|
5983
|
+
function ruleColorsFrom(palette) {
|
|
5984
|
+
return {
|
|
5985
|
+
mark: { ["met" /* Met */]: palette.success, ["unmet" /* Unmet */]: palette.textSecondary, ["refused" /* Refused */]: palette.error },
|
|
5986
|
+
text: { ["met" /* Met */]: palette.text, ["unmet" /* Unmet */]: palette.textSecondary, ["refused" /* Refused */]: palette.error },
|
|
5987
|
+
track: palette.border,
|
|
5988
|
+
onMark: palette.background
|
|
5989
|
+
};
|
|
5990
|
+
}
|
|
5991
|
+
function useRuleColors(override) {
|
|
5992
|
+
const { theme } = uiFeedback.useUi();
|
|
5993
|
+
return React37.useMemo(() => {
|
|
5994
|
+
if (override !== void 0) return ruleColorsFrom(override);
|
|
5995
|
+
return ruleColorsFrom({
|
|
5996
|
+
success: theme.semantic.success?.["500"] ?? theme.colors.text,
|
|
5997
|
+
error: theme.semantic.error["500"],
|
|
5998
|
+
text: theme.colors.text,
|
|
5999
|
+
textSecondary: theme.colors.textSecondary,
|
|
6000
|
+
border: theme.colors.border,
|
|
6001
|
+
background: theme.colors.background
|
|
6002
|
+
});
|
|
6003
|
+
}, [theme, override]);
|
|
6004
|
+
}
|
|
6005
|
+
var RULES_GAP = 8;
|
|
6006
|
+
var TOGGLE_INSET = 48;
|
|
6007
|
+
var NO_RULES = [];
|
|
6008
|
+
var styles41 = reactNative.StyleSheet.create({
|
|
6009
|
+
inputRow: { position: "relative", justifyContent: "center" },
|
|
6010
|
+
input: { paddingRight: TOGGLE_INSET },
|
|
6011
|
+
toggle: { position: "absolute", right: 0, top: 0, bottom: 0, justifyContent: "center" },
|
|
6012
|
+
rules: { marginTop: RULES_GAP },
|
|
6013
|
+
live: { position: "absolute", width: 1, height: 1, overflow: "hidden", opacity: 0 }
|
|
6014
|
+
});
|
|
6015
|
+
function joinIds(...ids) {
|
|
6016
|
+
const joined = ids.filter((id) => id !== void 0 && id !== "").join(" ");
|
|
6017
|
+
return joined === "" ? void 0 : joined;
|
|
6018
|
+
}
|
|
6019
|
+
function useCaretKeepingToggle(inputRef, initialLength) {
|
|
6020
|
+
const [revealed, setRevealed] = React37.useState(false);
|
|
6021
|
+
const selection2 = React37.useRef({ start: initialLength, end: initialLength });
|
|
6022
|
+
const hadFocus = React37.useRef(false);
|
|
6023
|
+
const onSelectionChange = React37.useCallback((event) => {
|
|
6024
|
+
selection2.current = event.nativeEvent.selection;
|
|
6025
|
+
}, []);
|
|
6026
|
+
const onPressIn = React37.useCallback(() => {
|
|
6027
|
+
hadFocus.current = inputRef.current?.isFocused?.() ?? false;
|
|
6028
|
+
}, [inputRef]);
|
|
6029
|
+
const onToggle = React37.useCallback(() => {
|
|
6030
|
+
setRevealed((current) => !current);
|
|
6031
|
+
if (!hadFocus.current) return;
|
|
6032
|
+
const node = inputRef.current;
|
|
6033
|
+
const { start, end } = selection2.current;
|
|
6034
|
+
requestAnimationFrame(() => {
|
|
6035
|
+
node?.focus();
|
|
6036
|
+
node?.setSelectionRange?.(start, end);
|
|
6037
|
+
});
|
|
6038
|
+
}, [inputRef]);
|
|
6039
|
+
return { revealed, onPressIn, onToggle, onSelectionChange };
|
|
6040
|
+
}
|
|
6041
|
+
var PasswordField = React37__default.default.forwardRef(function PasswordField2({ label, value, onChangeText, labels, testID, rules = NO_RULES, rulesDisplay = "meterGrid" /* MeterGrid */, flagUnmet = false, error, colors: colorOverride, inputProps }, ref) {
|
|
6042
|
+
const inputRef = React37.useRef(null);
|
|
6043
|
+
React37.useImperativeHandle(ref, () => inputRef.current);
|
|
6044
|
+
const toggle2 = useCaretKeepingToggle(inputRef, value.length);
|
|
6045
|
+
const colors = useRuleColors(colorOverride);
|
|
6046
|
+
const announcement = usePasswordRuleAnnouncement(rules, labels);
|
|
6047
|
+
const rulesId = `${testID}-rules`;
|
|
6048
|
+
const hasRules = rules.length > 0;
|
|
6049
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Field, { error, label, testID: `${testID}-field`, children: (context) => /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { children: [
|
|
6050
|
+
/* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles41.inputRow, children: [
|
|
6051
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6052
|
+
ThemedTextInput,
|
|
6053
|
+
{
|
|
6054
|
+
autoCapitalize: "none",
|
|
6055
|
+
autoCorrect: false,
|
|
6056
|
+
...inputProps,
|
|
6057
|
+
ref: inputRef,
|
|
6058
|
+
describedById: joinIds(context.describedById, hasRules ? rulesId : void 0),
|
|
6059
|
+
hasError: context.hasError || flagUnmet && rules.some((rule) => !rule.met),
|
|
6060
|
+
id: context.controlId,
|
|
6061
|
+
secureTextEntry: !toggle2.revealed,
|
|
6062
|
+
style: [styles41.input, inputProps?.style],
|
|
6063
|
+
testID,
|
|
6064
|
+
value,
|
|
6065
|
+
onChangeText,
|
|
6066
|
+
onSelectionChange: toggle2.onSelectionChange
|
|
6067
|
+
}
|
|
6068
|
+
),
|
|
6069
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: styles41.toggle, children: /* @__PURE__ */ jsxRuntime.jsx(RevealToggle, { color: colors.text.unmet, hideLabel: labels.hide, revealed: toggle2.revealed, showLabel: labels.show, testID: `${testID}-reveal`, onPressIn: toggle2.onPressIn, onToggle: toggle2.onToggle }) })
|
|
6070
|
+
] }),
|
|
6071
|
+
hasRules ? /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { nativeID: rulesId, style: styles41.rules, children: [
|
|
6072
|
+
/* @__PURE__ */ jsxRuntime.jsx(PasswordRules, { colors, display: rulesDisplay, flagUnmet, rules, testID: rulesId }),
|
|
6073
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { "aria-live": "polite", accessibilityLiveRegion: "polite", style: styles41.live, testID: `${testID}-announce`, children: announcement })
|
|
6074
|
+
] }) : null
|
|
6075
|
+
] }) });
|
|
6076
|
+
});
|
|
6077
|
+
|
|
5746
6078
|
exports.ActionBar = ActionBar;
|
|
5747
6079
|
exports.AddOnRequest = AddOnRequest;
|
|
5748
6080
|
exports.AlignToControl = AlignToControl;
|
|
@@ -5759,6 +6091,7 @@ exports.DEFAULT_MAX_RECENTS = DEFAULT_MAX_RECENTS;
|
|
|
5759
6091
|
exports.DEFAULT_OPTIONAL_LABEL = DEFAULT_OPTIONAL_LABEL;
|
|
5760
6092
|
exports.DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS = DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS;
|
|
5761
6093
|
exports.DEFAULT_TYPEAHEAD_MIN_CHARS = DEFAULT_TYPEAHEAD_MIN_CHARS;
|
|
6094
|
+
exports.DateDisplay = DateDisplay;
|
|
5762
6095
|
exports.DateField = DateField;
|
|
5763
6096
|
exports.DateInput = DateInput;
|
|
5764
6097
|
exports.DatePickerProvider = DatePickerProvider;
|
|
@@ -5791,9 +6124,14 @@ exports.InlineFieldRow = InlineFieldRow;
|
|
|
5791
6124
|
exports.LINE_ITEMS_WIDE_MIN_WIDTH = LINE_ITEMS_WIDE_MIN_WIDTH;
|
|
5792
6125
|
exports.LineItems = LineItems;
|
|
5793
6126
|
exports.PHONE_MAX_WIDTH = PHONE_MAX_WIDTH;
|
|
6127
|
+
exports.PasswordField = PasswordField;
|
|
6128
|
+
exports.PasswordRules = PasswordRules;
|
|
6129
|
+
exports.PasswordRulesDisplay = PasswordRulesDisplay;
|
|
5794
6130
|
exports.RESPONSIVE_FORM_DEFAULT_BREAKPOINT = RESPONSIVE_FORM_DEFAULT_BREAKPOINT;
|
|
5795
6131
|
exports.RadioList = RadioList;
|
|
5796
6132
|
exports.ResponsiveFormLayout = ResponsiveFormLayout;
|
|
6133
|
+
exports.RevealToggle = RevealToggle;
|
|
6134
|
+
exports.RuleTone = RuleTone;
|
|
5797
6135
|
exports.SEGMENT_BESIDE_FIELD = SEGMENT_BESIDE_FIELD;
|
|
5798
6136
|
exports.SEGMENT_BESIDE_TEXT_INPUT = SEGMENT_BESIDE_TEXT_INPUT;
|
|
5799
6137
|
exports.SearchSelect = SearchSelect;
|
|
@@ -5806,8 +6144,10 @@ exports.ThemedTextInput = ThemedTextInput;
|
|
|
5806
6144
|
exports.TypeaheadControl = TypeaheadControl;
|
|
5807
6145
|
exports.UploadWithLinkField = UploadWithLinkField;
|
|
5808
6146
|
exports.actionBarPosition = actionBarPosition;
|
|
6147
|
+
exports.assignServerErrors = assignServerErrors;
|
|
5809
6148
|
exports.buildSearchSelectSections = buildSearchSelectSections;
|
|
5810
6149
|
exports.canRemoveLine = canRemoveLine;
|
|
6150
|
+
exports.changedRules = changedRules;
|
|
5811
6151
|
exports.controlStyles = controlStyles;
|
|
5812
6152
|
exports.countryFieldOptions = countryFieldOptions;
|
|
5813
6153
|
exports.countryFlag = countryFlag;
|
|
@@ -5845,6 +6185,9 @@ exports.resolveGroupSelection = resolveGroupSelection;
|
|
|
5845
6185
|
exports.resolveSelectMotion = resolveSelectMotion;
|
|
5846
6186
|
exports.resolveStepNeighbours = resolveStepNeighbours;
|
|
5847
6187
|
exports.rowsForText = rowsForText;
|
|
6188
|
+
exports.ruleAnnouncement = ruleAnnouncement;
|
|
6189
|
+
exports.ruleColorsFrom = ruleColorsFrom;
|
|
6190
|
+
exports.ruleTone = ruleTone;
|
|
5848
6191
|
exports.suggestOptions = suggestOptions;
|
|
5849
6192
|
exports.toCountryValue = toCountryValue;
|
|
5850
6193
|
exports.toggleGroupSelection = toggleGroupSelection;
|
|
@@ -5857,6 +6200,7 @@ exports.useOutsidePress = useOutsidePress;
|
|
|
5857
6200
|
exports.useRecentValues = useRecentValues;
|
|
5858
6201
|
exports.useReducedMotion = useReducedMotion;
|
|
5859
6202
|
exports.useSearchSelectState = useSearchSelectState;
|
|
6203
|
+
exports.useServerFieldErrors = useServerFieldErrors;
|
|
5860
6204
|
exports.useThemedInput = useThemedInput;
|
|
5861
6205
|
exports.validateBic = validateBic;
|
|
5862
6206
|
exports.validateDecision = validateDecision;
|