@zag-js/combobox 1.34.0 → 1.35.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/combobox.anatomy.d.mts +6 -0
- package/dist/combobox.anatomy.d.ts +6 -0
- package/dist/combobox.anatomy.js +49 -0
- package/dist/combobox.anatomy.mjs +23 -0
- package/dist/combobox.collection.d.mts +8 -0
- package/dist/combobox.collection.d.ts +8 -0
- package/dist/combobox.collection.js +36 -0
- package/dist/combobox.collection.mjs +11 -0
- package/dist/combobox.connect.d.mts +10 -0
- package/dist/combobox.connect.d.ts +10 -0
- package/dist/combobox.connect.js +454 -0
- package/dist/combobox.connect.mjs +429 -0
- package/dist/combobox.dom.d.mts +24 -0
- package/dist/combobox.dom.d.ts +24 -0
- package/dist/combobox.dom.js +102 -0
- package/dist/combobox.dom.mjs +58 -0
- package/dist/combobox.machine.d.mts +10 -0
- package/dist/combobox.machine.d.ts +10 -0
- package/dist/combobox.machine.js +1085 -0
- package/dist/combobox.machine.mjs +1050 -0
- package/dist/combobox.props.d.mts +17 -0
- package/dist/combobox.props.d.ts +17 -0
- package/dist/combobox.props.js +100 -0
- package/dist/combobox.props.mjs +68 -0
- package/dist/combobox.types.d.mts +432 -0
- package/dist/combobox.types.d.ts +432 -0
- package/dist/combobox.types.js +18 -0
- package/dist/combobox.types.mjs +0 -0
- package/dist/index.d.mts +9 -452
- package/dist/index.d.ts +9 -452
- package/dist/index.js +37 -1585
- package/dist/index.mjs +11 -1576
- package/package.json +22 -12
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
// src/combobox.connect.ts
|
|
2
|
+
import {
|
|
3
|
+
ariaAttr,
|
|
4
|
+
dataAttr,
|
|
5
|
+
getEventKey,
|
|
6
|
+
isAnchorElement,
|
|
7
|
+
isComposingEvent,
|
|
8
|
+
isContextMenuEvent,
|
|
9
|
+
isDownloadingEvent,
|
|
10
|
+
isLeftClick,
|
|
11
|
+
isOpeningInNewTab
|
|
12
|
+
} from "@zag-js/dom-query";
|
|
13
|
+
import { getPlacementStyles } from "@zag-js/popper";
|
|
14
|
+
import { ensure } from "@zag-js/utils";
|
|
15
|
+
import { parts } from "./combobox.anatomy.mjs";
|
|
16
|
+
import * as dom from "./combobox.dom.mjs";
|
|
17
|
+
function connect(service, normalize) {
|
|
18
|
+
const { context, prop, state, send, scope, computed, event } = service;
|
|
19
|
+
const translations = prop("translations");
|
|
20
|
+
const collection = prop("collection");
|
|
21
|
+
const disabled = !!prop("disabled");
|
|
22
|
+
const interactive = computed("isInteractive");
|
|
23
|
+
const invalid = !!prop("invalid");
|
|
24
|
+
const required = !!prop("required");
|
|
25
|
+
const readOnly = !!prop("readOnly");
|
|
26
|
+
const open = state.hasTag("open");
|
|
27
|
+
const focused = state.hasTag("focused");
|
|
28
|
+
const composite = prop("composite");
|
|
29
|
+
const highlightedValue = context.get("highlightedValue");
|
|
30
|
+
const popperStyles = getPlacementStyles({
|
|
31
|
+
...prop("positioning"),
|
|
32
|
+
placement: context.get("currentPlacement")
|
|
33
|
+
});
|
|
34
|
+
function getItemState(props) {
|
|
35
|
+
const itemDisabled = collection.getItemDisabled(props.item);
|
|
36
|
+
const value = collection.getItemValue(props.item);
|
|
37
|
+
ensure(value, () => `[zag-js] No value found for item ${JSON.stringify(props.item)}`);
|
|
38
|
+
return {
|
|
39
|
+
value,
|
|
40
|
+
disabled: Boolean(disabled || itemDisabled),
|
|
41
|
+
highlighted: highlightedValue === value,
|
|
42
|
+
selected: context.get("value").includes(value)
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
focused,
|
|
47
|
+
open,
|
|
48
|
+
inputValue: context.get("inputValue"),
|
|
49
|
+
highlightedValue,
|
|
50
|
+
highlightedItem: context.get("highlightedItem"),
|
|
51
|
+
value: context.get("value"),
|
|
52
|
+
valueAsString: computed("valueAsString"),
|
|
53
|
+
hasSelectedItems: computed("hasSelectedItems"),
|
|
54
|
+
selectedItems: context.get("selectedItems"),
|
|
55
|
+
collection: prop("collection"),
|
|
56
|
+
multiple: !!prop("multiple"),
|
|
57
|
+
disabled: !!disabled,
|
|
58
|
+
syncSelectedItems() {
|
|
59
|
+
send({ type: "SELECTED_ITEMS.SYNC" });
|
|
60
|
+
},
|
|
61
|
+
reposition(options = {}) {
|
|
62
|
+
send({ type: "POSITIONING.SET", options });
|
|
63
|
+
},
|
|
64
|
+
setHighlightValue(value) {
|
|
65
|
+
send({ type: "HIGHLIGHTED_VALUE.SET", value });
|
|
66
|
+
},
|
|
67
|
+
clearHighlightValue() {
|
|
68
|
+
send({ type: "HIGHLIGHTED_VALUE.CLEAR" });
|
|
69
|
+
},
|
|
70
|
+
selectValue(value) {
|
|
71
|
+
send({ type: "ITEM.SELECT", value });
|
|
72
|
+
},
|
|
73
|
+
setValue(value) {
|
|
74
|
+
send({ type: "VALUE.SET", value });
|
|
75
|
+
},
|
|
76
|
+
setInputValue(value, reason = "script") {
|
|
77
|
+
send({ type: "INPUT_VALUE.SET", value, src: reason });
|
|
78
|
+
},
|
|
79
|
+
clearValue(value) {
|
|
80
|
+
if (value != null) {
|
|
81
|
+
send({ type: "ITEM.CLEAR", value });
|
|
82
|
+
} else {
|
|
83
|
+
send({ type: "VALUE.CLEAR" });
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
focus() {
|
|
87
|
+
dom.getInputEl(scope)?.focus();
|
|
88
|
+
},
|
|
89
|
+
setOpen(nextOpen, reason = "script") {
|
|
90
|
+
const open2 = state.hasTag("open");
|
|
91
|
+
if (open2 === nextOpen) return;
|
|
92
|
+
send({ type: nextOpen ? "OPEN" : "CLOSE", src: reason });
|
|
93
|
+
},
|
|
94
|
+
getRootProps() {
|
|
95
|
+
return normalize.element({
|
|
96
|
+
...parts.root.attrs,
|
|
97
|
+
dir: prop("dir"),
|
|
98
|
+
id: dom.getRootId(scope),
|
|
99
|
+
"data-invalid": dataAttr(invalid),
|
|
100
|
+
"data-readonly": dataAttr(readOnly)
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
getLabelProps() {
|
|
104
|
+
return normalize.label({
|
|
105
|
+
...parts.label.attrs,
|
|
106
|
+
dir: prop("dir"),
|
|
107
|
+
htmlFor: dom.getInputId(scope),
|
|
108
|
+
id: dom.getLabelId(scope),
|
|
109
|
+
"data-readonly": dataAttr(readOnly),
|
|
110
|
+
"data-disabled": dataAttr(disabled),
|
|
111
|
+
"data-invalid": dataAttr(invalid),
|
|
112
|
+
"data-required": dataAttr(required),
|
|
113
|
+
"data-focus": dataAttr(focused),
|
|
114
|
+
onClick(event2) {
|
|
115
|
+
if (composite) return;
|
|
116
|
+
event2.preventDefault();
|
|
117
|
+
dom.getTriggerEl(scope)?.focus({ preventScroll: true });
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
getControlProps() {
|
|
122
|
+
return normalize.element({
|
|
123
|
+
...parts.control.attrs,
|
|
124
|
+
dir: prop("dir"),
|
|
125
|
+
id: dom.getControlId(scope),
|
|
126
|
+
"data-state": open ? "open" : "closed",
|
|
127
|
+
"data-focus": dataAttr(focused),
|
|
128
|
+
"data-disabled": dataAttr(disabled),
|
|
129
|
+
"data-invalid": dataAttr(invalid)
|
|
130
|
+
});
|
|
131
|
+
},
|
|
132
|
+
getPositionerProps() {
|
|
133
|
+
return normalize.element({
|
|
134
|
+
...parts.positioner.attrs,
|
|
135
|
+
dir: prop("dir"),
|
|
136
|
+
id: dom.getPositionerId(scope),
|
|
137
|
+
style: popperStyles.floating
|
|
138
|
+
});
|
|
139
|
+
},
|
|
140
|
+
getInputProps() {
|
|
141
|
+
return normalize.input({
|
|
142
|
+
...parts.input.attrs,
|
|
143
|
+
dir: prop("dir"),
|
|
144
|
+
"aria-invalid": ariaAttr(invalid),
|
|
145
|
+
"data-invalid": dataAttr(invalid),
|
|
146
|
+
"data-autofocus": dataAttr(prop("autoFocus")),
|
|
147
|
+
name: prop("name"),
|
|
148
|
+
form: prop("form"),
|
|
149
|
+
disabled,
|
|
150
|
+
required: prop("required"),
|
|
151
|
+
autoComplete: "off",
|
|
152
|
+
autoCorrect: "off",
|
|
153
|
+
autoCapitalize: "none",
|
|
154
|
+
spellCheck: "false",
|
|
155
|
+
readOnly,
|
|
156
|
+
placeholder: prop("placeholder"),
|
|
157
|
+
id: dom.getInputId(scope),
|
|
158
|
+
type: "text",
|
|
159
|
+
role: "combobox",
|
|
160
|
+
defaultValue: context.get("inputValue"),
|
|
161
|
+
"aria-autocomplete": computed("autoComplete") ? "both" : "list",
|
|
162
|
+
"aria-controls": dom.getContentId(scope),
|
|
163
|
+
"aria-expanded": open,
|
|
164
|
+
"data-state": open ? "open" : "closed",
|
|
165
|
+
"aria-activedescendant": highlightedValue ? dom.getItemId(scope, highlightedValue) : void 0,
|
|
166
|
+
onClick(event2) {
|
|
167
|
+
if (event2.defaultPrevented) return;
|
|
168
|
+
if (!prop("openOnClick")) return;
|
|
169
|
+
if (!interactive) return;
|
|
170
|
+
send({ type: "INPUT.CLICK", src: "input-click" });
|
|
171
|
+
},
|
|
172
|
+
onFocus() {
|
|
173
|
+
if (disabled) return;
|
|
174
|
+
send({ type: "INPUT.FOCUS" });
|
|
175
|
+
},
|
|
176
|
+
onBlur() {
|
|
177
|
+
if (disabled) return;
|
|
178
|
+
send({ type: "INPUT.BLUR" });
|
|
179
|
+
},
|
|
180
|
+
onChange(event2) {
|
|
181
|
+
send({ type: "INPUT.CHANGE", value: event2.currentTarget.value, src: "input-change" });
|
|
182
|
+
},
|
|
183
|
+
onKeyDown(event2) {
|
|
184
|
+
if (event2.defaultPrevented) return;
|
|
185
|
+
if (!interactive) return;
|
|
186
|
+
if (event2.ctrlKey || event2.shiftKey || isComposingEvent(event2)) return;
|
|
187
|
+
const openOnKeyPress = prop("openOnKeyPress");
|
|
188
|
+
const isModifierKey = event2.ctrlKey || event2.metaKey || event2.shiftKey;
|
|
189
|
+
const keypress = true;
|
|
190
|
+
const keymap = {
|
|
191
|
+
ArrowDown(event3) {
|
|
192
|
+
if (!openOnKeyPress && !open) return;
|
|
193
|
+
send({ type: event3.altKey ? "OPEN" : "INPUT.ARROW_DOWN", keypress, src: "arrow-key" });
|
|
194
|
+
event3.preventDefault();
|
|
195
|
+
},
|
|
196
|
+
ArrowUp() {
|
|
197
|
+
if (!openOnKeyPress && !open) return;
|
|
198
|
+
send({ type: event2.altKey ? "CLOSE" : "INPUT.ARROW_UP", keypress, src: "arrow-key" });
|
|
199
|
+
event2.preventDefault();
|
|
200
|
+
},
|
|
201
|
+
Home(event3) {
|
|
202
|
+
if (isModifierKey) return;
|
|
203
|
+
send({ type: "INPUT.HOME", keypress });
|
|
204
|
+
if (open) {
|
|
205
|
+
event3.preventDefault();
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
End(event3) {
|
|
209
|
+
if (isModifierKey) return;
|
|
210
|
+
send({ type: "INPUT.END", keypress });
|
|
211
|
+
if (open) {
|
|
212
|
+
event3.preventDefault();
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
Enter(event3) {
|
|
216
|
+
send({ type: "INPUT.ENTER", keypress, src: "item-select" });
|
|
217
|
+
const submittable = computed("isCustomValue") && prop("allowCustomValue");
|
|
218
|
+
const hasHighlight = highlightedValue != null;
|
|
219
|
+
const alwaysSubmit = prop("alwaysSubmitOnEnter");
|
|
220
|
+
if (open && !submittable && !alwaysSubmit && hasHighlight) {
|
|
221
|
+
event3.preventDefault();
|
|
222
|
+
}
|
|
223
|
+
if (highlightedValue == null) return;
|
|
224
|
+
const itemEl = dom.getItemEl(scope, highlightedValue);
|
|
225
|
+
if (isAnchorElement(itemEl)) {
|
|
226
|
+
prop("navigate")?.({ value: highlightedValue, node: itemEl, href: itemEl.href });
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
Escape() {
|
|
230
|
+
send({ type: "INPUT.ESCAPE", keypress, src: "escape-key" });
|
|
231
|
+
event2.preventDefault();
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
const key = getEventKey(event2, { dir: prop("dir") });
|
|
235
|
+
const exec = keymap[key];
|
|
236
|
+
exec?.(event2);
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
},
|
|
240
|
+
getTriggerProps(props = {}) {
|
|
241
|
+
return normalize.button({
|
|
242
|
+
...parts.trigger.attrs,
|
|
243
|
+
dir: prop("dir"),
|
|
244
|
+
id: dom.getTriggerId(scope),
|
|
245
|
+
"aria-haspopup": composite ? "listbox" : "dialog",
|
|
246
|
+
type: "button",
|
|
247
|
+
tabIndex: props.focusable ? void 0 : -1,
|
|
248
|
+
"aria-label": translations.triggerLabel,
|
|
249
|
+
"aria-expanded": open,
|
|
250
|
+
"data-state": open ? "open" : "closed",
|
|
251
|
+
"aria-controls": open ? dom.getContentId(scope) : void 0,
|
|
252
|
+
disabled,
|
|
253
|
+
"data-invalid": dataAttr(invalid),
|
|
254
|
+
"data-focusable": dataAttr(props.focusable),
|
|
255
|
+
"data-readonly": dataAttr(readOnly),
|
|
256
|
+
"data-disabled": dataAttr(disabled),
|
|
257
|
+
onFocus() {
|
|
258
|
+
if (!props.focusable) return;
|
|
259
|
+
send({ type: "INPUT.FOCUS", src: "trigger" });
|
|
260
|
+
},
|
|
261
|
+
onClick(event2) {
|
|
262
|
+
if (event2.defaultPrevented) return;
|
|
263
|
+
if (!interactive) return;
|
|
264
|
+
if (!isLeftClick(event2)) return;
|
|
265
|
+
send({ type: "TRIGGER.CLICK", src: "trigger-click" });
|
|
266
|
+
},
|
|
267
|
+
onPointerDown(event2) {
|
|
268
|
+
if (!interactive) return;
|
|
269
|
+
if (event2.pointerType === "touch") return;
|
|
270
|
+
if (!isLeftClick(event2)) return;
|
|
271
|
+
event2.preventDefault();
|
|
272
|
+
queueMicrotask(() => {
|
|
273
|
+
dom.focusInputEl(scope);
|
|
274
|
+
});
|
|
275
|
+
},
|
|
276
|
+
onKeyDown(event2) {
|
|
277
|
+
if (event2.defaultPrevented) return;
|
|
278
|
+
if (composite) return;
|
|
279
|
+
const keyMap = {
|
|
280
|
+
ArrowDown() {
|
|
281
|
+
send({ type: "INPUT.ARROW_DOWN", src: "arrow-key" });
|
|
282
|
+
},
|
|
283
|
+
ArrowUp() {
|
|
284
|
+
send({ type: "INPUT.ARROW_UP", src: "arrow-key" });
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
const key = getEventKey(event2, { dir: prop("dir") });
|
|
288
|
+
const exec = keyMap[key];
|
|
289
|
+
if (exec) {
|
|
290
|
+
exec(event2);
|
|
291
|
+
event2.preventDefault();
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
},
|
|
296
|
+
getContentProps() {
|
|
297
|
+
return normalize.element({
|
|
298
|
+
...parts.content.attrs,
|
|
299
|
+
dir: prop("dir"),
|
|
300
|
+
id: dom.getContentId(scope),
|
|
301
|
+
role: !composite ? "dialog" : "listbox",
|
|
302
|
+
tabIndex: -1,
|
|
303
|
+
hidden: !open,
|
|
304
|
+
"data-state": open ? "open" : "closed",
|
|
305
|
+
"data-placement": context.get("currentPlacement"),
|
|
306
|
+
"aria-labelledby": dom.getLabelId(scope),
|
|
307
|
+
"aria-multiselectable": prop("multiple") && composite ? true : void 0,
|
|
308
|
+
"data-empty": dataAttr(collection.size === 0),
|
|
309
|
+
onPointerDown(event2) {
|
|
310
|
+
if (!isLeftClick(event2)) return;
|
|
311
|
+
event2.preventDefault();
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
},
|
|
315
|
+
getListProps() {
|
|
316
|
+
return normalize.element({
|
|
317
|
+
...parts.list.attrs,
|
|
318
|
+
role: !composite ? "listbox" : void 0,
|
|
319
|
+
"data-empty": dataAttr(collection.size === 0),
|
|
320
|
+
"aria-labelledby": dom.getLabelId(scope),
|
|
321
|
+
"aria-multiselectable": prop("multiple") && !composite ? true : void 0
|
|
322
|
+
});
|
|
323
|
+
},
|
|
324
|
+
getClearTriggerProps() {
|
|
325
|
+
return normalize.button({
|
|
326
|
+
...parts.clearTrigger.attrs,
|
|
327
|
+
dir: prop("dir"),
|
|
328
|
+
id: dom.getClearTriggerId(scope),
|
|
329
|
+
type: "button",
|
|
330
|
+
tabIndex: -1,
|
|
331
|
+
disabled,
|
|
332
|
+
"data-invalid": dataAttr(invalid),
|
|
333
|
+
"aria-label": translations.clearTriggerLabel,
|
|
334
|
+
"aria-controls": dom.getInputId(scope),
|
|
335
|
+
hidden: !context.get("value").length,
|
|
336
|
+
onPointerDown(event2) {
|
|
337
|
+
if (!isLeftClick(event2)) return;
|
|
338
|
+
event2.preventDefault();
|
|
339
|
+
},
|
|
340
|
+
onClick(event2) {
|
|
341
|
+
if (event2.defaultPrevented) return;
|
|
342
|
+
if (!interactive) return;
|
|
343
|
+
send({ type: "VALUE.CLEAR", src: "clear-trigger" });
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
},
|
|
347
|
+
getItemState,
|
|
348
|
+
getItemProps(props) {
|
|
349
|
+
const itemState = getItemState(props);
|
|
350
|
+
const value = itemState.value;
|
|
351
|
+
return normalize.element({
|
|
352
|
+
...parts.item.attrs,
|
|
353
|
+
dir: prop("dir"),
|
|
354
|
+
id: dom.getItemId(scope, value),
|
|
355
|
+
role: "option",
|
|
356
|
+
tabIndex: -1,
|
|
357
|
+
"data-highlighted": dataAttr(itemState.highlighted),
|
|
358
|
+
"data-state": itemState.selected ? "checked" : "unchecked",
|
|
359
|
+
"aria-selected": ariaAttr(itemState.selected),
|
|
360
|
+
"aria-disabled": ariaAttr(itemState.disabled),
|
|
361
|
+
"data-disabled": dataAttr(itemState.disabled),
|
|
362
|
+
"data-value": itemState.value,
|
|
363
|
+
onPointerMove() {
|
|
364
|
+
if (itemState.disabled) return;
|
|
365
|
+
if (itemState.highlighted) return;
|
|
366
|
+
send({ type: "ITEM.POINTER_MOVE", value });
|
|
367
|
+
},
|
|
368
|
+
onPointerLeave() {
|
|
369
|
+
if (props.persistFocus) return;
|
|
370
|
+
if (itemState.disabled) return;
|
|
371
|
+
const prev = event.previous();
|
|
372
|
+
const mouseMoved = prev?.type.includes("POINTER");
|
|
373
|
+
if (!mouseMoved) return;
|
|
374
|
+
send({ type: "ITEM.POINTER_LEAVE", value });
|
|
375
|
+
},
|
|
376
|
+
onClick(event2) {
|
|
377
|
+
if (isDownloadingEvent(event2)) return;
|
|
378
|
+
if (isOpeningInNewTab(event2)) return;
|
|
379
|
+
if (isContextMenuEvent(event2)) return;
|
|
380
|
+
if (itemState.disabled) return;
|
|
381
|
+
send({ type: "ITEM.CLICK", src: "item-select", value });
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
},
|
|
385
|
+
getItemTextProps(props) {
|
|
386
|
+
const itemState = getItemState(props);
|
|
387
|
+
return normalize.element({
|
|
388
|
+
...parts.itemText.attrs,
|
|
389
|
+
dir: prop("dir"),
|
|
390
|
+
"data-state": itemState.selected ? "checked" : "unchecked",
|
|
391
|
+
"data-disabled": dataAttr(itemState.disabled),
|
|
392
|
+
"data-highlighted": dataAttr(itemState.highlighted)
|
|
393
|
+
});
|
|
394
|
+
},
|
|
395
|
+
getItemIndicatorProps(props) {
|
|
396
|
+
const itemState = getItemState(props);
|
|
397
|
+
return normalize.element({
|
|
398
|
+
"aria-hidden": true,
|
|
399
|
+
...parts.itemIndicator.attrs,
|
|
400
|
+
dir: prop("dir"),
|
|
401
|
+
"data-state": itemState.selected ? "checked" : "unchecked",
|
|
402
|
+
hidden: !itemState.selected
|
|
403
|
+
});
|
|
404
|
+
},
|
|
405
|
+
getItemGroupProps(props) {
|
|
406
|
+
const { id } = props;
|
|
407
|
+
return normalize.element({
|
|
408
|
+
...parts.itemGroup.attrs,
|
|
409
|
+
dir: prop("dir"),
|
|
410
|
+
id: dom.getItemGroupId(scope, id),
|
|
411
|
+
"aria-labelledby": dom.getItemGroupLabelId(scope, id),
|
|
412
|
+
"data-empty": dataAttr(collection.size === 0),
|
|
413
|
+
role: "group"
|
|
414
|
+
});
|
|
415
|
+
},
|
|
416
|
+
getItemGroupLabelProps(props) {
|
|
417
|
+
const { htmlFor } = props;
|
|
418
|
+
return normalize.element({
|
|
419
|
+
...parts.itemGroupLabel.attrs,
|
|
420
|
+
dir: prop("dir"),
|
|
421
|
+
id: dom.getItemGroupLabelId(scope, htmlFor),
|
|
422
|
+
role: "presentation"
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
export {
|
|
428
|
+
connect
|
|
429
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Scope } from '@zag-js/core';
|
|
2
|
+
|
|
3
|
+
declare const getRootId: (ctx: Scope) => any;
|
|
4
|
+
declare const getLabelId: (ctx: Scope) => any;
|
|
5
|
+
declare const getControlId: (ctx: Scope) => any;
|
|
6
|
+
declare const getInputId: (ctx: Scope) => any;
|
|
7
|
+
declare const getContentId: (ctx: Scope) => any;
|
|
8
|
+
declare const getPositionerId: (ctx: Scope) => any;
|
|
9
|
+
declare const getTriggerId: (ctx: Scope) => any;
|
|
10
|
+
declare const getClearTriggerId: (ctx: Scope) => any;
|
|
11
|
+
declare const getItemGroupId: (ctx: Scope, id: string | number) => any;
|
|
12
|
+
declare const getItemGroupLabelId: (ctx: Scope, id: string | number) => any;
|
|
13
|
+
declare const getItemId: (ctx: Scope, id: string) => any;
|
|
14
|
+
declare const getContentEl: (ctx: Scope) => HTMLElement | null;
|
|
15
|
+
declare const getInputEl: (ctx: Scope) => HTMLInputElement | null;
|
|
16
|
+
declare const getPositionerEl: (ctx: Scope) => HTMLElement | null;
|
|
17
|
+
declare const getControlEl: (ctx: Scope) => HTMLElement | null;
|
|
18
|
+
declare const getTriggerEl: (ctx: Scope) => HTMLElement | null;
|
|
19
|
+
declare const getClearTriggerEl: (ctx: Scope) => HTMLElement | null;
|
|
20
|
+
declare const getItemEl: (ctx: Scope, value: string | null) => HTMLElement | null;
|
|
21
|
+
declare const focusInputEl: (ctx: Scope) => void;
|
|
22
|
+
declare const focusTriggerEl: (ctx: Scope) => void;
|
|
23
|
+
|
|
24
|
+
export { focusInputEl, focusTriggerEl, getClearTriggerEl, getClearTriggerId, getContentEl, getContentId, getControlEl, getControlId, getInputEl, getInputId, getItemEl, getItemGroupId, getItemGroupLabelId, getItemId, getLabelId, getPositionerEl, getPositionerId, getRootId, getTriggerEl, getTriggerId };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Scope } from '@zag-js/core';
|
|
2
|
+
|
|
3
|
+
declare const getRootId: (ctx: Scope) => any;
|
|
4
|
+
declare const getLabelId: (ctx: Scope) => any;
|
|
5
|
+
declare const getControlId: (ctx: Scope) => any;
|
|
6
|
+
declare const getInputId: (ctx: Scope) => any;
|
|
7
|
+
declare const getContentId: (ctx: Scope) => any;
|
|
8
|
+
declare const getPositionerId: (ctx: Scope) => any;
|
|
9
|
+
declare const getTriggerId: (ctx: Scope) => any;
|
|
10
|
+
declare const getClearTriggerId: (ctx: Scope) => any;
|
|
11
|
+
declare const getItemGroupId: (ctx: Scope, id: string | number) => any;
|
|
12
|
+
declare const getItemGroupLabelId: (ctx: Scope, id: string | number) => any;
|
|
13
|
+
declare const getItemId: (ctx: Scope, id: string) => any;
|
|
14
|
+
declare const getContentEl: (ctx: Scope) => HTMLElement | null;
|
|
15
|
+
declare const getInputEl: (ctx: Scope) => HTMLInputElement | null;
|
|
16
|
+
declare const getPositionerEl: (ctx: Scope) => HTMLElement | null;
|
|
17
|
+
declare const getControlEl: (ctx: Scope) => HTMLElement | null;
|
|
18
|
+
declare const getTriggerEl: (ctx: Scope) => HTMLElement | null;
|
|
19
|
+
declare const getClearTriggerEl: (ctx: Scope) => HTMLElement | null;
|
|
20
|
+
declare const getItemEl: (ctx: Scope, value: string | null) => HTMLElement | null;
|
|
21
|
+
declare const focusInputEl: (ctx: Scope) => void;
|
|
22
|
+
declare const focusTriggerEl: (ctx: Scope) => void;
|
|
23
|
+
|
|
24
|
+
export { focusInputEl, focusTriggerEl, getClearTriggerEl, getClearTriggerId, getContentEl, getContentId, getControlEl, getControlId, getInputEl, getInputId, getItemEl, getItemGroupId, getItemGroupLabelId, getItemId, getLabelId, getPositionerEl, getPositionerId, getRootId, getTriggerEl, getTriggerId };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/combobox.dom.ts
|
|
21
|
+
var combobox_dom_exports = {};
|
|
22
|
+
__export(combobox_dom_exports, {
|
|
23
|
+
focusInputEl: () => focusInputEl,
|
|
24
|
+
focusTriggerEl: () => focusTriggerEl,
|
|
25
|
+
getClearTriggerEl: () => getClearTriggerEl,
|
|
26
|
+
getClearTriggerId: () => getClearTriggerId,
|
|
27
|
+
getContentEl: () => getContentEl,
|
|
28
|
+
getContentId: () => getContentId,
|
|
29
|
+
getControlEl: () => getControlEl,
|
|
30
|
+
getControlId: () => getControlId,
|
|
31
|
+
getInputEl: () => getInputEl,
|
|
32
|
+
getInputId: () => getInputId,
|
|
33
|
+
getItemEl: () => getItemEl,
|
|
34
|
+
getItemGroupId: () => getItemGroupId,
|
|
35
|
+
getItemGroupLabelId: () => getItemGroupLabelId,
|
|
36
|
+
getItemId: () => getItemId,
|
|
37
|
+
getLabelId: () => getLabelId,
|
|
38
|
+
getPositionerEl: () => getPositionerEl,
|
|
39
|
+
getPositionerId: () => getPositionerId,
|
|
40
|
+
getRootId: () => getRootId,
|
|
41
|
+
getTriggerEl: () => getTriggerEl,
|
|
42
|
+
getTriggerId: () => getTriggerId
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(combobox_dom_exports);
|
|
45
|
+
var import_dom_query = require("@zag-js/dom-query");
|
|
46
|
+
var getRootId = (ctx) => ctx.ids?.root ?? `combobox:${ctx.id}`;
|
|
47
|
+
var getLabelId = (ctx) => ctx.ids?.label ?? `combobox:${ctx.id}:label`;
|
|
48
|
+
var getControlId = (ctx) => ctx.ids?.control ?? `combobox:${ctx.id}:control`;
|
|
49
|
+
var getInputId = (ctx) => ctx.ids?.input ?? `combobox:${ctx.id}:input`;
|
|
50
|
+
var getContentId = (ctx) => ctx.ids?.content ?? `combobox:${ctx.id}:content`;
|
|
51
|
+
var getPositionerId = (ctx) => ctx.ids?.positioner ?? `combobox:${ctx.id}:popper`;
|
|
52
|
+
var getTriggerId = (ctx) => ctx.ids?.trigger ?? `combobox:${ctx.id}:toggle-btn`;
|
|
53
|
+
var getClearTriggerId = (ctx) => ctx.ids?.clearTrigger ?? `combobox:${ctx.id}:clear-btn`;
|
|
54
|
+
var getItemGroupId = (ctx, id) => ctx.ids?.itemGroup?.(id) ?? `combobox:${ctx.id}:optgroup:${id}`;
|
|
55
|
+
var getItemGroupLabelId = (ctx, id) => ctx.ids?.itemGroupLabel?.(id) ?? `combobox:${ctx.id}:optgroup-label:${id}`;
|
|
56
|
+
var getItemId = (ctx, id) => ctx.ids?.item?.(id) ?? `combobox:${ctx.id}:option:${id}`;
|
|
57
|
+
var getContentEl = (ctx) => ctx.getById(getContentId(ctx));
|
|
58
|
+
var getInputEl = (ctx) => ctx.getById(getInputId(ctx));
|
|
59
|
+
var getPositionerEl = (ctx) => ctx.getById(getPositionerId(ctx));
|
|
60
|
+
var getControlEl = (ctx) => ctx.getById(getControlId(ctx));
|
|
61
|
+
var getTriggerEl = (ctx) => ctx.getById(getTriggerId(ctx));
|
|
62
|
+
var getClearTriggerEl = (ctx) => ctx.getById(getClearTriggerId(ctx));
|
|
63
|
+
var getItemEl = (ctx, value) => {
|
|
64
|
+
if (value == null) return null;
|
|
65
|
+
const selector = `[role=option][data-value="${CSS.escape(value)}"]`;
|
|
66
|
+
return (0, import_dom_query.query)(getContentEl(ctx), selector);
|
|
67
|
+
};
|
|
68
|
+
var focusInputEl = (ctx) => {
|
|
69
|
+
const inputEl = getInputEl(ctx);
|
|
70
|
+
if (!ctx.isActiveElement(inputEl)) {
|
|
71
|
+
inputEl?.focus({ preventScroll: true });
|
|
72
|
+
}
|
|
73
|
+
(0, import_dom_query.setCaretToEnd)(inputEl);
|
|
74
|
+
};
|
|
75
|
+
var focusTriggerEl = (ctx) => {
|
|
76
|
+
const triggerEl = getTriggerEl(ctx);
|
|
77
|
+
if (ctx.isActiveElement(triggerEl)) return;
|
|
78
|
+
triggerEl?.focus({ preventScroll: true });
|
|
79
|
+
};
|
|
80
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
81
|
+
0 && (module.exports = {
|
|
82
|
+
focusInputEl,
|
|
83
|
+
focusTriggerEl,
|
|
84
|
+
getClearTriggerEl,
|
|
85
|
+
getClearTriggerId,
|
|
86
|
+
getContentEl,
|
|
87
|
+
getContentId,
|
|
88
|
+
getControlEl,
|
|
89
|
+
getControlId,
|
|
90
|
+
getInputEl,
|
|
91
|
+
getInputId,
|
|
92
|
+
getItemEl,
|
|
93
|
+
getItemGroupId,
|
|
94
|
+
getItemGroupLabelId,
|
|
95
|
+
getItemId,
|
|
96
|
+
getLabelId,
|
|
97
|
+
getPositionerEl,
|
|
98
|
+
getPositionerId,
|
|
99
|
+
getRootId,
|
|
100
|
+
getTriggerEl,
|
|
101
|
+
getTriggerId
|
|
102
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// src/combobox.dom.ts
|
|
2
|
+
import { query, setCaretToEnd } from "@zag-js/dom-query";
|
|
3
|
+
var getRootId = (ctx) => ctx.ids?.root ?? `combobox:${ctx.id}`;
|
|
4
|
+
var getLabelId = (ctx) => ctx.ids?.label ?? `combobox:${ctx.id}:label`;
|
|
5
|
+
var getControlId = (ctx) => ctx.ids?.control ?? `combobox:${ctx.id}:control`;
|
|
6
|
+
var getInputId = (ctx) => ctx.ids?.input ?? `combobox:${ctx.id}:input`;
|
|
7
|
+
var getContentId = (ctx) => ctx.ids?.content ?? `combobox:${ctx.id}:content`;
|
|
8
|
+
var getPositionerId = (ctx) => ctx.ids?.positioner ?? `combobox:${ctx.id}:popper`;
|
|
9
|
+
var getTriggerId = (ctx) => ctx.ids?.trigger ?? `combobox:${ctx.id}:toggle-btn`;
|
|
10
|
+
var getClearTriggerId = (ctx) => ctx.ids?.clearTrigger ?? `combobox:${ctx.id}:clear-btn`;
|
|
11
|
+
var getItemGroupId = (ctx, id) => ctx.ids?.itemGroup?.(id) ?? `combobox:${ctx.id}:optgroup:${id}`;
|
|
12
|
+
var getItemGroupLabelId = (ctx, id) => ctx.ids?.itemGroupLabel?.(id) ?? `combobox:${ctx.id}:optgroup-label:${id}`;
|
|
13
|
+
var getItemId = (ctx, id) => ctx.ids?.item?.(id) ?? `combobox:${ctx.id}:option:${id}`;
|
|
14
|
+
var getContentEl = (ctx) => ctx.getById(getContentId(ctx));
|
|
15
|
+
var getInputEl = (ctx) => ctx.getById(getInputId(ctx));
|
|
16
|
+
var getPositionerEl = (ctx) => ctx.getById(getPositionerId(ctx));
|
|
17
|
+
var getControlEl = (ctx) => ctx.getById(getControlId(ctx));
|
|
18
|
+
var getTriggerEl = (ctx) => ctx.getById(getTriggerId(ctx));
|
|
19
|
+
var getClearTriggerEl = (ctx) => ctx.getById(getClearTriggerId(ctx));
|
|
20
|
+
var getItemEl = (ctx, value) => {
|
|
21
|
+
if (value == null) return null;
|
|
22
|
+
const selector = `[role=option][data-value="${CSS.escape(value)}"]`;
|
|
23
|
+
return query(getContentEl(ctx), selector);
|
|
24
|
+
};
|
|
25
|
+
var focusInputEl = (ctx) => {
|
|
26
|
+
const inputEl = getInputEl(ctx);
|
|
27
|
+
if (!ctx.isActiveElement(inputEl)) {
|
|
28
|
+
inputEl?.focus({ preventScroll: true });
|
|
29
|
+
}
|
|
30
|
+
setCaretToEnd(inputEl);
|
|
31
|
+
};
|
|
32
|
+
var focusTriggerEl = (ctx) => {
|
|
33
|
+
const triggerEl = getTriggerEl(ctx);
|
|
34
|
+
if (ctx.isActiveElement(triggerEl)) return;
|
|
35
|
+
triggerEl?.focus({ preventScroll: true });
|
|
36
|
+
};
|
|
37
|
+
export {
|
|
38
|
+
focusInputEl,
|
|
39
|
+
focusTriggerEl,
|
|
40
|
+
getClearTriggerEl,
|
|
41
|
+
getClearTriggerId,
|
|
42
|
+
getContentEl,
|
|
43
|
+
getContentId,
|
|
44
|
+
getControlEl,
|
|
45
|
+
getControlId,
|
|
46
|
+
getInputEl,
|
|
47
|
+
getInputId,
|
|
48
|
+
getItemEl,
|
|
49
|
+
getItemGroupId,
|
|
50
|
+
getItemGroupLabelId,
|
|
51
|
+
getItemId,
|
|
52
|
+
getLabelId,
|
|
53
|
+
getPositionerEl,
|
|
54
|
+
getPositionerId,
|
|
55
|
+
getRootId,
|
|
56
|
+
getTriggerEl,
|
|
57
|
+
getTriggerId
|
|
58
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as _zag_js_core from '@zag-js/core';
|
|
2
|
+
import { ComboboxSchema } from './combobox.types.mjs';
|
|
3
|
+
import '@zag-js/collection';
|
|
4
|
+
import '@zag-js/dismissable';
|
|
5
|
+
import '@zag-js/popper';
|
|
6
|
+
import '@zag-js/types';
|
|
7
|
+
|
|
8
|
+
declare const machine: _zag_js_core.Machine<ComboboxSchema<any>>;
|
|
9
|
+
|
|
10
|
+
export { machine };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as _zag_js_core from '@zag-js/core';
|
|
2
|
+
import { ComboboxSchema } from './combobox.types.js';
|
|
3
|
+
import '@zag-js/collection';
|
|
4
|
+
import '@zag-js/dismissable';
|
|
5
|
+
import '@zag-js/popper';
|
|
6
|
+
import '@zag-js/types';
|
|
7
|
+
|
|
8
|
+
declare const machine: _zag_js_core.Machine<ComboboxSchema<any>>;
|
|
9
|
+
|
|
10
|
+
export { machine };
|