@dloizides/ui-forms 1.42.1 → 1.42.3
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.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +120 -48
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +120 -48
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1491,7 +1491,7 @@ interface DropdownFrame {
|
|
|
1491
1491
|
}
|
|
1492
1492
|
/** Opens below when the list fits there, else on whichever side has more room. */
|
|
1493
1493
|
declare function placeDropdown(anchor: AnchorRect, panelHeight: number, viewportHeight: number): DropdownPlacement;
|
|
1494
|
-
/** The window frame for the list next to `anchor`, kept inside the viewport; `preferBelow`
|
|
1494
|
+
/** The window frame for the list next to `anchor`, kept inside the viewport; `preferBelow` opens under the field unless only the room above fits the list. */
|
|
1495
1495
|
declare function dropdownFrame(anchor: AnchorRect, panelHeight: number, viewportHeight: number, preferBelow?: boolean): DropdownFrame;
|
|
1496
1496
|
/** Widens a narrow anchor's list to `minWidth` (default a readable width) and keeps it inside the viewport. */
|
|
1497
1497
|
declare function fitDropdownWidth(frame: DropdownFrame, viewportWidth: number, minWidth?: number): DropdownFrame;
|
package/dist/index.d.ts
CHANGED
|
@@ -1491,7 +1491,7 @@ interface DropdownFrame {
|
|
|
1491
1491
|
}
|
|
1492
1492
|
/** Opens below when the list fits there, else on whichever side has more room. */
|
|
1493
1493
|
declare function placeDropdown(anchor: AnchorRect, panelHeight: number, viewportHeight: number): DropdownPlacement;
|
|
1494
|
-
/** The window frame for the list next to `anchor`, kept inside the viewport; `preferBelow`
|
|
1494
|
+
/** The window frame for the list next to `anchor`, kept inside the viewport; `preferBelow` opens under the field unless only the room above fits the list. */
|
|
1495
1495
|
declare function dropdownFrame(anchor: AnchorRect, panelHeight: number, viewportHeight: number, preferBelow?: boolean): DropdownFrame;
|
|
1496
1496
|
/** Widens a narrow anchor's list to `minWidth` (default a readable width) and keeps it inside the viewport. */
|
|
1497
1497
|
declare function fitDropdownWidth(frame: DropdownFrame, viewportWidth: number, minWidth?: number): DropdownFrame;
|
package/dist/index.js
CHANGED
|
@@ -2423,11 +2423,16 @@ function placeDropdown(anchor, panelHeight, viewportHeight) {
|
|
|
2423
2423
|
if (roomBelow >= panelHeight) return "below" /* Below */;
|
|
2424
2424
|
return anchor.y > roomBelow ? "above" /* Above */ : "below" /* Below */;
|
|
2425
2425
|
}
|
|
2426
|
+
function placeBelowFirst(anchor, panelHeight, viewportHeight) {
|
|
2427
|
+
const roomBelow = viewportHeight - (anchor.y + anchor.height);
|
|
2428
|
+
const fitsOnlyAbove = roomBelow < panelHeight && anchor.y - EDGE >= panelHeight;
|
|
2429
|
+
return fitsOnlyAbove ? "above" /* Above */ : "below" /* Below */;
|
|
2430
|
+
}
|
|
2426
2431
|
function clampTop(top, panelHeight, viewportHeight) {
|
|
2427
2432
|
return Math.max(EDGE, Math.min(top, viewportHeight - panelHeight - EDGE));
|
|
2428
2433
|
}
|
|
2429
2434
|
function dropdownFrame(anchor, panelHeight, viewportHeight, preferBelow = false) {
|
|
2430
|
-
const placement = preferBelow ?
|
|
2435
|
+
const placement = preferBelow ? placeBelowFirst(anchor, panelHeight, viewportHeight) : placeDropdown(anchor, panelHeight, viewportHeight);
|
|
2431
2436
|
const base = { placement, left: anchor.x, width: anchor.width };
|
|
2432
2437
|
if (placement === "above" /* Above */) return { ...base, bottom: viewportHeight - clampTop(anchor.y - panelHeight, panelHeight, viewportHeight) - panelHeight };
|
|
2433
2438
|
return { ...base, top: clampTop(anchor.y + anchor.height, panelHeight, viewportHeight) };
|
|
@@ -2835,17 +2840,17 @@ var BOLD2 = 700;
|
|
|
2835
2840
|
var ROW = { display: "flex" };
|
|
2836
2841
|
var EMPTY = { width: DAY_CELL_PX, height: DAY_CELL_PX, flexShrink: 0 };
|
|
2837
2842
|
var FALLBACK = { year: 1970, month: 1};
|
|
2838
|
-
function MonthGrid({ month, selection, focusedDay, bounds, testID, onPick, onKey, showCaption = false, motion }) {
|
|
2843
|
+
function MonthGrid({ month, selection: selection2, focusedDay, bounds, testID, onPick, onKey, showCaption = false, motion }) {
|
|
2839
2844
|
const { labels, locale, today, firstDay } = useDatePickerConfig();
|
|
2840
2845
|
const colors = usePickerColors();
|
|
2841
2846
|
const parts = parseIso(month) ?? FALLBACK;
|
|
2842
2847
|
const weeks = React37.useMemo(() => buildMonthGrid(parts.year, parts.month, firstDay), [parts.year, parts.month, firstDay]);
|
|
2843
2848
|
const weekdays = React37.useMemo(() => weekdayNames(locale, firstDay), [locale, firstDay]);
|
|
2844
2849
|
const title = formatMonthYear(month, locale);
|
|
2845
|
-
const end =
|
|
2850
|
+
const end = selection2.to === "" ? selection2.from : selection2.to;
|
|
2846
2851
|
const stateOf = (iso) => ({
|
|
2847
|
-
inRange:
|
|
2848
|
-
isEnd: iso ===
|
|
2852
|
+
inRange: selection2.from !== "" && iso >= selection2.from && iso <= end,
|
|
2853
|
+
isEnd: iso === selection2.from || iso === selection2.to,
|
|
2849
2854
|
isToday: iso === today,
|
|
2850
2855
|
enabled: isWithinBounds(iso, bounds.min, bounds.max),
|
|
2851
2856
|
focusable: iso === focusedDay
|
|
@@ -2957,9 +2962,9 @@ function useReturnFocus(open, target) {
|
|
|
2957
2962
|
return () => clearTimeout(timer);
|
|
2958
2963
|
}, [open, target]);
|
|
2959
2964
|
}
|
|
2960
|
-
function useTypedDate({ value, onChange, bounds, format, onError, rangeMessage }) {
|
|
2965
|
+
function useTypedDate({ value, onChange, bounds, format, onError, rangeMessage, editOnType = false }) {
|
|
2961
2966
|
const { labels, locale } = useDatePickerConfig();
|
|
2962
|
-
const [
|
|
2967
|
+
const [editing, setEditing] = React37.useState(false);
|
|
2963
2968
|
const [text, setText] = React37.useState("");
|
|
2964
2969
|
React37.useEffect(() => {
|
|
2965
2970
|
setText((current) => {
|
|
@@ -2974,7 +2979,12 @@ function useTypedDate({ value, onChange, bounds, format, onError, rangeMessage }
|
|
|
2974
2979
|
if (parsed === null) return labels.invalidDate;
|
|
2975
2980
|
return isWithinBounds(parsed, bounds.min, bounds.max) ? void 0 : rangeMessage ?? labels.outOfRange;
|
|
2976
2981
|
};
|
|
2982
|
+
const startEdit = () => {
|
|
2983
|
+
setEditing(true);
|
|
2984
|
+
setText(value === "" ? "" : formatTyped(value, locale));
|
|
2985
|
+
};
|
|
2977
2986
|
const onText = (next) => {
|
|
2987
|
+
setEditing(true);
|
|
2978
2988
|
setText(next);
|
|
2979
2989
|
if (next.trim() === "") {
|
|
2980
2990
|
onError?.(void 0);
|
|
@@ -2988,21 +2998,26 @@ function useTypedDate({ value, onChange, bounds, format, onError, rangeMessage }
|
|
|
2988
2998
|
if (message === void 0) onChange(parsed);
|
|
2989
2999
|
};
|
|
2990
3000
|
const isReady = () => {
|
|
2991
|
-
if (!
|
|
3001
|
+
if (!editing) return true;
|
|
2992
3002
|
const message = verdict(text);
|
|
2993
3003
|
onError?.(message);
|
|
2994
3004
|
return message === void 0;
|
|
2995
3005
|
};
|
|
2996
3006
|
return {
|
|
2997
|
-
display:
|
|
3007
|
+
display: editing ? text : value === "" ? "" : format(value, locale),
|
|
2998
3008
|
onText,
|
|
2999
3009
|
onFocus: () => {
|
|
3000
|
-
|
|
3001
|
-
setText(value === "" ? "" : formatTyped(value, locale));
|
|
3010
|
+
if (!editOnType) startEdit();
|
|
3002
3011
|
},
|
|
3003
3012
|
onBlur: () => {
|
|
3004
|
-
|
|
3005
|
-
if (verdict(text) !== void 0) onError?.(verdict(text));
|
|
3013
|
+
setEditing(false);
|
|
3014
|
+
if (editing && verdict(text) !== void 0) onError?.(verdict(text));
|
|
3015
|
+
},
|
|
3016
|
+
onEdit: (replacement) => {
|
|
3017
|
+
if (editing) return false;
|
|
3018
|
+
if (replacement !== void 0) onText(replacement);
|
|
3019
|
+
else startEdit();
|
|
3020
|
+
return replacement !== void 0;
|
|
3006
3021
|
},
|
|
3007
3022
|
isReady
|
|
3008
3023
|
};
|
|
@@ -3018,6 +3033,51 @@ function closedFieldMinWidth(text, iconRoom) {
|
|
|
3018
3033
|
const chars = Math.max(text.length, PLACEHOLDER_CHARS);
|
|
3019
3034
|
return Math.ceil(chars * FONT_PX * GLYPH_EM) + PAD_INLINE + iconRoom + BORDER + BORDER;
|
|
3020
3035
|
}
|
|
3036
|
+
|
|
3037
|
+
// src/DatePicker/utils/typedEdit.ts
|
|
3038
|
+
var DELETE_KEYS = /* @__PURE__ */ new Set(["Backspace", "Delete"]);
|
|
3039
|
+
function isPrintable(event) {
|
|
3040
|
+
return event.key.length === 1 && !event.ctrlKey && !event.metaKey;
|
|
3041
|
+
}
|
|
3042
|
+
function selection(input) {
|
|
3043
|
+
const end = input.selectionEnd ?? input.value.length;
|
|
3044
|
+
return [input.selectionStart ?? end, end];
|
|
3045
|
+
}
|
|
3046
|
+
function editedText(input, insert) {
|
|
3047
|
+
const [start, end] = selection(input);
|
|
3048
|
+
return { text: input.value.slice(0, start) + insert + input.value.slice(end), caret: start + insert.length };
|
|
3049
|
+
}
|
|
3050
|
+
function placeCaret(input, caret) {
|
|
3051
|
+
requestAnimationFrame(() => input.setSelectionRange(caret, caret));
|
|
3052
|
+
}
|
|
3053
|
+
function typedEditBind(typed) {
|
|
3054
|
+
const start = (event, insert) => {
|
|
3055
|
+
const input = event.currentTarget;
|
|
3056
|
+
const [from, to] = selection(input);
|
|
3057
|
+
if (from === to) {
|
|
3058
|
+
typed.onEdit();
|
|
3059
|
+
return;
|
|
3060
|
+
}
|
|
3061
|
+
const edit = editedText(input, insert);
|
|
3062
|
+
if (!typed.onEdit(edit.text)) return;
|
|
3063
|
+
event.preventDefault();
|
|
3064
|
+
placeCaret(input, edit.caret);
|
|
3065
|
+
};
|
|
3066
|
+
return {
|
|
3067
|
+
onEditKey: (event) => {
|
|
3068
|
+
if (isPrintable(event)) start(event, event.key);
|
|
3069
|
+
else if (DELETE_KEYS.has(event.key)) start(event, "");
|
|
3070
|
+
},
|
|
3071
|
+
onPaste: (event) => start(event, event.clipboardData.getData("text")),
|
|
3072
|
+
onCut: (event) => {
|
|
3073
|
+
const input = event.currentTarget;
|
|
3074
|
+
const [from, to] = selection(input);
|
|
3075
|
+
if (from === to) return;
|
|
3076
|
+
event.clipboardData.setData("text/plain", input.value.slice(from, to));
|
|
3077
|
+
start(event, "");
|
|
3078
|
+
}
|
|
3079
|
+
};
|
|
3080
|
+
}
|
|
3021
3081
|
var SINGLE_PICKER_WIDTH = 340;
|
|
3022
3082
|
var ICON_ROOM = 48;
|
|
3023
3083
|
var ICON_SLOT = { position: "absolute", right: 2, top: 0, bottom: 0, display: "flex", alignItems: "center" };
|
|
@@ -3030,7 +3090,8 @@ function DatePickerInput({ fieldProps, context, onTypedError }) {
|
|
|
3030
3090
|
const anchorRef = React37.useRef(null);
|
|
3031
3091
|
const inputRef = React37.useRef(null);
|
|
3032
3092
|
const bounds = { min, max };
|
|
3033
|
-
const typed = useTypedDate({ value, onChange, bounds, format: formatDisplay, onError: onTypedError });
|
|
3093
|
+
const typed = useTypedDate({ value, onChange, bounds, format: formatDisplay, onError: onTypedError, editOnType: true });
|
|
3094
|
+
const edit = typedEditBind(typed);
|
|
3034
3095
|
const { style, focusBind, hoverBind } = useThemedInput({ hasError: context.hasError, editable: !disabled });
|
|
3035
3096
|
const focus = focusBind;
|
|
3036
3097
|
const webA11y = webFieldA11y({ describedById: context.describedById, hasError: context.hasError, required });
|
|
@@ -3042,6 +3103,7 @@ function DatePickerInput({ fieldProps, context, onTypedError }) {
|
|
|
3042
3103
|
close();
|
|
3043
3104
|
};
|
|
3044
3105
|
const onKeyDown = (event) => {
|
|
3106
|
+
edit.onEditKey(event);
|
|
3045
3107
|
if (event.key === "ArrowDown" && event.altKey) {
|
|
3046
3108
|
event.preventDefault();
|
|
3047
3109
|
setOpen(true);
|
|
@@ -3076,7 +3138,9 @@ function DatePickerInput({ fieldProps, context, onTypedError }) {
|
|
|
3076
3138
|
focus.onFocus?.(event);
|
|
3077
3139
|
typed.onFocus();
|
|
3078
3140
|
},
|
|
3079
|
-
onKeyDown
|
|
3141
|
+
onKeyDown,
|
|
3142
|
+
onCut: edit.onCut,
|
|
3143
|
+
onPaste: edit.onPaste
|
|
3080
3144
|
}
|
|
3081
3145
|
),
|
|
3082
3146
|
/* @__PURE__ */ jsxRuntime.jsx("div", { style: ICON_SLOT, children: /* @__PURE__ */ jsxRuntime.jsx(uiButtons.IconButton, { accessibilityHint: labels.openCalendarHint, accessibilityLabel: labels.openCalendar, appearance: "ghost", disabled, renderIcon: (color) => /* @__PURE__ */ jsxRuntime.jsx(Glyph, { color, name: "calendar" /* Calendar */ }), testID: `${testID}-calendar`, onPress: () => setOpen((current) => !current) }) }),
|
|
@@ -3300,8 +3364,8 @@ function WebDateRange({ value, onChange, onSubmit, fromLabel, toLabel, hint, tes
|
|
|
3300
3364
|
const [toError, setToError] = React37.useState(void 0);
|
|
3301
3365
|
const anchorRef = React37.useRef(null);
|
|
3302
3366
|
const fromRef = React37.useRef(null);
|
|
3303
|
-
const from = useTypedDate({ value: value.from, onChange: (next) => onChange({ from: next, to: value.to }), bounds: { max: orNone(value.to) }, format: formatShort, onError: setFromError, rangeMessage: labels.rangeOrder });
|
|
3304
|
-
const to = useTypedDate({ value: value.to, onChange: (next) => onChange({ from: value.from, to: next }), bounds: { min: orNone(value.from) }, format: formatShort, onError: setToError, rangeMessage: labels.rangeOrder });
|
|
3367
|
+
const from = useTypedDate({ value: value.from, onChange: (next) => onChange({ from: next, to: value.to }), bounds: { max: orNone(value.to) }, format: formatShort, onError: setFromError, rangeMessage: labels.rangeOrder, editOnType: true });
|
|
3368
|
+
const to = useTypedDate({ value: value.to, onChange: (next) => onChange({ from: value.from, to: next }), bounds: { min: orNone(value.from) }, format: formatShort, onError: setToError, rangeMessage: labels.rangeOrder, editOnType: true });
|
|
3305
3369
|
const { style, focusBind, hoverBind } = useThemedInput({ hasError: context.hasError, editable: true });
|
|
3306
3370
|
const focus = focusBind;
|
|
3307
3371
|
const webA11y = webFieldA11y({ describedById: context.describedById, hasError: context.hasError });
|
|
@@ -3319,31 +3383,39 @@ function WebDateRange({ value, onChange, onSubmit, fromLabel, toLabel, hint, tes
|
|
|
3319
3383
|
const ready = [from.isReady(), to.isReady()].every(Boolean);
|
|
3320
3384
|
if (ready) onSubmit();
|
|
3321
3385
|
};
|
|
3322
|
-
const segment = (side, typed) =>
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3386
|
+
const segment = (side, typed) => {
|
|
3387
|
+
const edit = typedEditBind(typed);
|
|
3388
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3389
|
+
"input",
|
|
3390
|
+
{
|
|
3391
|
+
...webA11y,
|
|
3392
|
+
ref: side === "from" /* From */ ? fromRef : void 0,
|
|
3393
|
+
"aria-label": side === "from" /* From */ ? fromLabel : toLabel,
|
|
3394
|
+
autoComplete: "off",
|
|
3395
|
+
"data-testid": `${testID}-${side}`,
|
|
3396
|
+
id: side === "from" /* From */ ? context.controlId : void 0,
|
|
3397
|
+
style: SEGMENT,
|
|
3398
|
+
title: hint,
|
|
3399
|
+
type: "text",
|
|
3400
|
+
value: typed.display,
|
|
3401
|
+
onBlur: (event) => {
|
|
3402
|
+
focus.onBlur?.(event);
|
|
3403
|
+
typed.onBlur();
|
|
3404
|
+
},
|
|
3405
|
+
onChange: (event) => typed.onText(event.target.value),
|
|
3406
|
+
onFocus: (event) => {
|
|
3407
|
+
focus.onFocus?.(event);
|
|
3408
|
+
typed.onFocus();
|
|
3409
|
+
},
|
|
3410
|
+
onCut: edit.onCut,
|
|
3411
|
+
onKeyDown: (event) => {
|
|
3412
|
+
edit.onEditKey(event);
|
|
3413
|
+
onKeyDown(event);
|
|
3414
|
+
},
|
|
3415
|
+
onPaste: edit.onPaste
|
|
3416
|
+
}
|
|
3417
|
+
);
|
|
3418
|
+
};
|
|
3347
3419
|
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { ref: anchorRef, style: anchorStyles.wrap, children: [
|
|
3348
3420
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { ...hoverBind, style: { ...buildNativeInputStyle(style), display: "flex", alignItems: "center", gap: GAP5, paddingInlineEnd: ICON_ROOM }, children: [
|
|
3349
3421
|
segment("from" /* From */, from),
|
|
@@ -4923,15 +4995,15 @@ function rawCaretAfterChange(previous, previousCaret, next) {
|
|
|
4923
4995
|
|
|
4924
4996
|
// src/IbanInput/hooks/useIbanCaret.ts
|
|
4925
4997
|
function useIbanCaret(display) {
|
|
4926
|
-
const [
|
|
4998
|
+
const [selection2, setSelection] = React37.useState({ start: display.length, end: display.length });
|
|
4927
4999
|
const onSelectionChange = React37.useCallback((event) => {
|
|
4928
5000
|
setSelection(event.nativeEvent.selection);
|
|
4929
5001
|
}, []);
|
|
4930
5002
|
const placeAfterEdit = React37.useCallback((text) => {
|
|
4931
|
-
const caret = caretAfterEdit(text, rawCaretAfterChange(display,
|
|
5003
|
+
const caret = caretAfterEdit(text, rawCaretAfterChange(display, selection2.end, text));
|
|
4932
5004
|
setSelection({ start: caret, end: caret });
|
|
4933
|
-
}, [display,
|
|
4934
|
-
const clamped = { start: Math.min(
|
|
5005
|
+
}, [display, selection2.end]);
|
|
5006
|
+
const clamped = { start: Math.min(selection2.start, display.length), end: Math.min(selection2.end, display.length) };
|
|
4935
5007
|
return { selection: clamped, onSelectionChange, placeAfterEdit };
|
|
4936
5008
|
}
|
|
4937
5009
|
var FONT_SIZE = 14;
|
|
@@ -5038,7 +5110,7 @@ function IbanInput({ value, onChange, onVerdict, accessibilityLabel, accessibili
|
|
|
5038
5110
|
const { verdict, onEdit, onLeave } = useBlurVerdict(validate);
|
|
5039
5111
|
const message = value === "" ? null : rejectionMessage(verdict?.rejection ?? null, "None" /* None */, rejectionLabels);
|
|
5040
5112
|
const counter = ibanCounter(draft);
|
|
5041
|
-
const { selection, onSelectionChange, placeAfterEdit } = useIbanCaret(draft.display);
|
|
5113
|
+
const { selection: selection2, onSelectionChange, placeAfterEdit } = useIbanCaret(draft.display);
|
|
5042
5114
|
const onChangeText = React37.useCallback((text) => {
|
|
5043
5115
|
onEdit();
|
|
5044
5116
|
onVerdict?.(null);
|
|
@@ -5067,7 +5139,7 @@ function IbanInput({ value, onChange, onVerdict, accessibilityLabel, accessibili
|
|
|
5067
5139
|
autoCorrect: false,
|
|
5068
5140
|
placeholder: draft.display === "" ? placeholder : void 0,
|
|
5069
5141
|
placeholderTextColor: colors.textSecondary,
|
|
5070
|
-
selection,
|
|
5142
|
+
selection: selection2,
|
|
5071
5143
|
spellCheck: false,
|
|
5072
5144
|
style: [ghostStyles.mono, ghostStyles.input, { color: colors.text }],
|
|
5073
5145
|
testID,
|