@zag-js/combobox
Advanced tools
Comparing version 0.70.0 to 0.71.0
@@ -1,33 +0,15 @@ | ||
"use strict"; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
'use strict'; | ||
// src/index.ts | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
anatomy: () => anatomy, | ||
collection: () => collection, | ||
connect: () => connect, | ||
machine: () => machine | ||
}); | ||
module.exports = __toCommonJS(src_exports); | ||
var anatomy$1 = require('@zag-js/anatomy'); | ||
var collection$1 = require('@zag-js/collection'); | ||
var core = require('@zag-js/core'); | ||
var domEvent = require('@zag-js/dom-event'); | ||
var domQuery = require('@zag-js/dom-query'); | ||
var popper = require('@zag-js/popper'); | ||
var ariaHidden = require('@zag-js/aria-hidden'); | ||
var dismissable = require('@zag-js/dismissable'); | ||
var utils = require('@zag-js/utils'); | ||
// src/combobox.anatomy.ts | ||
var import_anatomy = require("@zag-js/anatomy"); | ||
var anatomy = (0, import_anatomy.createAnatomy)("combobox").parts( | ||
var anatomy = anatomy$1.createAnatomy("combobox").parts( | ||
"root", | ||
@@ -49,21 +31,9 @@ "clearTrigger", | ||
var parts = anatomy.build(); | ||
// src/combobox.collection.ts | ||
var import_collection = require("@zag-js/collection"); | ||
var import_core = require("@zag-js/core"); | ||
var collection = (options) => { | ||
return (0, import_core.ref)(new import_collection.ListCollection(options)); | ||
return core.ref(new collection$1.ListCollection(options)); | ||
}; | ||
collection.empty = () => { | ||
return (0, import_core.ref)(new import_collection.ListCollection({ items: [] })); | ||
return core.ref(new collection$1.ListCollection({ items: [] })); | ||
}; | ||
// src/combobox.connect.ts | ||
var import_dom_event = require("@zag-js/dom-event"); | ||
var import_dom_query2 = require("@zag-js/dom-query"); | ||
var import_popper = require("@zag-js/popper"); | ||
// src/combobox.dom.ts | ||
var import_dom_query = require("@zag-js/dom-query"); | ||
var dom = (0, import_dom_query.createScope)({ | ||
var dom = domQuery.createScope({ | ||
getRootId: (ctx) => ctx.ids?.root ?? `combobox:${ctx.id}`, | ||
@@ -90,3 +60,3 @@ getLabelId: (ctx) => ctx.ids?.label ?? `combobox:${ctx.id}:label`, | ||
const selector = `[role=option][data-value="${CSS.escape(value)}"`; | ||
return (0, import_dom_query.query)(dom.getContentEl(ctx), selector); | ||
return domQuery.query(dom.getContentEl(ctx), selector); | ||
}, | ||
@@ -117,3 +87,3 @@ focusInputEl: (ctx) => { | ||
const highlightedValue = state.context.highlightedValue; | ||
const popperStyles = (0, import_popper.getPlacementStyles)({ | ||
const popperStyles = popper.getPlacementStyles({ | ||
...state.context.positioning, | ||
@@ -181,4 +151,4 @@ placement: state.context.currentPlacement | ||
id: dom.getRootId(state.context), | ||
"data-invalid": (0, import_dom_query2.dataAttr)(invalid), | ||
"data-readonly": (0, import_dom_query2.dataAttr)(readOnly) | ||
"data-invalid": domQuery.dataAttr(invalid), | ||
"data-readonly": domQuery.dataAttr(readOnly) | ||
}); | ||
@@ -192,6 +162,6 @@ }, | ||
id: dom.getLabelId(state.context), | ||
"data-readonly": (0, import_dom_query2.dataAttr)(readOnly), | ||
"data-disabled": (0, import_dom_query2.dataAttr)(disabled), | ||
"data-invalid": (0, import_dom_query2.dataAttr)(invalid), | ||
"data-focus": (0, import_dom_query2.dataAttr)(focused), | ||
"data-readonly": domQuery.dataAttr(readOnly), | ||
"data-disabled": domQuery.dataAttr(disabled), | ||
"data-invalid": domQuery.dataAttr(invalid), | ||
"data-focus": domQuery.dataAttr(focused), | ||
onClick(event) { | ||
@@ -210,5 +180,5 @@ if (composite) return; | ||
"data-state": open ? "open" : "closed", | ||
"data-focus": (0, import_dom_query2.dataAttr)(focused), | ||
"data-disabled": (0, import_dom_query2.dataAttr)(disabled), | ||
"data-invalid": (0, import_dom_query2.dataAttr)(invalid) | ||
"data-focus": domQuery.dataAttr(focused), | ||
"data-disabled": domQuery.dataAttr(disabled), | ||
"data-invalid": domQuery.dataAttr(invalid) | ||
}); | ||
@@ -228,4 +198,4 @@ }, | ||
dir: state.context.dir, | ||
"aria-invalid": (0, import_dom_query2.ariaAttr)(invalid), | ||
"data-invalid": (0, import_dom_query2.dataAttr)(invalid), | ||
"aria-invalid": domQuery.ariaAttr(invalid), | ||
"data-invalid": domQuery.dataAttr(invalid), | ||
name: state.context.name, | ||
@@ -271,3 +241,3 @@ form: state.context.form, | ||
if (!interactive) return; | ||
if (event.ctrlKey || event.shiftKey || (0, import_dom_query2.isComposingEvent)(event)) return; | ||
if (event.ctrlKey || event.shiftKey || domQuery.isComposingEvent(event)) return; | ||
const openOnKeyPress = state.context.openOnKeyPress; | ||
@@ -307,3 +277,3 @@ const isModifierKey = event.ctrlKey || event.metaKey || event.shiftKey; | ||
const itemEl = dom.getHighlightedItemEl(state.context); | ||
(0, import_dom_event.clickIfLink)(itemEl); | ||
domEvent.clickIfLink(itemEl); | ||
}, | ||
@@ -315,3 +285,3 @@ Escape() { | ||
}; | ||
const key = (0, import_dom_event.getEventKey)(event, state.context); | ||
const key = domEvent.getEventKey(event, state.context); | ||
const exec = keymap[key]; | ||
@@ -335,6 +305,6 @@ exec?.(event); | ||
disabled, | ||
"data-invalid": (0, import_dom_query2.dataAttr)(invalid), | ||
"data-focusable": (0, import_dom_query2.dataAttr)(props.focusable), | ||
"data-readonly": (0, import_dom_query2.dataAttr)(readOnly), | ||
"data-disabled": (0, import_dom_query2.dataAttr)(disabled), | ||
"data-invalid": domQuery.dataAttr(invalid), | ||
"data-focusable": domQuery.dataAttr(props.focusable), | ||
"data-readonly": domQuery.dataAttr(readOnly), | ||
"data-disabled": domQuery.dataAttr(disabled), | ||
onFocus() { | ||
@@ -347,3 +317,3 @@ if (!props.focusable) return; | ||
if (!interactive) return; | ||
if (!(0, import_dom_event.isLeftClick)(event)) return; | ||
if (!domEvent.isLeftClick(event)) return; | ||
send("TRIGGER.CLICK"); | ||
@@ -370,3 +340,3 @@ }, | ||
}; | ||
const key = (0, import_dom_event.getEventKey)(event, state.context); | ||
const key = domEvent.getEventKey(event, state.context); | ||
const exec = keyMap[key]; | ||
@@ -413,3 +383,3 @@ if (exec) { | ||
disabled, | ||
"data-invalid": (0, import_dom_query2.dataAttr)(invalid), | ||
"data-invalid": domQuery.dataAttr(invalid), | ||
"aria-label": translations.clearTriggerLabel, | ||
@@ -438,7 +408,7 @@ "aria-controls": dom.getInputId(state.context), | ||
tabIndex: -1, | ||
"data-highlighted": (0, import_dom_query2.dataAttr)(itemState.highlighted), | ||
"data-highlighted": domQuery.dataAttr(itemState.highlighted), | ||
"data-state": itemState.selected ? "checked" : "unchecked", | ||
"aria-selected": (0, import_dom_query2.ariaAttr)(itemState.highlighted), | ||
"aria-disabled": (0, import_dom_query2.ariaAttr)(itemState.disabled), | ||
"data-disabled": (0, import_dom_query2.dataAttr)(itemState.disabled), | ||
"aria-selected": domQuery.ariaAttr(itemState.highlighted), | ||
"aria-disabled": domQuery.ariaAttr(itemState.disabled), | ||
"data-disabled": domQuery.dataAttr(itemState.disabled), | ||
"data-value": itemState.value, | ||
@@ -458,5 +428,5 @@ onPointerMove() { | ||
onClick(event) { | ||
if ((0, import_dom_query2.isDownloadingEvent)(event)) return; | ||
if ((0, import_dom_query2.isOpeningInNewTab)(event)) return; | ||
if ((0, import_dom_event.isContextMenuEvent)(event)) return; | ||
if (domQuery.isDownloadingEvent(event)) return; | ||
if (domQuery.isOpeningInNewTab(event)) return; | ||
if (domEvent.isContextMenuEvent(event)) return; | ||
if (itemState.disabled) return; | ||
@@ -473,4 +443,4 @@ send({ type: "ITEM.CLICK", src: "click", value }); | ||
"data-state": itemState.selected ? "checked" : "unchecked", | ||
"data-disabled": (0, import_dom_query2.dataAttr)(itemState.disabled), | ||
"data-highlighted": (0, import_dom_query2.dataAttr)(itemState.highlighted) | ||
"data-disabled": domQuery.dataAttr(itemState.disabled), | ||
"data-highlighted": domQuery.dataAttr(itemState.highlighted) | ||
}); | ||
@@ -508,14 +478,6 @@ }, | ||
} | ||
// src/combobox.machine.ts | ||
var import_aria_hidden = require("@zag-js/aria-hidden"); | ||
var import_core2 = require("@zag-js/core"); | ||
var import_dismissable = require("@zag-js/dismissable"); | ||
var import_dom_query3 = require("@zag-js/dom-query"); | ||
var import_popper2 = require("@zag-js/popper"); | ||
var import_utils = require("@zag-js/utils"); | ||
var { and, not } = import_core2.guards; | ||
var { and, not } = core.guards; | ||
function machine(userContext) { | ||
const ctx = (0, import_utils.compact)(userContext); | ||
return (0, import_core2.createMachine)( | ||
const ctx = utils.compact(userContext); | ||
return core.createMachine( | ||
{ | ||
@@ -1073,3 +1035,3 @@ id: "combobox", | ||
openOnChange: (ctx2, evt) => { | ||
if ((0, import_utils.isBoolean)(ctx2.openOnChange)) return ctx2.openOnChange; | ||
if (utils.isBoolean(ctx2.openOnChange)) return ctx2.openOnChange; | ||
return !!ctx2.openOnChange?.({ inputValue: evt.value }); | ||
@@ -1084,3 +1046,3 @@ }, | ||
const contentEl = () => dom.getContentEl(ctx2); | ||
return (0, import_dismissable.trackDismissableElement)(contentEl, { | ||
return dismissable.trackDismissableElement(contentEl, { | ||
defer: true, | ||
@@ -1102,3 +1064,3 @@ exclude: () => [dom.getInputEl(ctx2), dom.getTriggerEl(ctx2), dom.getClearTriggerEl(ctx2)], | ||
hideOtherElements(ctx2) { | ||
return (0, import_aria_hidden.ariaHidden)([dom.getInputEl(ctx2), dom.getContentEl(ctx2), dom.getTriggerEl(ctx2)]); | ||
return ariaHidden.ariaHidden([dom.getInputEl(ctx2), dom.getContentEl(ctx2), dom.getTriggerEl(ctx2)]); | ||
}, | ||
@@ -1109,3 +1071,3 @@ computePlacement(ctx2) { | ||
ctx2.currentPlacement = ctx2.positioning.placement; | ||
return (0, import_popper2.getPlacement)(controlEl, positionerEl, { | ||
return popper.getPlacement(controlEl, positionerEl, { | ||
...ctx2.positioning, | ||
@@ -1123,3 +1085,3 @@ defer: true, | ||
const contentEl = () => dom.getContentEl(ctx2); | ||
return (0, import_dom_query3.observeChildren)(contentEl, { | ||
return domQuery.observeChildren(contentEl, { | ||
callback: exec, | ||
@@ -1143,10 +1105,10 @@ defer: true | ||
} | ||
const rafCleanup2 = (0, import_dom_query3.raf)(() => { | ||
(0, import_dom_query3.scrollIntoView)(itemEl, { rootEl: contentEl, block: "nearest" }); | ||
const rafCleanup2 = domQuery.raf(() => { | ||
domQuery.scrollIntoView(itemEl, { rootEl: contentEl, block: "nearest" }); | ||
}); | ||
cleanups.push(rafCleanup2); | ||
}; | ||
const rafCleanup = (0, import_dom_query3.raf)(() => exec(true)); | ||
const rafCleanup = domQuery.raf(() => exec(true)); | ||
cleanups.push(rafCleanup); | ||
const observerCleanup = (0, import_dom_query3.observeAttributes)(inputEl, { | ||
const observerCleanup = domQuery.observeAttributes(inputEl, { | ||
attributes: ["aria-activedescendant"], | ||
@@ -1165,3 +1127,3 @@ callback: () => exec(false) | ||
const positionerEl = () => dom.getPositionerEl(ctx2); | ||
(0, import_popper2.getPlacement)(controlEl, positionerEl, { | ||
popper.getPlacement(controlEl, positionerEl, { | ||
...ctx2.positioning, | ||
@@ -1196,3 +1158,3 @@ ...evt.options, | ||
setInitialFocus(ctx2) { | ||
(0, import_dom_query3.raf)(() => { | ||
domQuery.raf(() => { | ||
dom.focusInputEl(ctx2); | ||
@@ -1202,3 +1164,3 @@ }); | ||
setFinalFocus(ctx2) { | ||
(0, import_dom_query3.raf)(() => { | ||
domQuery.raf(() => { | ||
const triggerEl = dom.getTriggerEl(ctx2); | ||
@@ -1230,3 +1192,3 @@ if (triggerEl?.dataset.focusable == null) { | ||
revertInputValue(ctx2) { | ||
const inputValue = (0, import_utils.match)(ctx2.selectionBehavior, { | ||
const inputValue = utils.match(ctx2.selectionBehavior, { | ||
replace: ctx2.hasSelectedItems ? ctx2.valueAsString : "", | ||
@@ -1245,3 +1207,3 @@ preserve: ctx2.inputValue, | ||
if (ctx2.inputValue.trim() || ctx2.multiple) return; | ||
ctx2.inputValue = (0, import_utils.match)(ctx2.selectionBehavior, { | ||
ctx2.inputValue = utils.match(ctx2.selectionBehavior, { | ||
preserve: ctx2.inputValue || valueAsString, | ||
@@ -1258,3 +1220,3 @@ replace: valueAsString, | ||
setSelectedItems(ctx2, evt) { | ||
if (!(0, import_utils.isArray)(evt.value)) return; | ||
if (!utils.isArray(evt.value)) return; | ||
set.value(ctx2, evt.value); | ||
@@ -1281,3 +1243,3 @@ }, | ||
highlightFirstItem(ctx2) { | ||
(0, import_dom_query3.raf)(() => { | ||
domQuery.raf(() => { | ||
const value = ctx2.collection.firstValue; | ||
@@ -1289,3 +1251,3 @@ set.highlightedValue(ctx2, value, true); | ||
if (!ctx2.autoHighlight) return; | ||
(0, import_dom_query3.raf)(() => { | ||
domQuery.raf(() => { | ||
const value = ctx2.collection.firstValue; | ||
@@ -1296,3 +1258,3 @@ set.highlightedValue(ctx2, value); | ||
highlightLastItem(ctx2) { | ||
(0, import_dom_query3.raf)(() => { | ||
domQuery.raf(() => { | ||
const value = ctx2.collection.lastValue; | ||
@@ -1323,3 +1285,3 @@ set.highlightedValue(ctx2, value); | ||
highlightFirstSelectedItem(ctx2) { | ||
(0, import_dom_query3.raf)(() => { | ||
domQuery.raf(() => { | ||
const [value] = ctx2.collection.sort(ctx2.value); | ||
@@ -1330,3 +1292,3 @@ set.highlightedValue(ctx2, value); | ||
highlightFirstOrSelectedItem(ctx2) { | ||
(0, import_dom_query3.raf)(() => { | ||
domQuery.raf(() => { | ||
let value = null; | ||
@@ -1342,3 +1304,3 @@ if (ctx2.hasSelectedItems) { | ||
highlightLastOrSelectedItem(ctx2) { | ||
(0, import_dom_query3.raf)(() => { | ||
domQuery.raf(() => { | ||
let value = null; | ||
@@ -1357,3 +1319,3 @@ if (ctx2.hasSelectedItems) { | ||
const valueText = ctx2.collection.stringify(ctx2.highlightedValue); | ||
(0, import_dom_query3.raf)(() => { | ||
domQuery.raf(() => { | ||
inputEl.value = valueText || ctx2.inputValue; | ||
@@ -1396,3 +1358,3 @@ }); | ||
} else { | ||
inputValue = (0, import_utils.match)(ctx.selectionBehavior, { | ||
inputValue = utils.match(ctx.selectionBehavior, { | ||
replace: ctx.valueAsString, | ||
@@ -1430,3 +1392,3 @@ preserve: ctx.inputValue, | ||
value: (ctx, value, force = false) => { | ||
if ((0, import_utils.isEqual)(ctx.value, value)) return; | ||
if (utils.isEqual(ctx.value, value)) return; | ||
if (value == null && !force) return; | ||
@@ -1438,6 +1400,6 @@ if (value == null && force) { | ||
} | ||
if ((0, import_utils.isArray)(value)) { | ||
if (utils.isArray(value)) { | ||
ctx.value = value; | ||
} else if (value != null) { | ||
ctx.value = ctx.multiple ? (0, import_utils.addOrRemove)(ctx.value, value) : [value]; | ||
ctx.value = ctx.multiple ? utils.addOrRemove(ctx.value, value) : [value]; | ||
} | ||
@@ -1447,3 +1409,3 @@ invoke.valueChange(ctx); | ||
highlightedValue: (ctx, value, force = false) => { | ||
if ((0, import_utils.isEqual)(ctx.highlightedValue, value)) return; | ||
if (utils.isEqual(ctx.highlightedValue, value)) return; | ||
if (!value && !force) return; | ||
@@ -1454,3 +1416,3 @@ ctx.highlightedValue = value || null; | ||
inputValue: (ctx, value) => { | ||
if ((0, import_utils.isEqual)(ctx.inputValue, value)) return; | ||
if (utils.isEqual(ctx.inputValue, value)) return; | ||
ctx.inputValue = value; | ||
@@ -1460,9 +1422,6 @@ invoke.inputChange(ctx); | ||
}; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
anatomy, | ||
collection, | ||
connect, | ||
machine | ||
}); | ||
//# sourceMappingURL=index.js.map | ||
exports.anatomy = anatomy; | ||
exports.collection = collection; | ||
exports.connect = connect; | ||
exports.machine = machine; |
{ | ||
"name": "@zag-js/combobox", | ||
"version": "0.70.0", | ||
"version": "0.71.0", | ||
"description": "Core logic for the combobox widget implemented as a state machine", | ||
@@ -20,4 +20,3 @@ "keywords": [ | ||
"files": [ | ||
"dist", | ||
"src" | ||
"dist" | ||
], | ||
@@ -31,12 +30,12 @@ "publishConfig": { | ||
"dependencies": { | ||
"@zag-js/anatomy": "0.70.0", | ||
"@zag-js/aria-hidden": "0.70.0", | ||
"@zag-js/collection": "0.70.0", | ||
"@zag-js/core": "0.70.0", | ||
"@zag-js/dismissable": "0.70.0", | ||
"@zag-js/dom-query": "0.70.0", | ||
"@zag-js/dom-event": "0.70.0", | ||
"@zag-js/utils": "0.70.0", | ||
"@zag-js/popper": "0.70.0", | ||
"@zag-js/types": "0.70.0" | ||
"@zag-js/anatomy": "0.71.0", | ||
"@zag-js/aria-hidden": "0.71.0", | ||
"@zag-js/collection": "0.71.0", | ||
"@zag-js/core": "0.71.0", | ||
"@zag-js/dismissable": "0.71.0", | ||
"@zag-js/dom-query": "0.71.0", | ||
"@zag-js/dom-event": "0.71.0", | ||
"@zag-js/utils": "0.71.0", | ||
"@zag-js/popper": "0.71.0", | ||
"@zag-js/types": "0.71.0" | ||
}, | ||
@@ -43,0 +42,0 @@ "devDependencies": { |
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
121646
7
3161
+ Added@zag-js/anatomy@0.71.0(transitive)
+ Added@zag-js/aria-hidden@0.71.0(transitive)
+ Added@zag-js/collection@0.71.0(transitive)
+ Added@zag-js/core@0.71.0(transitive)
+ Added@zag-js/dismissable@0.71.0(transitive)
+ Added@zag-js/dom-event@0.71.0(transitive)
+ Added@zag-js/dom-query@0.71.0(transitive)
+ Added@zag-js/interact-outside@0.71.0(transitive)
+ Added@zag-js/popper@0.71.0(transitive)
+ Added@zag-js/store@0.71.0(transitive)
+ Added@zag-js/text-selection@0.71.0(transitive)
+ Added@zag-js/types@0.71.0(transitive)
+ Added@zag-js/utils@0.71.0(transitive)
- Removed@zag-js/anatomy@0.70.0(transitive)
- Removed@zag-js/aria-hidden@0.70.0(transitive)
- Removed@zag-js/collection@0.70.0(transitive)
- Removed@zag-js/core@0.70.0(transitive)
- Removed@zag-js/dismissable@0.70.0(transitive)
- Removed@zag-js/dom-event@0.70.0(transitive)
- Removed@zag-js/dom-query@0.70.0(transitive)
- Removed@zag-js/interact-outside@0.70.0(transitive)
- Removed@zag-js/popper@0.70.0(transitive)
- Removed@zag-js/store@0.70.0(transitive)
- Removed@zag-js/text-selection@0.70.0(transitive)
- Removed@zag-js/types@0.70.0(transitive)
- Removed@zag-js/utils@0.70.0(transitive)
Updated@zag-js/anatomy@0.71.0
Updated@zag-js/aria-hidden@0.71.0
Updated@zag-js/collection@0.71.0
Updated@zag-js/core@0.71.0
Updated@zag-js/dismissable@0.71.0
Updated@zag-js/dom-event@0.71.0
Updated@zag-js/dom-query@0.71.0
Updated@zag-js/popper@0.71.0
Updated@zag-js/types@0.71.0
Updated@zag-js/utils@0.71.0