@zag-js/tags-input
Advanced tools
Comparing version 0.61.0 to 0.61.1
@@ -209,9 +209,12 @@ "use strict"; | ||
const evt = (0, import_dom_event.getNativeEvent)(event); | ||
if (evt.inputType === "insertFromPaste") return; | ||
let value = event.target.value; | ||
const value = event.target.value; | ||
if (evt.inputType === "insertFromPaste") { | ||
send({ type: "PASTE", value }); | ||
return; | ||
} | ||
if (endsWith(value, state.context.delimiter)) { | ||
send("DELIMITER_KEY"); | ||
} else { | ||
send({ type: "TYPE", value, key: evt.inputType }); | ||
return; | ||
} | ||
send({ type: "TYPE", value, key: evt.inputType }); | ||
}, | ||
@@ -221,7 +224,2 @@ onFocus() { | ||
}, | ||
onPaste(event) { | ||
event.preventDefault(); | ||
const value = event.clipboardData.getData("text/plain"); | ||
send({ type: "PASTE", value }); | ||
}, | ||
onKeyDown(event) { | ||
@@ -617,3 +615,14 @@ if (event.defaultPrevented) return; | ||
actions: ["deleteHighlightedTag", "highlightTagAtIndex"] | ||
} | ||
}, | ||
PASTE: [ | ||
{ | ||
guard: "addOnPaste", | ||
target: "focused:input", | ||
actions: ["setInputValue", "addTagFromPaste"] | ||
}, | ||
{ | ||
target: "focused:input", | ||
actions: "setInputValue" | ||
} | ||
] | ||
} | ||
@@ -857,3 +866,4 @@ }, | ||
if (guard) { | ||
set.value(ctx2, ctx2.value.concat(value)); | ||
const nextValue = (0, import_utils.uniq)(ctx2.value.concat(value)); | ||
set.value(ctx2, nextValue); | ||
ctx2.log.prev = ctx2.log.current; | ||
@@ -871,3 +881,4 @@ ctx2.log.current = { type: "add", value }; | ||
const trimmedValue = ctx2.delimiter ? value.split(ctx2.delimiter).map((v) => v.trim()) : [value]; | ||
set.value(ctx2, ctx2.value.concat(...trimmedValue)); | ||
const nextValue = (0, import_utils.uniq)(ctx2.value.concat(...trimmedValue)); | ||
set.value(ctx2, nextValue); | ||
ctx2.log.prev = ctx2.log.current; | ||
@@ -874,0 +885,0 @@ ctx2.log.current = { type: "paste", values: trimmedValue }; |
{ | ||
"name": "@zag-js/tags-input", | ||
"version": "0.61.0", | ||
"version": "0.61.1", | ||
"description": "Core logic for the tags-input widget implemented as a state machine", | ||
@@ -30,12 +30,12 @@ "keywords": [ | ||
"dependencies": { | ||
"@zag-js/anatomy": "0.61.0", | ||
"@zag-js/auto-resize": "0.61.0", | ||
"@zag-js/core": "0.61.0", | ||
"@zag-js/interact-outside": "0.61.0", | ||
"@zag-js/live-region": "0.61.0", | ||
"@zag-js/dom-query": "0.61.0", | ||
"@zag-js/dom-event": "0.61.0", | ||
"@zag-js/form-utils": "0.61.0", | ||
"@zag-js/utils": "0.61.0", | ||
"@zag-js/types": "0.61.0" | ||
"@zag-js/anatomy": "0.61.1", | ||
"@zag-js/auto-resize": "0.61.1", | ||
"@zag-js/core": "0.61.1", | ||
"@zag-js/interact-outside": "0.61.1", | ||
"@zag-js/live-region": "0.61.1", | ||
"@zag-js/dom-query": "0.61.1", | ||
"@zag-js/dom-event": "0.61.1", | ||
"@zag-js/form-utils": "0.61.1", | ||
"@zag-js/utils": "0.61.1", | ||
"@zag-js/types": "0.61.1" | ||
}, | ||
@@ -42,0 +42,0 @@ "devDependencies": { |
@@ -122,11 +122,15 @@ import { getEventKey, getNativeEvent, type EventKeyMap } from "@zag-js/dom-event" | ||
const evt = getNativeEvent(event) | ||
const value = event.target.value | ||
if (evt.inputType === "insertFromPaste") return | ||
let value = event.target.value | ||
if (evt.inputType === "insertFromPaste") { | ||
send({ type: "PASTE", value }) | ||
return | ||
} | ||
if (endsWith(value, state.context.delimiter)) { | ||
send("DELIMITER_KEY") | ||
} else { | ||
send({ type: "TYPE", value, key: evt.inputType }) | ||
return | ||
} | ||
send({ type: "TYPE", value, key: evt.inputType }) | ||
}, | ||
@@ -136,7 +140,2 @@ onFocus() { | ||
}, | ||
onPaste(event) { | ||
event.preventDefault() | ||
const value = event.clipboardData.getData("text/plain") | ||
send({ type: "PASTE", value }) | ||
}, | ||
onKeyDown(event) { | ||
@@ -143,0 +142,0 @@ if (event.defaultPrevented) return |
@@ -7,3 +7,3 @@ import { autoResizeInput } from "@zag-js/auto-resize" | ||
import { createLiveRegion } from "@zag-js/live-region" | ||
import { compact, isEqual, removeAt, warn } from "@zag-js/utils" | ||
import { compact, isEqual, removeAt, uniq, warn } from "@zag-js/utils" | ||
import { dom } from "./tags-input.dom" | ||
@@ -215,2 +215,13 @@ import type { MachineContext, MachineState, UserDefinedContext } from "./tags-input.types" | ||
}, | ||
PASTE: [ | ||
{ | ||
guard: "addOnPaste", | ||
target: "focused:input", | ||
actions: ["setInputValue", "addTagFromPaste"], | ||
}, | ||
{ | ||
target: "focused:input", | ||
actions: "setInputValue", | ||
}, | ||
], | ||
}, | ||
@@ -469,3 +480,4 @@ }, | ||
if (guard) { | ||
set.value(ctx, ctx.value.concat(value)) | ||
const nextValue = uniq(ctx.value.concat(value)) | ||
set.value(ctx, nextValue) | ||
// log | ||
@@ -484,3 +496,4 @@ ctx.log.prev = ctx.log.current | ||
const trimmedValue = ctx.delimiter ? value.split(ctx.delimiter).map((v) => v.trim()) : [value] | ||
set.value(ctx, ctx.value.concat(...trimmedValue)) | ||
const nextValue = uniq(ctx.value.concat(...trimmedValue)) | ||
set.value(ctx, nextValue) | ||
// log | ||
@@ -487,0 +500,0 @@ ctx.log.prev = ctx.log.current |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
256371
3658
+ Added@zag-js/anatomy@0.61.1(transitive)
+ Added@zag-js/auto-resize@0.61.1(transitive)
+ Added@zag-js/core@0.61.1(transitive)
+ Added@zag-js/dom-event@0.61.1(transitive)
+ Added@zag-js/dom-query@0.61.1(transitive)
+ Added@zag-js/form-utils@0.61.1(transitive)
+ Added@zag-js/interact-outside@0.61.1(transitive)
+ Added@zag-js/live-region@0.61.1(transitive)
+ Added@zag-js/store@0.61.1(transitive)
+ Added@zag-js/text-selection@0.61.1(transitive)
+ Added@zag-js/types@0.61.1(transitive)
+ Added@zag-js/utils@0.61.1(transitive)
- Removed@zag-js/anatomy@0.61.0(transitive)
- Removed@zag-js/auto-resize@0.61.0(transitive)
- Removed@zag-js/core@0.61.0(transitive)
- Removed@zag-js/dom-event@0.61.0(transitive)
- Removed@zag-js/dom-query@0.61.0(transitive)
- Removed@zag-js/form-utils@0.61.0(transitive)
- Removed@zag-js/interact-outside@0.61.0(transitive)
- Removed@zag-js/live-region@0.61.0(transitive)
- Removed@zag-js/store@0.61.0(transitive)
- Removed@zag-js/text-selection@0.61.0(transitive)
- Removed@zag-js/types@0.61.0(transitive)
- Removed@zag-js/utils@0.61.0(transitive)
Updated@zag-js/anatomy@0.61.1
Updated@zag-js/auto-resize@0.61.1
Updated@zag-js/core@0.61.1
Updated@zag-js/dom-event@0.61.1
Updated@zag-js/dom-query@0.61.1
Updated@zag-js/form-utils@0.61.1
Updated@zag-js/live-region@0.61.1
Updated@zag-js/types@0.61.1
Updated@zag-js/utils@0.61.1