@dloizides/ui-forms 1.42.2 → 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.mjs CHANGED
@@ -2833,17 +2833,17 @@ var BOLD2 = 700;
2833
2833
  var ROW = { display: "flex" };
2834
2834
  var EMPTY = { width: DAY_CELL_PX, height: DAY_CELL_PX, flexShrink: 0 };
2835
2835
  var FALLBACK = { year: 1970, month: 1};
2836
- function MonthGrid({ month, selection, focusedDay, bounds, testID, onPick, onKey, showCaption = false, motion }) {
2836
+ function MonthGrid({ month, selection: selection2, focusedDay, bounds, testID, onPick, onKey, showCaption = false, motion }) {
2837
2837
  const { labels, locale, today, firstDay } = useDatePickerConfig();
2838
2838
  const colors = usePickerColors();
2839
2839
  const parts = parseIso(month) ?? FALLBACK;
2840
2840
  const weeks = useMemo(() => buildMonthGrid(parts.year, parts.month, firstDay), [parts.year, parts.month, firstDay]);
2841
2841
  const weekdays = useMemo(() => weekdayNames(locale, firstDay), [locale, firstDay]);
2842
2842
  const title = formatMonthYear(month, locale);
2843
- const end = selection.to === "" ? selection.from : selection.to;
2843
+ const end = selection2.to === "" ? selection2.from : selection2.to;
2844
2844
  const stateOf = (iso) => ({
2845
- inRange: selection.from !== "" && iso >= selection.from && iso <= end,
2846
- isEnd: iso === selection.from || iso === selection.to,
2845
+ inRange: selection2.from !== "" && iso >= selection2.from && iso <= end,
2846
+ isEnd: iso === selection2.from || iso === selection2.to,
2847
2847
  isToday: iso === today,
2848
2848
  enabled: isWithinBounds(iso, bounds.min, bounds.max),
2849
2849
  focusable: iso === focusedDay
@@ -3029,16 +3029,32 @@ function closedFieldMinWidth(text, iconRoom) {
3029
3029
 
3030
3030
  // src/DatePicker/utils/typedEdit.ts
3031
3031
  var DELETE_KEYS = /* @__PURE__ */ new Set(["Backspace", "Delete"]);
3032
- function coversAll(input) {
3033
- const { selectionStart, selectionEnd, value } = input;
3034
- return value !== "" && selectionStart === 0 && selectionEnd === value.length;
3035
- }
3036
3032
  function isPrintable(event) {
3037
3033
  return event.key.length === 1 && !event.ctrlKey && !event.metaKey;
3038
3034
  }
3035
+ function selection(input) {
3036
+ const end = input.selectionEnd ?? input.value.length;
3037
+ return [input.selectionStart ?? end, end];
3038
+ }
3039
+ function editedText(input, insert) {
3040
+ const [start, end] = selection(input);
3041
+ return { text: input.value.slice(0, start) + insert + input.value.slice(end), caret: start + insert.length };
3042
+ }
3043
+ function placeCaret(input, caret) {
3044
+ requestAnimationFrame(() => input.setSelectionRange(caret, caret));
3045
+ }
3039
3046
  function typedEditBind(typed) {
3040
- const start = (event, replacement) => {
3041
- if (typed.onEdit(coversAll(event.currentTarget) ? replacement : void 0)) event.preventDefault();
3047
+ const start = (event, insert) => {
3048
+ const input = event.currentTarget;
3049
+ const [from, to] = selection(input);
3050
+ if (from === to) {
3051
+ typed.onEdit();
3052
+ return;
3053
+ }
3054
+ const edit = editedText(input, insert);
3055
+ if (!typed.onEdit(edit.text)) return;
3056
+ event.preventDefault();
3057
+ placeCaret(input, edit.caret);
3042
3058
  };
3043
3059
  return {
3044
3060
  onEditKey: (event) => {
@@ -3047,7 +3063,11 @@ function typedEditBind(typed) {
3047
3063
  },
3048
3064
  onPaste: (event) => start(event, event.clipboardData.getData("text")),
3049
3065
  onCut: (event) => {
3050
- if (!coversAll(event.currentTarget)) typed.onEdit();
3066
+ const input = event.currentTarget;
3067
+ const [from, to] = selection(input);
3068
+ if (from === to) return;
3069
+ event.clipboardData.setData("text/plain", input.value.slice(from, to));
3070
+ start(event, "");
3051
3071
  }
3052
3072
  };
3053
3073
  }
@@ -3356,36 +3376,39 @@ function WebDateRange({ value, onChange, onSubmit, fromLabel, toLabel, hint, tes
3356
3376
  const ready = [from.isReady(), to.isReady()].every(Boolean);
3357
3377
  if (ready) onSubmit();
3358
3378
  };
3359
- const segment = (side, typed) => /* @__PURE__ */ jsx(
3360
- "input",
3361
- {
3362
- ...webA11y,
3363
- ref: side === "from" /* From */ ? fromRef : void 0,
3364
- "aria-label": side === "from" /* From */ ? fromLabel : toLabel,
3365
- autoComplete: "off",
3366
- "data-testid": `${testID}-${side}`,
3367
- id: side === "from" /* From */ ? context.controlId : void 0,
3368
- style: SEGMENT,
3369
- title: hint,
3370
- type: "text",
3371
- value: typed.display,
3372
- onBlur: (event) => {
3373
- focus.onBlur?.(event);
3374
- typed.onBlur();
3375
- },
3376
- onChange: (event) => typed.onText(event.target.value),
3377
- onFocus: (event) => {
3378
- focus.onFocus?.(event);
3379
- typed.onFocus();
3380
- },
3381
- onCut: typedEditBind(typed).onCut,
3382
- onKeyDown: (event) => {
3383
- typedEditBind(typed).onEditKey(event);
3384
- onKeyDown(event);
3385
- },
3386
- onPaste: typedEditBind(typed).onPaste
3387
- }
3388
- );
3379
+ const segment = (side, typed) => {
3380
+ const edit = typedEditBind(typed);
3381
+ return /* @__PURE__ */ jsx(
3382
+ "input",
3383
+ {
3384
+ ...webA11y,
3385
+ ref: side === "from" /* From */ ? fromRef : void 0,
3386
+ "aria-label": side === "from" /* From */ ? fromLabel : toLabel,
3387
+ autoComplete: "off",
3388
+ "data-testid": `${testID}-${side}`,
3389
+ id: side === "from" /* From */ ? context.controlId : void 0,
3390
+ style: SEGMENT,
3391
+ title: hint,
3392
+ type: "text",
3393
+ value: typed.display,
3394
+ onBlur: (event) => {
3395
+ focus.onBlur?.(event);
3396
+ typed.onBlur();
3397
+ },
3398
+ onChange: (event) => typed.onText(event.target.value),
3399
+ onFocus: (event) => {
3400
+ focus.onFocus?.(event);
3401
+ typed.onFocus();
3402
+ },
3403
+ onCut: edit.onCut,
3404
+ onKeyDown: (event) => {
3405
+ edit.onEditKey(event);
3406
+ onKeyDown(event);
3407
+ },
3408
+ onPaste: edit.onPaste
3409
+ }
3410
+ );
3411
+ };
3389
3412
  return /* @__PURE__ */ jsxs(View, { ref: anchorRef, style: anchorStyles.wrap, children: [
3390
3413
  /* @__PURE__ */ jsxs("div", { ...hoverBind, style: { ...buildNativeInputStyle(style), display: "flex", alignItems: "center", gap: GAP5, paddingInlineEnd: ICON_ROOM }, children: [
3391
3414
  segment("from" /* From */, from),
@@ -4965,15 +4988,15 @@ function rawCaretAfterChange(previous, previousCaret, next) {
4965
4988
 
4966
4989
  // src/IbanInput/hooks/useIbanCaret.ts
4967
4990
  function useIbanCaret(display) {
4968
- const [selection, setSelection] = useState({ start: display.length, end: display.length });
4991
+ const [selection2, setSelection] = useState({ start: display.length, end: display.length });
4969
4992
  const onSelectionChange = useCallback((event) => {
4970
4993
  setSelection(event.nativeEvent.selection);
4971
4994
  }, []);
4972
4995
  const placeAfterEdit = useCallback((text) => {
4973
- const caret = caretAfterEdit(text, rawCaretAfterChange(display, selection.end, text));
4996
+ const caret = caretAfterEdit(text, rawCaretAfterChange(display, selection2.end, text));
4974
4997
  setSelection({ start: caret, end: caret });
4975
- }, [display, selection.end]);
4976
- const clamped = { start: Math.min(selection.start, display.length), end: Math.min(selection.end, display.length) };
4998
+ }, [display, selection2.end]);
4999
+ const clamped = { start: Math.min(selection2.start, display.length), end: Math.min(selection2.end, display.length) };
4977
5000
  return { selection: clamped, onSelectionChange, placeAfterEdit };
4978
5001
  }
4979
5002
  var FONT_SIZE = 14;
@@ -5080,7 +5103,7 @@ function IbanInput({ value, onChange, onVerdict, accessibilityLabel, accessibili
5080
5103
  const { verdict, onEdit, onLeave } = useBlurVerdict(validate);
5081
5104
  const message = value === "" ? null : rejectionMessage(verdict?.rejection ?? null, "None" /* None */, rejectionLabels);
5082
5105
  const counter = ibanCounter(draft);
5083
- const { selection, onSelectionChange, placeAfterEdit } = useIbanCaret(draft.display);
5106
+ const { selection: selection2, onSelectionChange, placeAfterEdit } = useIbanCaret(draft.display);
5084
5107
  const onChangeText = useCallback((text) => {
5085
5108
  onEdit();
5086
5109
  onVerdict?.(null);
@@ -5109,7 +5132,7 @@ function IbanInput({ value, onChange, onVerdict, accessibilityLabel, accessibili
5109
5132
  autoCorrect: false,
5110
5133
  placeholder: draft.display === "" ? placeholder : void 0,
5111
5134
  placeholderTextColor: colors.textSecondary,
5112
- selection,
5135
+ selection: selection2,
5113
5136
  spellCheck: false,
5114
5137
  style: [ghostStyles.mono, ghostStyles.input, { color: colors.text }],
5115
5138
  testID,