@dloizides/ui-forms 1.42.1 → 1.42.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.
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +63 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +63 -14
- 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) };
|
|
@@ -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,31 @@ 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 coversAll(input) {
|
|
3040
|
+
const { selectionStart, selectionEnd, value } = input;
|
|
3041
|
+
return value !== "" && selectionStart === 0 && selectionEnd === value.length;
|
|
3042
|
+
}
|
|
3043
|
+
function isPrintable(event) {
|
|
3044
|
+
return event.key.length === 1 && !event.ctrlKey && !event.metaKey;
|
|
3045
|
+
}
|
|
3046
|
+
function typedEditBind(typed) {
|
|
3047
|
+
const start = (event, replacement) => {
|
|
3048
|
+
if (typed.onEdit(coversAll(event.currentTarget) ? replacement : void 0)) event.preventDefault();
|
|
3049
|
+
};
|
|
3050
|
+
return {
|
|
3051
|
+
onEditKey: (event) => {
|
|
3052
|
+
if (isPrintable(event)) start(event, event.key);
|
|
3053
|
+
else if (DELETE_KEYS.has(event.key)) start(event, "");
|
|
3054
|
+
},
|
|
3055
|
+
onPaste: (event) => start(event, event.clipboardData.getData("text")),
|
|
3056
|
+
onCut: (event) => {
|
|
3057
|
+
if (!coversAll(event.currentTarget)) typed.onEdit();
|
|
3058
|
+
}
|
|
3059
|
+
};
|
|
3060
|
+
}
|
|
3021
3061
|
var SINGLE_PICKER_WIDTH = 340;
|
|
3022
3062
|
var ICON_ROOM = 48;
|
|
3023
3063
|
var ICON_SLOT = { position: "absolute", right: 2, top: 0, bottom: 0, display: "flex", alignItems: "center" };
|
|
@@ -3030,7 +3070,8 @@ function DatePickerInput({ fieldProps, context, onTypedError }) {
|
|
|
3030
3070
|
const anchorRef = React37.useRef(null);
|
|
3031
3071
|
const inputRef = React37.useRef(null);
|
|
3032
3072
|
const bounds = { min, max };
|
|
3033
|
-
const typed = useTypedDate({ value, onChange, bounds, format: formatDisplay, onError: onTypedError });
|
|
3073
|
+
const typed = useTypedDate({ value, onChange, bounds, format: formatDisplay, onError: onTypedError, editOnType: true });
|
|
3074
|
+
const edit = typedEditBind(typed);
|
|
3034
3075
|
const { style, focusBind, hoverBind } = useThemedInput({ hasError: context.hasError, editable: !disabled });
|
|
3035
3076
|
const focus = focusBind;
|
|
3036
3077
|
const webA11y = webFieldA11y({ describedById: context.describedById, hasError: context.hasError, required });
|
|
@@ -3042,6 +3083,7 @@ function DatePickerInput({ fieldProps, context, onTypedError }) {
|
|
|
3042
3083
|
close();
|
|
3043
3084
|
};
|
|
3044
3085
|
const onKeyDown = (event) => {
|
|
3086
|
+
edit.onEditKey(event);
|
|
3045
3087
|
if (event.key === "ArrowDown" && event.altKey) {
|
|
3046
3088
|
event.preventDefault();
|
|
3047
3089
|
setOpen(true);
|
|
@@ -3076,7 +3118,9 @@ function DatePickerInput({ fieldProps, context, onTypedError }) {
|
|
|
3076
3118
|
focus.onFocus?.(event);
|
|
3077
3119
|
typed.onFocus();
|
|
3078
3120
|
},
|
|
3079
|
-
onKeyDown
|
|
3121
|
+
onKeyDown,
|
|
3122
|
+
onCut: edit.onCut,
|
|
3123
|
+
onPaste: edit.onPaste
|
|
3080
3124
|
}
|
|
3081
3125
|
),
|
|
3082
3126
|
/* @__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 +3344,8 @@ function WebDateRange({ value, onChange, onSubmit, fromLabel, toLabel, hint, tes
|
|
|
3300
3344
|
const [toError, setToError] = React37.useState(void 0);
|
|
3301
3345
|
const anchorRef = React37.useRef(null);
|
|
3302
3346
|
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 });
|
|
3347
|
+
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 });
|
|
3348
|
+
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
3349
|
const { style, focusBind, hoverBind } = useThemedInput({ hasError: context.hasError, editable: true });
|
|
3306
3350
|
const focus = focusBind;
|
|
3307
3351
|
const webA11y = webFieldA11y({ describedById: context.describedById, hasError: context.hasError });
|
|
@@ -3341,7 +3385,12 @@ function WebDateRange({ value, onChange, onSubmit, fromLabel, toLabel, hint, tes
|
|
|
3341
3385
|
focus.onFocus?.(event);
|
|
3342
3386
|
typed.onFocus();
|
|
3343
3387
|
},
|
|
3344
|
-
|
|
3388
|
+
onCut: typedEditBind(typed).onCut,
|
|
3389
|
+
onKeyDown: (event) => {
|
|
3390
|
+
typedEditBind(typed).onEditKey(event);
|
|
3391
|
+
onKeyDown(event);
|
|
3392
|
+
},
|
|
3393
|
+
onPaste: typedEditBind(typed).onPaste
|
|
3345
3394
|
}
|
|
3346
3395
|
);
|
|
3347
3396
|
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { ref: anchorRef, style: anchorStyles.wrap, children: [
|