@zag-js/pin-input 1.31.0 → 1.32.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/dist/index.js CHANGED
@@ -149,6 +149,18 @@ function connect(service, normalize) {
149
149
  autoCapitalize: "none",
150
150
  autoComplete: prop("otp") ? "one-time-code" : "off",
151
151
  placeholder: focusedIndex === index ? "" : prop("placeholder"),
152
+ onPaste(event) {
153
+ const pastedValue = event.clipboardData?.getData("text/plain");
154
+ if (!pastedValue) return;
155
+ const isValid = isValidValue(pastedValue, prop("type"), prop("pattern"));
156
+ if (!isValid) {
157
+ send({ type: "VALUE.INVALID", value: pastedValue });
158
+ event.preventDefault();
159
+ return;
160
+ }
161
+ event.preventDefault();
162
+ send({ type: "INPUT.PASTE", value: pastedValue });
163
+ },
152
164
  onBeforeInput(event) {
153
165
  try {
154
166
  const value = domQuery.getBeforeInputValue(event);
@@ -157,7 +169,7 @@ function connect(service, normalize) {
157
169
  send({ type: "VALUE.INVALID", value });
158
170
  event.preventDefault();
159
171
  }
160
- if (value.length > 2) {
172
+ if (value.length > 1) {
161
173
  event.currentTarget.setSelectionRange(0, 1, "forward");
162
174
  }
163
175
  } catch {
@@ -166,7 +178,11 @@ function connect(service, normalize) {
166
178
  onChange(event) {
167
179
  const evt = domQuery.getNativeEvent(event);
168
180
  const { value } = event.currentTarget;
169
- if (evt.inputType === "insertFromPaste" || value.length > 2) {
181
+ if (evt.inputType === "insertFromPaste") {
182
+ event.currentTarget.value = value[0] || "";
183
+ return;
184
+ }
185
+ if (value.length > 2) {
170
186
  send({ type: "INPUT.PASTE", value });
171
187
  event.currentTarget.value = value[0];
172
188
  event.preventDefault();
package/dist/index.mjs CHANGED
@@ -147,6 +147,18 @@ function connect(service, normalize) {
147
147
  autoCapitalize: "none",
148
148
  autoComplete: prop("otp") ? "one-time-code" : "off",
149
149
  placeholder: focusedIndex === index ? "" : prop("placeholder"),
150
+ onPaste(event) {
151
+ const pastedValue = event.clipboardData?.getData("text/plain");
152
+ if (!pastedValue) return;
153
+ const isValid = isValidValue(pastedValue, prop("type"), prop("pattern"));
154
+ if (!isValid) {
155
+ send({ type: "VALUE.INVALID", value: pastedValue });
156
+ event.preventDefault();
157
+ return;
158
+ }
159
+ event.preventDefault();
160
+ send({ type: "INPUT.PASTE", value: pastedValue });
161
+ },
150
162
  onBeforeInput(event) {
151
163
  try {
152
164
  const value = getBeforeInputValue(event);
@@ -155,7 +167,7 @@ function connect(service, normalize) {
155
167
  send({ type: "VALUE.INVALID", value });
156
168
  event.preventDefault();
157
169
  }
158
- if (value.length > 2) {
170
+ if (value.length > 1) {
159
171
  event.currentTarget.setSelectionRange(0, 1, "forward");
160
172
  }
161
173
  } catch {
@@ -164,7 +176,11 @@ function connect(service, normalize) {
164
176
  onChange(event) {
165
177
  const evt = getNativeEvent(event);
166
178
  const { value } = event.currentTarget;
167
- if (evt.inputType === "insertFromPaste" || value.length > 2) {
179
+ if (evt.inputType === "insertFromPaste") {
180
+ event.currentTarget.value = value[0] || "";
181
+ return;
182
+ }
183
+ if (value.length > 2) {
168
184
  send({ type: "INPUT.PASTE", value });
169
185
  event.currentTarget.value = value[0];
170
186
  event.preventDefault();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/pin-input",
3
- "version": "1.31.0",
3
+ "version": "1.32.0",
4
4
  "description": "Core logic for the pin-input widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -26,11 +26,11 @@
26
26
  "url": "https://github.com/chakra-ui/zag/issues"
27
27
  },
28
28
  "dependencies": {
29
- "@zag-js/anatomy": "1.31.0",
30
- "@zag-js/dom-query": "1.31.0",
31
- "@zag-js/utils": "1.31.0",
32
- "@zag-js/core": "1.31.0",
33
- "@zag-js/types": "1.31.0"
29
+ "@zag-js/anatomy": "1.32.0",
30
+ "@zag-js/dom-query": "1.32.0",
31
+ "@zag-js/utils": "1.32.0",
32
+ "@zag-js/core": "1.32.0",
33
+ "@zag-js/types": "1.32.0"
34
34
  },
35
35
  "devDependencies": {
36
36
  "clean-package": "2.2.0"