@aspprev/versi-ds 0.4.3 → 0.4.6

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.
@@ -88,6 +88,23 @@ var FieldFrame_default = FieldFrame;
88
88
 
89
89
  // src/components/input/Input.tsx
90
90
  import { Fragment, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
91
+ function getFormattedCaretPosition(rawValue, formattedValue, selectionStart, formatter, sanitize) {
92
+ if (selectionStart === null) return null;
93
+ if (selectionStart >= rawValue.length) return formattedValue.length;
94
+ const formattedSuffix = sanitize(formatter(rawValue.slice(selectionStart)));
95
+ return Math.max(
96
+ 0,
97
+ Math.min(formattedValue.length, formattedValue.length - formattedSuffix.length)
98
+ );
99
+ }
100
+ function restoreCaretPosition(inputRef, position) {
101
+ if (position === null || typeof window === "undefined") return;
102
+ window.requestAnimationFrame(() => {
103
+ const input = inputRef.current;
104
+ if (!input || document.activeElement !== input) return;
105
+ input.setSelectionRange(position, position);
106
+ });
107
+ }
91
108
  var BaseInput = React.forwardRef((props, ref) => /* @__PURE__ */ jsx2(
92
109
  "input",
93
110
  {
@@ -150,6 +167,7 @@ var Input = ({
150
167
  prefix,
151
168
  suffix,
152
169
  mask,
170
+ formatter,
153
171
  disabled,
154
172
  error,
155
173
  disallowSpaces,
@@ -248,6 +266,44 @@ var Input = ({
248
266
  };
249
267
  const renderMaskedInput = (inputType) => {
250
268
  const autoCompleteValue = rest.autoComplete;
269
+ if (formatter) {
270
+ const currentValue = String(safeValue(field.value));
271
+ return /* @__PURE__ */ jsx2(
272
+ "input",
273
+ {
274
+ ...rest,
275
+ ...accessibilityProps,
276
+ name,
277
+ ref: inputRef,
278
+ type: inputType === "date" ? "text" : inputType,
279
+ value: currentValue,
280
+ onChange: (event) => {
281
+ const rawValue = event.target.value;
282
+ const formattedValue = sanitizeValue(formatter(rawValue));
283
+ const caretPosition = getFormattedCaretPosition(
284
+ rawValue,
285
+ formattedValue,
286
+ event.target.selectionStart,
287
+ formatter,
288
+ sanitizeValue
289
+ );
290
+ helpers.setValue(formattedValue);
291
+ restoreCaretPosition(inputRef, caretPosition);
292
+ rest.onChange?.({
293
+ ...event,
294
+ target: { ...event.target, value: formattedValue },
295
+ currentTarget: { ...event.currentTarget, value: formattedValue }
296
+ });
297
+ },
298
+ onBlur: field.onBlur,
299
+ onPaste: handlePasteFormik,
300
+ placeholder,
301
+ className: classNames2(FIELD_INPUT_CLASS, className),
302
+ autoComplete: autoCompleteValue,
303
+ disabled
304
+ }
305
+ );
306
+ }
251
307
  if (mask === "currency") {
252
308
  const rawCurrencyValue = typeof field.value === "string" || typeof field.value === "number" ? field.value : "";
253
309
  return /* @__PURE__ */ jsx2(
@@ -531,6 +587,7 @@ var InputStandalone = (props) => {
531
587
  prefix,
532
588
  suffix,
533
589
  mask,
590
+ formatter,
534
591
  disabled,
535
592
  error,
536
593
  errorText,
@@ -615,6 +672,41 @@ var InputStandalone = (props) => {
615
672
  };
616
673
  const renderMaskedInput = (inputType) => {
617
674
  const autoCompleteValue = rest.autoComplete;
675
+ if (formatter) {
676
+ const currentValue = String(safeValue(rest.value));
677
+ return /* @__PURE__ */ jsx2(
678
+ "input",
679
+ {
680
+ ...rest,
681
+ ...accessibilityProps,
682
+ ref: inputRef,
683
+ type: inputType === "date" ? "text" : inputType,
684
+ value: currentValue,
685
+ onChange: (event) => {
686
+ const rawValue = event.target.value;
687
+ const formattedValue = sanitizeValue(formatter(rawValue));
688
+ const caretPosition = getFormattedCaretPosition(
689
+ rawValue,
690
+ formattedValue,
691
+ event.target.selectionStart,
692
+ formatter,
693
+ sanitizeValue
694
+ );
695
+ restoreCaretPosition(inputRef, caretPosition);
696
+ rest.onChange?.({
697
+ ...event,
698
+ target: { ...event.target, value: formattedValue },
699
+ currentTarget: { ...event.currentTarget, value: formattedValue }
700
+ });
701
+ },
702
+ onPaste: handlePasteStandalone,
703
+ placeholder: rest.placeholder,
704
+ className: classNames2(FIELD_INPUT_CLASS, className),
705
+ autoComplete: autoCompleteValue,
706
+ disabled
707
+ }
708
+ );
709
+ }
618
710
  if (mask === "currency") {
619
711
  const rawCurrencyValue = typeof rest.value === "string" || typeof rest.value === "number" ? rest.value : "";
620
712
  return /* @__PURE__ */ jsx2(
@@ -3653,4 +3745,4 @@ export {
3653
3745
  RadioCardGroup,
3654
3746
  OtpCodeInput_default
3655
3747
  };
3656
- //# sourceMappingURL=chunk-MC4MSOCM.js.map
3748
+ //# sourceMappingURL=chunk-CLXCB6LY.js.map