lite-phone-input 0.1.0 → 0.2.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/README.md CHANGED
@@ -55,12 +55,11 @@ const phone = PhoneInput.mount(document.getElementById('phone'), {
55
55
  ### React
56
56
 
57
57
  ```jsx
58
- import { useRef, useState } from 'react';
58
+ import { useRef } from 'react';
59
59
  import { PhoneInput } from 'lite-phone-input/react';
60
60
  import 'lite-phone-input/styles';
61
61
 
62
62
  function MyForm() {
63
- const [value, setValue] = useState('');
64
63
  const phoneRef = useRef(null);
65
64
 
66
65
  return (
@@ -68,8 +67,8 @@ function MyForm() {
68
67
  ref={phoneRef}
69
68
  defaultCountry="US"
70
69
  separateDialCode
71
- value={value}
72
- onChange={(e164) => setValue(e164)}
70
+ initialValue="+12025551234"
71
+ onChange={(e164) => console.log(e164)}
73
72
  name="phone"
74
73
  aria-label="Phone number"
75
74
  />
@@ -104,7 +103,7 @@ Same API as React. Uses `preact/hooks` directly — no `preact/compat` required.
104
103
  |---|---|
105
104
  | [Getting Started](docs/getting-started.md) | Installation and first render |
106
105
  | [Vanilla JS Guide](docs/vanilla-guide.md) | Mounting, methods, callbacks |
107
- | [React Guide](docs/react-guide.md) | Controlled/uncontrolled, form libraries |
106
+ | [React Guide](docs/react-guide.md) | Usage, ref methods, form libraries |
108
107
  | [Preact Guide](docs/preact-guide.md) | Preact-specific setup |
109
108
  | [API Reference](docs/api-reference.md) | All options, methods, and types |
110
109
  | [Styling & Theming](docs/styling.md) | CSS variables, BEM classes, dark mode |
@@ -2493,9 +2493,9 @@ var phone_countries_default = [
2493
2493
  var TRAILING_SEP = /[\s\-]+$/;
2494
2494
  var FALLBACK_GROUP = /(.{4})(?=.)/g;
2495
2495
  var NON_ASCII_DIGITS = /[\u0660-\u0669\u06F0-\u06F9]/g;
2496
- function isDigit(ch) {
2496
+ function isRelevantChar(ch) {
2497
2497
  const c = ch.charCodeAt(0);
2498
- return c >= 48 && c <= 57;
2498
+ return c >= 48 && c <= 57 || c === 43;
2499
2499
  }
2500
2500
  function formatPhone(digits, pattern) {
2501
2501
  if (!digits) return "";
@@ -2518,18 +2518,19 @@ function formatPhone(digits, pattern) {
2518
2518
  return result.replace(TRAILING_SEP, "");
2519
2519
  }
2520
2520
  function getCursorPosition(oldValue, oldCursor, newValue) {
2521
- let digitsBeforeCursor = 0;
2521
+ if (oldCursor === 0) return 0;
2522
+ let relevantBeforeCursor = 0;
2522
2523
  for (let i = 0; i < oldCursor && i < oldValue.length; i++) {
2523
- if (isDigit(oldValue[i])) {
2524
- digitsBeforeCursor++;
2524
+ if (isRelevantChar(oldValue[i])) {
2525
+ relevantBeforeCursor++;
2525
2526
  }
2526
2527
  }
2527
- let digitCount = 0;
2528
+ let count = 0;
2528
2529
  for (let i = 0; i < newValue.length; i++) {
2529
- if (isDigit(newValue[i])) {
2530
- digitCount++;
2530
+ if (isRelevantChar(newValue[i])) {
2531
+ count++;
2531
2532
  }
2532
- if (digitCount === digitsBeforeCursor) {
2533
+ if (count === relevantBeforeCursor) {
2533
2534
  return i + 1;
2534
2535
  }
2535
2536
  }