@zag-js/pin-input 1.2.0 → 1.2.1
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 +11 -7
- package/dist/index.mjs +12 -8
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -23,6 +23,10 @@ var getInputEls = (ctx) => {
|
|
|
23
23
|
var getInputElAtIndex = (ctx, index) => getInputEls(ctx)[index];
|
|
24
24
|
var getFirstInputEl = (ctx) => getInputEls(ctx)[0];
|
|
25
25
|
var getHiddenInputEl = (ctx) => ctx.getById(getHiddenInputId(ctx));
|
|
26
|
+
var setInputValue = (inputEl, value) => {
|
|
27
|
+
inputEl.value = value;
|
|
28
|
+
inputEl.setAttribute("value", value);
|
|
29
|
+
};
|
|
26
30
|
|
|
27
31
|
// src/pin-input.utils.ts
|
|
28
32
|
var REGEX = {
|
|
@@ -200,11 +204,11 @@ function connect(service, normalize) {
|
|
|
200
204
|
}
|
|
201
205
|
},
|
|
202
206
|
onFocus() {
|
|
203
|
-
|
|
204
|
-
send({ type: "INPUT.FOCUS", index });
|
|
205
|
-
});
|
|
207
|
+
send({ type: "INPUT.FOCUS", index });
|
|
206
208
|
},
|
|
207
|
-
onBlur() {
|
|
209
|
+
onBlur(event) {
|
|
210
|
+
const target = event.relatedTarget;
|
|
211
|
+
if (domQuery.isHTMLElement(target) && target.dataset.ownedby === getRootId(scope)) return;
|
|
208
212
|
send({ type: "INPUT.BLUR", index });
|
|
209
213
|
}
|
|
210
214
|
});
|
|
@@ -399,18 +403,18 @@ var machine = createMachine({
|
|
|
399
403
|
},
|
|
400
404
|
revertInputValue({ context, computed, scope }) {
|
|
401
405
|
const inputEl = getInputElAtIndex(scope, context.get("focusedIndex"));
|
|
402
|
-
inputEl
|
|
406
|
+
setInputValue(inputEl, computed("focusedValue"));
|
|
403
407
|
},
|
|
404
408
|
syncInputValue({ context, event, scope }) {
|
|
405
409
|
const value = context.get("value");
|
|
406
410
|
const inputEl = getInputElAtIndex(scope, event.index);
|
|
407
|
-
inputEl
|
|
411
|
+
setInputValue(inputEl, value[event.index]);
|
|
408
412
|
},
|
|
409
413
|
syncInputElements({ context, scope }) {
|
|
410
414
|
const inputEls = getInputEls(scope);
|
|
411
415
|
const value = context.get("value");
|
|
412
416
|
inputEls.forEach((inputEl, index) => {
|
|
413
|
-
inputEl
|
|
417
|
+
setInputValue(inputEl, value[index]);
|
|
414
418
|
});
|
|
415
419
|
},
|
|
416
420
|
setPastedValue({ context, event, computed, flush }) {
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createAnatomy } from '@zag-js/anatomy';
|
|
2
|
-
import { dispatchInputValueEvent, raf, queryAll, dataAttr, visuallyHiddenStyle, ariaAttr, getBeforeInputValue, getNativeEvent, isComposingEvent, isModifierKey, getEventKey } from '@zag-js/dom-query';
|
|
2
|
+
import { dispatchInputValueEvent, raf, queryAll, dataAttr, visuallyHiddenStyle, ariaAttr, getBeforeInputValue, getNativeEvent, isComposingEvent, isModifierKey, getEventKey, isHTMLElement } from '@zag-js/dom-query';
|
|
3
3
|
import { setValueAtIndex, createSplitProps, invariant } from '@zag-js/utils';
|
|
4
4
|
import { setup } from '@zag-js/core';
|
|
5
5
|
import { createProps } from '@zag-js/types';
|
|
@@ -21,6 +21,10 @@ var getInputEls = (ctx) => {
|
|
|
21
21
|
var getInputElAtIndex = (ctx, index) => getInputEls(ctx)[index];
|
|
22
22
|
var getFirstInputEl = (ctx) => getInputEls(ctx)[0];
|
|
23
23
|
var getHiddenInputEl = (ctx) => ctx.getById(getHiddenInputId(ctx));
|
|
24
|
+
var setInputValue = (inputEl, value) => {
|
|
25
|
+
inputEl.value = value;
|
|
26
|
+
inputEl.setAttribute("value", value);
|
|
27
|
+
};
|
|
24
28
|
|
|
25
29
|
// src/pin-input.utils.ts
|
|
26
30
|
var REGEX = {
|
|
@@ -198,11 +202,11 @@ function connect(service, normalize) {
|
|
|
198
202
|
}
|
|
199
203
|
},
|
|
200
204
|
onFocus() {
|
|
201
|
-
|
|
202
|
-
send({ type: "INPUT.FOCUS", index });
|
|
203
|
-
});
|
|
205
|
+
send({ type: "INPUT.FOCUS", index });
|
|
204
206
|
},
|
|
205
|
-
onBlur() {
|
|
207
|
+
onBlur(event) {
|
|
208
|
+
const target = event.relatedTarget;
|
|
209
|
+
if (isHTMLElement(target) && target.dataset.ownedby === getRootId(scope)) return;
|
|
206
210
|
send({ type: "INPUT.BLUR", index });
|
|
207
211
|
}
|
|
208
212
|
});
|
|
@@ -397,18 +401,18 @@ var machine = createMachine({
|
|
|
397
401
|
},
|
|
398
402
|
revertInputValue({ context, computed, scope }) {
|
|
399
403
|
const inputEl = getInputElAtIndex(scope, context.get("focusedIndex"));
|
|
400
|
-
inputEl
|
|
404
|
+
setInputValue(inputEl, computed("focusedValue"));
|
|
401
405
|
},
|
|
402
406
|
syncInputValue({ context, event, scope }) {
|
|
403
407
|
const value = context.get("value");
|
|
404
408
|
const inputEl = getInputElAtIndex(scope, event.index);
|
|
405
|
-
inputEl
|
|
409
|
+
setInputValue(inputEl, value[event.index]);
|
|
406
410
|
},
|
|
407
411
|
syncInputElements({ context, scope }) {
|
|
408
412
|
const inputEls = getInputEls(scope);
|
|
409
413
|
const value = context.get("value");
|
|
410
414
|
inputEls.forEach((inputEl, index) => {
|
|
411
|
-
inputEl
|
|
415
|
+
setInputValue(inputEl, value[index]);
|
|
412
416
|
});
|
|
413
417
|
},
|
|
414
418
|
setPastedValue({ context, event, computed, flush }) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/pin-input",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
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.2.
|
|
30
|
-
"@zag-js/dom-query": "1.2.
|
|
31
|
-
"@zag-js/utils": "1.2.
|
|
32
|
-
"@zag-js/core": "1.2.
|
|
33
|
-
"@zag-js/types": "1.2.
|
|
29
|
+
"@zag-js/anatomy": "1.2.1",
|
|
30
|
+
"@zag-js/dom-query": "1.2.1",
|
|
31
|
+
"@zag-js/utils": "1.2.1",
|
|
32
|
+
"@zag-js/core": "1.2.1",
|
|
33
|
+
"@zag-js/types": "1.2.1"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"clean-package": "2.2.0"
|