@zag-js/radio-group 0.1.6 → 0.1.7
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/chunk-EQKWEHJW.mjs +192 -0
- package/dist/chunk-JSIZLP57.mjs +110 -0
- package/dist/chunk-KXAYH7UX.mjs +197 -0
- package/dist/chunk-MGLN5L3R.mjs +16 -0
- package/dist/index.d.ts +7 -951
- package/dist/index.js +44 -32
- package/dist/index.mjs +10 -476
- package/dist/radio-group.anatomy.d.ts +6 -0
- package/dist/radio-group.anatomy.js +41 -0
- package/dist/radio-group.anatomy.mjs +8 -0
- package/dist/radio-group.connect.d.ts +18 -0
- package/dist/radio-group.connect.js +330 -0
- package/dist/radio-group.connect.mjs +8 -0
- package/dist/radio-group.dom.d.ts +39 -0
- package/dist/radio-group.dom.js +131 -0
- package/dist/radio-group.dom.mjs +6 -0
- package/dist/radio-group.machine.d.ts +7 -0
- package/dist/radio-group.machine.js +317 -0
- package/dist/radio-group.machine.mjs +7 -0
- package/dist/radio-group.types.d.ts +86 -0
- package/dist/radio-group.types.js +18 -0
- package/dist/radio-group.types.mjs +0 -0
- package/package.json +22 -12
|
@@ -0,0 +1,330 @@
|
|
|
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/radio-group.connect.ts
|
|
21
|
+
var radio_group_connect_exports = {};
|
|
22
|
+
__export(radio_group_connect_exports, {
|
|
23
|
+
connect: () => connect
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(radio_group_connect_exports);
|
|
26
|
+
|
|
27
|
+
// ../../utilities/dom/src/attrs.ts
|
|
28
|
+
var dataAttr = (guard) => {
|
|
29
|
+
return guard ? "" : void 0;
|
|
30
|
+
};
|
|
31
|
+
var ariaAttr = (guard) => {
|
|
32
|
+
return guard ? "true" : void 0;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// ../../utilities/dom/src/query.ts
|
|
36
|
+
function isDocument(el) {
|
|
37
|
+
return el.nodeType === Node.DOCUMENT_NODE;
|
|
38
|
+
}
|
|
39
|
+
function isWindow(value) {
|
|
40
|
+
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
41
|
+
}
|
|
42
|
+
function getDocument(el) {
|
|
43
|
+
var _a;
|
|
44
|
+
if (isWindow(el))
|
|
45
|
+
return el.document;
|
|
46
|
+
if (isDocument(el))
|
|
47
|
+
return el;
|
|
48
|
+
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
49
|
+
}
|
|
50
|
+
function defineDomHelpers(helpers) {
|
|
51
|
+
const dom2 = {
|
|
52
|
+
getRootNode: (ctx) => {
|
|
53
|
+
var _a, _b;
|
|
54
|
+
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
55
|
+
},
|
|
56
|
+
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
57
|
+
getWin: (ctx) => {
|
|
58
|
+
var _a;
|
|
59
|
+
return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
|
|
60
|
+
},
|
|
61
|
+
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
62
|
+
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
|
|
63
|
+
createEmitter: (ctx, target) => {
|
|
64
|
+
const win = dom2.getWin(ctx);
|
|
65
|
+
return function emit(evt, detail, options) {
|
|
66
|
+
const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
|
|
67
|
+
const eventName = `zag:${evt}`;
|
|
68
|
+
const init = { bubbles, cancelable, composed, detail };
|
|
69
|
+
const event = new win.CustomEvent(eventName, init);
|
|
70
|
+
target.dispatchEvent(event);
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
createListener: (target) => {
|
|
74
|
+
return function listen(evt, handler) {
|
|
75
|
+
const eventName = `zag:${evt}`;
|
|
76
|
+
const listener = (e) => handler(e);
|
|
77
|
+
target.addEventListener(eventName, listener);
|
|
78
|
+
return () => target.removeEventListener(eventName, listener);
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
return {
|
|
83
|
+
...dom2,
|
|
84
|
+
...helpers
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ../../utilities/dom/src/nodelist.ts
|
|
89
|
+
function queryAll(root, selector) {
|
|
90
|
+
var _a;
|
|
91
|
+
return Array.from((_a = root == null ? void 0 : root.querySelectorAll(selector)) != null ? _a : []);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// ../../utilities/dom/src/visually-hidden.ts
|
|
95
|
+
var visuallyHiddenStyle = {
|
|
96
|
+
border: "0",
|
|
97
|
+
clip: "rect(0 0 0 0)",
|
|
98
|
+
height: "1px",
|
|
99
|
+
margin: "-1px",
|
|
100
|
+
overflow: "hidden",
|
|
101
|
+
padding: "0",
|
|
102
|
+
position: "absolute",
|
|
103
|
+
width: "1px",
|
|
104
|
+
whiteSpace: "nowrap",
|
|
105
|
+
wordWrap: "normal"
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
// src/radio-group.anatomy.ts
|
|
109
|
+
var import_anatomy = require("@zag-js/anatomy");
|
|
110
|
+
var anatomy = (0, import_anatomy.createAnatomy)("radio-group").parts(
|
|
111
|
+
"root",
|
|
112
|
+
"label",
|
|
113
|
+
"radio",
|
|
114
|
+
"radioLabel",
|
|
115
|
+
"radioControl",
|
|
116
|
+
"radioInput"
|
|
117
|
+
);
|
|
118
|
+
var parts = anatomy.build();
|
|
119
|
+
|
|
120
|
+
// src/radio-group.dom.ts
|
|
121
|
+
var dom = defineDomHelpers({
|
|
122
|
+
getRootId: (ctx) => {
|
|
123
|
+
var _a, _b;
|
|
124
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `radio-group:${ctx.id}`;
|
|
125
|
+
},
|
|
126
|
+
getLabelId: (ctx) => {
|
|
127
|
+
var _a, _b;
|
|
128
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `radio-group:${ctx.id}:label`;
|
|
129
|
+
},
|
|
130
|
+
getRadioId: (ctx, value) => {
|
|
131
|
+
var _a, _b, _c;
|
|
132
|
+
return (_c = (_b = (_a = ctx.ids) == null ? void 0 : _a.radio) == null ? void 0 : _b.call(_a, value)) != null ? _c : `radio-group:${ctx.id}:radio:${value}`;
|
|
133
|
+
},
|
|
134
|
+
getRadioInputId: (ctx, value) => {
|
|
135
|
+
var _a, _b, _c;
|
|
136
|
+
return (_c = (_b = (_a = ctx.ids) == null ? void 0 : _a.radioInput) == null ? void 0 : _b.call(_a, value)) != null ? _c : `radio-group:${ctx.id}:radio:input:${value}`;
|
|
137
|
+
},
|
|
138
|
+
getRadioControlId: (ctx, value) => {
|
|
139
|
+
var _a, _b, _c;
|
|
140
|
+
return (_c = (_b = (_a = ctx.ids) == null ? void 0 : _a.radioControl) == null ? void 0 : _b.call(_a, value)) != null ? _c : `radio-group:${ctx.id}:radio:control:${value}`;
|
|
141
|
+
},
|
|
142
|
+
getRadioLabelId: (ctx, value) => {
|
|
143
|
+
var _a, _b, _c;
|
|
144
|
+
return (_c = (_b = (_a = ctx.ids) == null ? void 0 : _a.radioLabel) == null ? void 0 : _b.call(_a, value)) != null ? _c : `radio-group:${ctx.id}:radio:label:${value}`;
|
|
145
|
+
},
|
|
146
|
+
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
147
|
+
getRadioInputEl: (ctx, value) => dom.getById(ctx, dom.getRadioInputId(ctx, value)),
|
|
148
|
+
getFirstEnabledInputEl: (ctx) => {
|
|
149
|
+
var _a;
|
|
150
|
+
return (_a = dom.getRootEl(ctx)) == null ? void 0 : _a.querySelector("input:not(:disabled)");
|
|
151
|
+
},
|
|
152
|
+
getFirstEnabledAndCheckedInputEl: (ctx) => {
|
|
153
|
+
var _a;
|
|
154
|
+
return (_a = dom.getRootEl(ctx)) == null ? void 0 : _a.querySelector("input:not(:disabled):checked");
|
|
155
|
+
},
|
|
156
|
+
getInputEls: (ctx) => {
|
|
157
|
+
const ownerId = CSS.escape(dom.getRootId(ctx));
|
|
158
|
+
const selector = `input[type=radio][data-ownedby='${ownerId}']:not([disabled])`;
|
|
159
|
+
return queryAll(dom.getRootEl(ctx), selector);
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// src/radio-group.connect.ts
|
|
164
|
+
function connect(state, send, normalize) {
|
|
165
|
+
const isGroupDisabled = state.context.disabled;
|
|
166
|
+
const isGroupReadOnly = state.context.readOnly;
|
|
167
|
+
function getRadioState(props) {
|
|
168
|
+
const radioState = {
|
|
169
|
+
isReadOnly: props.readOnly || isGroupReadOnly,
|
|
170
|
+
isInvalid: props.invalid,
|
|
171
|
+
isDisabled: props.disabled || isGroupDisabled,
|
|
172
|
+
isChecked: state.context.value === props.value,
|
|
173
|
+
isFocused: state.context.focusedId === props.value,
|
|
174
|
+
isHovered: state.context.hoveredId === props.value,
|
|
175
|
+
isActive: state.context.activeId === props.value
|
|
176
|
+
};
|
|
177
|
+
return {
|
|
178
|
+
...radioState,
|
|
179
|
+
isInteractive: !(radioState.isReadOnly || radioState.isDisabled)
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
function getRadioDataSet(props) {
|
|
183
|
+
const radioState = getRadioState(props);
|
|
184
|
+
return {
|
|
185
|
+
"data-focus": dataAttr(radioState.isFocused),
|
|
186
|
+
"data-disabled": dataAttr(radioState.isDisabled),
|
|
187
|
+
"data-checked": dataAttr(radioState.isChecked),
|
|
188
|
+
"data-hover": dataAttr(radioState.isHovered),
|
|
189
|
+
"data-invalid": dataAttr(radioState.isInvalid),
|
|
190
|
+
"data-readonly": dataAttr(radioState.isReadOnly)
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
const focus = () => {
|
|
194
|
+
const firstEnabledAndCheckedInput = dom.getFirstEnabledAndCheckedInputEl(state.context);
|
|
195
|
+
if (firstEnabledAndCheckedInput) {
|
|
196
|
+
firstEnabledAndCheckedInput.focus();
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const firstEnabledInput = dom.getFirstEnabledInputEl(state.context);
|
|
200
|
+
firstEnabledInput == null ? void 0 : firstEnabledInput.focus();
|
|
201
|
+
};
|
|
202
|
+
return {
|
|
203
|
+
value: state.context.value,
|
|
204
|
+
setValue(value) {
|
|
205
|
+
send({ type: "SET_VALUE", value, manual: true });
|
|
206
|
+
},
|
|
207
|
+
focus,
|
|
208
|
+
blur() {
|
|
209
|
+
const focusedElement = dom.getActiveElement(state.context);
|
|
210
|
+
const inputEls = dom.getInputEls(state.context);
|
|
211
|
+
const radioInputIsFocused = inputEls.some((el) => el === focusedElement);
|
|
212
|
+
if (radioInputIsFocused)
|
|
213
|
+
focusedElement == null ? void 0 : focusedElement.blur();
|
|
214
|
+
},
|
|
215
|
+
rootProps: normalize.element({
|
|
216
|
+
...parts.root.attrs,
|
|
217
|
+
role: "radiogroup",
|
|
218
|
+
id: dom.getRootId(state.context),
|
|
219
|
+
"data-orientation": state.context.orientation,
|
|
220
|
+
"aria-orientation": state.context.orientation,
|
|
221
|
+
dir: state.context.dir
|
|
222
|
+
}),
|
|
223
|
+
labelProps: normalize.element({
|
|
224
|
+
...parts.label.attrs,
|
|
225
|
+
id: dom.getLabelId(state.context),
|
|
226
|
+
onClick: focus
|
|
227
|
+
}),
|
|
228
|
+
getRadioProps(props) {
|
|
229
|
+
const rootState = getRadioState(props);
|
|
230
|
+
return normalize.label({
|
|
231
|
+
...parts.radio.attrs,
|
|
232
|
+
id: dom.getRadioId(state.context, props.value),
|
|
233
|
+
htmlFor: dom.getRadioInputId(state.context, props.value),
|
|
234
|
+
...getRadioDataSet(props),
|
|
235
|
+
onPointerMove() {
|
|
236
|
+
if (!rootState.isInteractive)
|
|
237
|
+
return;
|
|
238
|
+
send({ type: "SET_HOVERED", value: props.value, hovered: true });
|
|
239
|
+
},
|
|
240
|
+
onPointerLeave() {
|
|
241
|
+
if (!rootState.isInteractive)
|
|
242
|
+
return;
|
|
243
|
+
send({ type: "SET_HOVERED", value: null });
|
|
244
|
+
},
|
|
245
|
+
onPointerDown(event) {
|
|
246
|
+
if (!rootState.isInteractive)
|
|
247
|
+
return;
|
|
248
|
+
if (rootState.isFocused)
|
|
249
|
+
event.preventDefault();
|
|
250
|
+
send({ type: "SET_ACTIVE", value: props.value, active: true });
|
|
251
|
+
},
|
|
252
|
+
onPointerUp() {
|
|
253
|
+
if (!rootState.isInteractive)
|
|
254
|
+
return;
|
|
255
|
+
send({ type: "SET_ACTIVE", value: null });
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
},
|
|
259
|
+
getRadioLabelProps(props) {
|
|
260
|
+
return normalize.element({
|
|
261
|
+
...parts.radioLabel.attrs,
|
|
262
|
+
id: dom.getRadioLabelId(state.context, props.value),
|
|
263
|
+
...getRadioDataSet(props)
|
|
264
|
+
});
|
|
265
|
+
},
|
|
266
|
+
getRadioControlProps(props) {
|
|
267
|
+
const controlState = getRadioState(props);
|
|
268
|
+
return normalize.element({
|
|
269
|
+
...parts.radioControl.attrs,
|
|
270
|
+
id: dom.getRadioControlId(state.context, props.value),
|
|
271
|
+
"data-active": dataAttr(controlState.isActive),
|
|
272
|
+
"aria-hidden": true,
|
|
273
|
+
...getRadioDataSet(props)
|
|
274
|
+
});
|
|
275
|
+
},
|
|
276
|
+
getRadioInputProps(props) {
|
|
277
|
+
const inputState = getRadioState(props);
|
|
278
|
+
const isRequired = props.required;
|
|
279
|
+
const trulyDisabled = inputState.isDisabled && !props.focusable;
|
|
280
|
+
return normalize.input({
|
|
281
|
+
...parts.radioInput.attrs,
|
|
282
|
+
"data-ownedby": dom.getRootId(state.context),
|
|
283
|
+
id: dom.getRadioInputId(state.context, props.value),
|
|
284
|
+
type: "radio",
|
|
285
|
+
name: state.context.name || state.context.id,
|
|
286
|
+
form: state.context.form,
|
|
287
|
+
value: props.value,
|
|
288
|
+
onChange(event) {
|
|
289
|
+
if (inputState.isReadOnly || inputState.isDisabled) {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
if (event.target.checked) {
|
|
293
|
+
send({ type: "SET_VALUE", value: props.value });
|
|
294
|
+
}
|
|
295
|
+
},
|
|
296
|
+
onBlur() {
|
|
297
|
+
send({ type: "SET_FOCUSED", value: null });
|
|
298
|
+
},
|
|
299
|
+
onFocus() {
|
|
300
|
+
send({ type: "SET_FOCUSED", value: props.value, focused: true });
|
|
301
|
+
},
|
|
302
|
+
onKeyDown(event) {
|
|
303
|
+
if (event.key === " ") {
|
|
304
|
+
send({ type: "SET_ACTIVE", value: props.value, active: true });
|
|
305
|
+
}
|
|
306
|
+
},
|
|
307
|
+
onKeyUp(event) {
|
|
308
|
+
if (event.key === " ") {
|
|
309
|
+
send({ type: "SET_ACTIVE", value: null });
|
|
310
|
+
}
|
|
311
|
+
},
|
|
312
|
+
disabled: trulyDisabled,
|
|
313
|
+
required: isRequired,
|
|
314
|
+
defaultChecked: inputState.isChecked,
|
|
315
|
+
"data-disabled": dataAttr(inputState.isDisabled),
|
|
316
|
+
"aria-required": ariaAttr(isRequired),
|
|
317
|
+
"aria-invalid": ariaAttr(inputState.isInvalid),
|
|
318
|
+
readOnly: inputState.isReadOnly,
|
|
319
|
+
"data-readonly": dataAttr(inputState.isReadOnly),
|
|
320
|
+
"aria-disabled": ariaAttr(trulyDisabled),
|
|
321
|
+
"aria-checked": ariaAttr(inputState.isChecked),
|
|
322
|
+
style: visuallyHiddenStyle
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
328
|
+
0 && (module.exports = {
|
|
329
|
+
connect
|
|
330
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { MachineContext } from './radio-group.types.js';
|
|
2
|
+
import '@zag-js/core';
|
|
3
|
+
import '@zag-js/types';
|
|
4
|
+
|
|
5
|
+
declare const dom: {
|
|
6
|
+
getRootNode: (ctx: {
|
|
7
|
+
getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
|
|
8
|
+
}) => Document | ShadowRoot;
|
|
9
|
+
getDoc: (ctx: {
|
|
10
|
+
getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
|
|
11
|
+
}) => Document;
|
|
12
|
+
getWin: (ctx: {
|
|
13
|
+
getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
|
|
14
|
+
}) => Window & typeof globalThis;
|
|
15
|
+
getActiveElement: (ctx: {
|
|
16
|
+
getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
|
|
17
|
+
}) => HTMLElement | null;
|
|
18
|
+
getById: <T = HTMLElement>(ctx: {
|
|
19
|
+
getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
|
|
20
|
+
}, id: string) => T | null;
|
|
21
|
+
createEmitter: (ctx: {
|
|
22
|
+
getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
|
|
23
|
+
}, target: HTMLElement) => (evt: string, detail: Record<string, any>, options?: EventInit | undefined) => void;
|
|
24
|
+
createListener: (target: HTMLElement) => <T_1 = any>(evt: string, handler: (e: CustomEvent<T_1>) => void) => () => void;
|
|
25
|
+
} & {
|
|
26
|
+
getRootId: (ctx: MachineContext) => string;
|
|
27
|
+
getLabelId: (ctx: MachineContext) => string;
|
|
28
|
+
getRadioId: (ctx: MachineContext, value: string) => string;
|
|
29
|
+
getRadioInputId: (ctx: MachineContext, value: string) => string;
|
|
30
|
+
getRadioControlId: (ctx: MachineContext, value: string) => string;
|
|
31
|
+
getRadioLabelId: (ctx: MachineContext, value: string) => string;
|
|
32
|
+
getRootEl: (ctx: MachineContext) => HTMLElement | null;
|
|
33
|
+
getRadioInputEl: (ctx: MachineContext, value: string) => HTMLInputElement | null;
|
|
34
|
+
getFirstEnabledInputEl: (ctx: MachineContext) => HTMLInputElement | null | undefined;
|
|
35
|
+
getFirstEnabledAndCheckedInputEl: (ctx: MachineContext) => HTMLInputElement | null | undefined;
|
|
36
|
+
getInputEls: (ctx: MachineContext) => HTMLElement[];
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export { dom };
|
|
@@ -0,0 +1,131 @@
|
|
|
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/radio-group.dom.ts
|
|
21
|
+
var radio_group_dom_exports = {};
|
|
22
|
+
__export(radio_group_dom_exports, {
|
|
23
|
+
dom: () => dom
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(radio_group_dom_exports);
|
|
26
|
+
|
|
27
|
+
// ../../utilities/dom/src/query.ts
|
|
28
|
+
function isDocument(el) {
|
|
29
|
+
return el.nodeType === Node.DOCUMENT_NODE;
|
|
30
|
+
}
|
|
31
|
+
function isWindow(value) {
|
|
32
|
+
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
33
|
+
}
|
|
34
|
+
function getDocument(el) {
|
|
35
|
+
var _a;
|
|
36
|
+
if (isWindow(el))
|
|
37
|
+
return el.document;
|
|
38
|
+
if (isDocument(el))
|
|
39
|
+
return el;
|
|
40
|
+
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
41
|
+
}
|
|
42
|
+
function defineDomHelpers(helpers) {
|
|
43
|
+
const dom2 = {
|
|
44
|
+
getRootNode: (ctx) => {
|
|
45
|
+
var _a, _b;
|
|
46
|
+
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
47
|
+
},
|
|
48
|
+
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
49
|
+
getWin: (ctx) => {
|
|
50
|
+
var _a;
|
|
51
|
+
return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
|
|
52
|
+
},
|
|
53
|
+
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
54
|
+
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
|
|
55
|
+
createEmitter: (ctx, target) => {
|
|
56
|
+
const win = dom2.getWin(ctx);
|
|
57
|
+
return function emit(evt, detail, options) {
|
|
58
|
+
const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
|
|
59
|
+
const eventName = `zag:${evt}`;
|
|
60
|
+
const init = { bubbles, cancelable, composed, detail };
|
|
61
|
+
const event = new win.CustomEvent(eventName, init);
|
|
62
|
+
target.dispatchEvent(event);
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
createListener: (target) => {
|
|
66
|
+
return function listen(evt, handler) {
|
|
67
|
+
const eventName = `zag:${evt}`;
|
|
68
|
+
const listener = (e) => handler(e);
|
|
69
|
+
target.addEventListener(eventName, listener);
|
|
70
|
+
return () => target.removeEventListener(eventName, listener);
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
return {
|
|
75
|
+
...dom2,
|
|
76
|
+
...helpers
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// ../../utilities/dom/src/nodelist.ts
|
|
81
|
+
function queryAll(root, selector) {
|
|
82
|
+
var _a;
|
|
83
|
+
return Array.from((_a = root == null ? void 0 : root.querySelectorAll(selector)) != null ? _a : []);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// src/radio-group.dom.ts
|
|
87
|
+
var dom = defineDomHelpers({
|
|
88
|
+
getRootId: (ctx) => {
|
|
89
|
+
var _a, _b;
|
|
90
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `radio-group:${ctx.id}`;
|
|
91
|
+
},
|
|
92
|
+
getLabelId: (ctx) => {
|
|
93
|
+
var _a, _b;
|
|
94
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `radio-group:${ctx.id}:label`;
|
|
95
|
+
},
|
|
96
|
+
getRadioId: (ctx, value) => {
|
|
97
|
+
var _a, _b, _c;
|
|
98
|
+
return (_c = (_b = (_a = ctx.ids) == null ? void 0 : _a.radio) == null ? void 0 : _b.call(_a, value)) != null ? _c : `radio-group:${ctx.id}:radio:${value}`;
|
|
99
|
+
},
|
|
100
|
+
getRadioInputId: (ctx, value) => {
|
|
101
|
+
var _a, _b, _c;
|
|
102
|
+
return (_c = (_b = (_a = ctx.ids) == null ? void 0 : _a.radioInput) == null ? void 0 : _b.call(_a, value)) != null ? _c : `radio-group:${ctx.id}:radio:input:${value}`;
|
|
103
|
+
},
|
|
104
|
+
getRadioControlId: (ctx, value) => {
|
|
105
|
+
var _a, _b, _c;
|
|
106
|
+
return (_c = (_b = (_a = ctx.ids) == null ? void 0 : _a.radioControl) == null ? void 0 : _b.call(_a, value)) != null ? _c : `radio-group:${ctx.id}:radio:control:${value}`;
|
|
107
|
+
},
|
|
108
|
+
getRadioLabelId: (ctx, value) => {
|
|
109
|
+
var _a, _b, _c;
|
|
110
|
+
return (_c = (_b = (_a = ctx.ids) == null ? void 0 : _a.radioLabel) == null ? void 0 : _b.call(_a, value)) != null ? _c : `radio-group:${ctx.id}:radio:label:${value}`;
|
|
111
|
+
},
|
|
112
|
+
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
113
|
+
getRadioInputEl: (ctx, value) => dom.getById(ctx, dom.getRadioInputId(ctx, value)),
|
|
114
|
+
getFirstEnabledInputEl: (ctx) => {
|
|
115
|
+
var _a;
|
|
116
|
+
return (_a = dom.getRootEl(ctx)) == null ? void 0 : _a.querySelector("input:not(:disabled)");
|
|
117
|
+
},
|
|
118
|
+
getFirstEnabledAndCheckedInputEl: (ctx) => {
|
|
119
|
+
var _a;
|
|
120
|
+
return (_a = dom.getRootEl(ctx)) == null ? void 0 : _a.querySelector("input:not(:disabled):checked");
|
|
121
|
+
},
|
|
122
|
+
getInputEls: (ctx) => {
|
|
123
|
+
const ownerId = CSS.escape(dom.getRootId(ctx));
|
|
124
|
+
const selector = `input[type=radio][data-ownedby='${ownerId}']:not([disabled])`;
|
|
125
|
+
return queryAll(dom.getRootEl(ctx), selector);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
129
|
+
0 && (module.exports = {
|
|
130
|
+
dom
|
|
131
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as _zag_js_core from '@zag-js/core';
|
|
2
|
+
import { UserDefinedContext, MachineContext, MachineState } from './radio-group.types.js';
|
|
3
|
+
import '@zag-js/types';
|
|
4
|
+
|
|
5
|
+
declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
|
|
6
|
+
|
|
7
|
+
export { machine };
|