@zag-js/radio-group 0.0.0-dev-20230201173935 → 0.0.0-dev-20230201190914
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-CYVZAWTC.mjs +59 -0
- package/dist/{chunk-OUUIV2HJ.mjs → chunk-F57UWPRI.mjs} +4 -4
- package/dist/{chunk-GQM54R75.mjs → chunk-IKSLQ33Q.mjs} +8 -11
- package/dist/{chunk-OIKV2FWN.mjs → chunk-MGLN5L3R.mjs} +0 -0
- package/dist/index.js +23 -59
- package/dist/index.mjs +4 -4
- package/dist/radio-group.anatomy.mjs +1 -1
- package/dist/radio-group.connect.js +15 -47
- package/dist/radio-group.connect.mjs +3 -3
- package/dist/radio-group.dom.js +13 -45
- package/dist/radio-group.dom.mjs +1 -1
- package/dist/radio-group.machine.js +21 -57
- package/dist/radio-group.machine.mjs +2 -2
- package/package.json +7 -7
- package/dist/chunk-ZTD6B547.mjs +0 -92
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// ../../utilities/dom/src/query.ts
|
|
2
|
+
function isDocument(el) {
|
|
3
|
+
return el.nodeType === Node.DOCUMENT_NODE;
|
|
4
|
+
}
|
|
5
|
+
function isWindow(value) {
|
|
6
|
+
return value?.toString() === "[object Window]";
|
|
7
|
+
}
|
|
8
|
+
function getDocument(el) {
|
|
9
|
+
if (isWindow(el))
|
|
10
|
+
return el.document;
|
|
11
|
+
if (isDocument(el))
|
|
12
|
+
return el;
|
|
13
|
+
return el?.ownerDocument ?? document;
|
|
14
|
+
}
|
|
15
|
+
function getWindow(el) {
|
|
16
|
+
return el?.ownerDocument.defaultView ?? window;
|
|
17
|
+
}
|
|
18
|
+
function defineDomHelpers(helpers) {
|
|
19
|
+
const dom2 = {
|
|
20
|
+
getRootNode: (ctx) => ctx.getRootNode?.() ?? document,
|
|
21
|
+
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
22
|
+
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
23
|
+
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
24
|
+
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
...dom2,
|
|
28
|
+
...helpers
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// ../../utilities/dom/src/nodelist.ts
|
|
33
|
+
function queryAll(root, selector) {
|
|
34
|
+
return Array.from(root?.querySelectorAll(selector) ?? []);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/radio-group.dom.ts
|
|
38
|
+
var dom = defineDomHelpers({
|
|
39
|
+
getRootId: (ctx) => ctx.ids?.root ?? `radio-group:${ctx.id}`,
|
|
40
|
+
getLabelId: (ctx) => ctx.ids?.label ?? `radio-group:${ctx.id}:label`,
|
|
41
|
+
getRadioId: (ctx, value) => ctx.ids?.radio?.(value) ?? `radio-group:${ctx.id}:radio:${value}`,
|
|
42
|
+
getRadioInputId: (ctx, value) => ctx.ids?.radioInput?.(value) ?? `radio-group:${ctx.id}:radio:input:${value}`,
|
|
43
|
+
getRadioControlId: (ctx, value) => ctx.ids?.radioControl?.(value) ?? `radio-group:${ctx.id}:radio:control:${value}`,
|
|
44
|
+
getRadioLabelId: (ctx, value) => ctx.ids?.radioLabel?.(value) ?? `radio-group:${ctx.id}:radio:label:${value}`,
|
|
45
|
+
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
46
|
+
getRadioInputEl: (ctx, value) => dom.getById(ctx, dom.getRadioInputId(ctx, value)),
|
|
47
|
+
getFirstEnabledInputEl: (ctx) => dom.getRootEl(ctx)?.querySelector("input:not(:disabled)"),
|
|
48
|
+
getFirstEnabledAndCheckedInputEl: (ctx) => dom.getRootEl(ctx)?.querySelector("input:not(:disabled):checked"),
|
|
49
|
+
getInputEls: (ctx) => {
|
|
50
|
+
const ownerId = CSS.escape(dom.getRootId(ctx));
|
|
51
|
+
const selector = `input[type=radio][data-ownedby='${ownerId}']:not([disabled])`;
|
|
52
|
+
return queryAll(dom.getRootEl(ctx), selector);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
export {
|
|
57
|
+
getWindow,
|
|
58
|
+
dom
|
|
59
|
+
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
parts
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-MGLN5L3R.mjs";
|
|
4
4
|
import {
|
|
5
5
|
dom
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-CYVZAWTC.mjs";
|
|
7
7
|
|
|
8
8
|
// ../../utilities/dom/src/attrs.ts
|
|
9
9
|
var dataAttr = (guard) => {
|
|
@@ -64,7 +64,7 @@ function connect(state, send, normalize) {
|
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
66
|
const firstEnabledInput = dom.getFirstEnabledInputEl(state.context);
|
|
67
|
-
firstEnabledInput
|
|
67
|
+
firstEnabledInput?.focus();
|
|
68
68
|
};
|
|
69
69
|
return {
|
|
70
70
|
value: state.context.value,
|
|
@@ -77,7 +77,7 @@ function connect(state, send, normalize) {
|
|
|
77
77
|
const inputEls = dom.getInputEls(state.context);
|
|
78
78
|
const radioInputIsFocused = inputEls.some((el) => el === focusedElement);
|
|
79
79
|
if (radioInputIsFocused)
|
|
80
|
-
focusedElement
|
|
80
|
+
focusedElement?.blur();
|
|
81
81
|
},
|
|
82
82
|
rootProps: normalize.element({
|
|
83
83
|
...parts.root.attrs,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
dom,
|
|
3
3
|
getWindow
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-CYVZAWTC.mjs";
|
|
5
5
|
|
|
6
6
|
// src/radio-group.machine.ts
|
|
7
7
|
import { createMachine } from "@zag-js/core";
|
|
@@ -38,20 +38,18 @@ function observeAttributes(node, attributes, fn) {
|
|
|
38
38
|
|
|
39
39
|
// ../../utilities/form-utils/src/input-event.ts
|
|
40
40
|
function getDescriptor(el, options) {
|
|
41
|
-
var _a;
|
|
42
41
|
const { type, property = "value" } = options;
|
|
43
42
|
const proto = getWindow(el)[type].prototype;
|
|
44
|
-
return
|
|
43
|
+
return Object.getOwnPropertyDescriptor(proto, property) ?? {};
|
|
45
44
|
}
|
|
46
45
|
function dispatchInputCheckedEvent(el, checked) {
|
|
47
|
-
var _a;
|
|
48
46
|
if (!el)
|
|
49
47
|
return;
|
|
50
48
|
const win = getWindow(el);
|
|
51
49
|
if (!(el instanceof win.HTMLInputElement))
|
|
52
50
|
return;
|
|
53
51
|
const desc = getDescriptor(el, { type: "HTMLInputElement", property: "checked" });
|
|
54
|
-
|
|
52
|
+
desc.set?.call(el, checked);
|
|
55
53
|
const event = new win.Event("click", { bubbles: true });
|
|
56
54
|
el.dispatchEvent(event);
|
|
57
55
|
}
|
|
@@ -70,13 +68,13 @@ function trackFormReset(el, callback) {
|
|
|
70
68
|
if (!el)
|
|
71
69
|
return;
|
|
72
70
|
const form = getClosestForm(el);
|
|
73
|
-
form
|
|
71
|
+
form?.addEventListener("reset", callback, { passive: true });
|
|
74
72
|
return () => {
|
|
75
|
-
form
|
|
73
|
+
form?.removeEventListener("reset", callback);
|
|
76
74
|
};
|
|
77
75
|
}
|
|
78
76
|
function trackFieldsetDisabled(el, callback) {
|
|
79
|
-
const fieldset = el
|
|
77
|
+
const fieldset = el?.closest("fieldset");
|
|
80
78
|
if (!fieldset)
|
|
81
79
|
return;
|
|
82
80
|
callback(fieldset.disabled);
|
|
@@ -94,7 +92,7 @@ function trackFormControl(el, options) {
|
|
|
94
92
|
})
|
|
95
93
|
];
|
|
96
94
|
return () => {
|
|
97
|
-
cleanups.forEach((cleanup) => cleanup
|
|
95
|
+
cleanups.forEach((cleanup) => cleanup?.());
|
|
98
96
|
};
|
|
99
97
|
}
|
|
100
98
|
|
|
@@ -171,8 +169,7 @@ function machine(userContext) {
|
|
|
171
169
|
ctx2.focusedId = evt.value;
|
|
172
170
|
},
|
|
173
171
|
invokeOnChange(ctx2, evt) {
|
|
174
|
-
|
|
175
|
-
(_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, { value: evt.value });
|
|
172
|
+
ctx2.onChange?.({ value: evt.value });
|
|
176
173
|
},
|
|
177
174
|
dispatchChangeEvent(ctx2, evt) {
|
|
178
175
|
if (!evt.manual)
|
|
File without changes
|
package/dist/index.js
CHANGED
|
@@ -64,31 +64,23 @@ function isDocument(el) {
|
|
|
64
64
|
return el.nodeType === Node.DOCUMENT_NODE;
|
|
65
65
|
}
|
|
66
66
|
function isWindow(value) {
|
|
67
|
-
return
|
|
67
|
+
return value?.toString() === "[object Window]";
|
|
68
68
|
}
|
|
69
69
|
function getDocument(el) {
|
|
70
|
-
var _a;
|
|
71
70
|
if (isWindow(el))
|
|
72
71
|
return el.document;
|
|
73
72
|
if (isDocument(el))
|
|
74
73
|
return el;
|
|
75
|
-
return
|
|
74
|
+
return el?.ownerDocument ?? document;
|
|
76
75
|
}
|
|
77
76
|
function getWindow(el) {
|
|
78
|
-
|
|
79
|
-
return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
|
|
77
|
+
return el?.ownerDocument.defaultView ?? window;
|
|
80
78
|
}
|
|
81
79
|
function defineDomHelpers(helpers) {
|
|
82
80
|
const dom2 = {
|
|
83
|
-
getRootNode: (ctx) =>
|
|
84
|
-
var _a, _b;
|
|
85
|
-
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
86
|
-
},
|
|
81
|
+
getRootNode: (ctx) => ctx.getRootNode?.() ?? document,
|
|
87
82
|
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
88
|
-
getWin: (ctx) =>
|
|
89
|
-
var _a;
|
|
90
|
-
return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
|
|
91
|
-
},
|
|
83
|
+
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
92
84
|
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
93
85
|
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
94
86
|
};
|
|
@@ -117,8 +109,7 @@ function observeAttributes(node, attributes, fn) {
|
|
|
117
109
|
|
|
118
110
|
// ../../utilities/dom/src/nodelist.ts
|
|
119
111
|
function queryAll(root, selector) {
|
|
120
|
-
|
|
121
|
-
return Array.from((_a = root == null ? void 0 : root.querySelectorAll(selector)) != null ? _a : []);
|
|
112
|
+
return Array.from(root?.querySelectorAll(selector) ?? []);
|
|
122
113
|
}
|
|
123
114
|
|
|
124
115
|
// ../../utilities/dom/src/visually-hidden.ts
|
|
@@ -137,40 +128,16 @@ var visuallyHiddenStyle = {
|
|
|
137
128
|
|
|
138
129
|
// src/radio-group.dom.ts
|
|
139
130
|
var dom = defineDomHelpers({
|
|
140
|
-
getRootId: (ctx) => {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `radio-group:${ctx.id}:label`;
|
|
147
|
-
},
|
|
148
|
-
getRadioId: (ctx, value) => {
|
|
149
|
-
var _a, _b, _c;
|
|
150
|
-
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}`;
|
|
151
|
-
},
|
|
152
|
-
getRadioInputId: (ctx, value) => {
|
|
153
|
-
var _a, _b, _c;
|
|
154
|
-
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}`;
|
|
155
|
-
},
|
|
156
|
-
getRadioControlId: (ctx, value) => {
|
|
157
|
-
var _a, _b, _c;
|
|
158
|
-
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}`;
|
|
159
|
-
},
|
|
160
|
-
getRadioLabelId: (ctx, value) => {
|
|
161
|
-
var _a, _b, _c;
|
|
162
|
-
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}`;
|
|
163
|
-
},
|
|
131
|
+
getRootId: (ctx) => ctx.ids?.root ?? `radio-group:${ctx.id}`,
|
|
132
|
+
getLabelId: (ctx) => ctx.ids?.label ?? `radio-group:${ctx.id}:label`,
|
|
133
|
+
getRadioId: (ctx, value) => ctx.ids?.radio?.(value) ?? `radio-group:${ctx.id}:radio:${value}`,
|
|
134
|
+
getRadioInputId: (ctx, value) => ctx.ids?.radioInput?.(value) ?? `radio-group:${ctx.id}:radio:input:${value}`,
|
|
135
|
+
getRadioControlId: (ctx, value) => ctx.ids?.radioControl?.(value) ?? `radio-group:${ctx.id}:radio:control:${value}`,
|
|
136
|
+
getRadioLabelId: (ctx, value) => ctx.ids?.radioLabel?.(value) ?? `radio-group:${ctx.id}:radio:label:${value}`,
|
|
164
137
|
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
165
138
|
getRadioInputEl: (ctx, value) => dom.getById(ctx, dom.getRadioInputId(ctx, value)),
|
|
166
|
-
getFirstEnabledInputEl: (ctx) =>
|
|
167
|
-
|
|
168
|
-
return (_a = dom.getRootEl(ctx)) == null ? void 0 : _a.querySelector("input:not(:disabled)");
|
|
169
|
-
},
|
|
170
|
-
getFirstEnabledAndCheckedInputEl: (ctx) => {
|
|
171
|
-
var _a;
|
|
172
|
-
return (_a = dom.getRootEl(ctx)) == null ? void 0 : _a.querySelector("input:not(:disabled):checked");
|
|
173
|
-
},
|
|
139
|
+
getFirstEnabledInputEl: (ctx) => dom.getRootEl(ctx)?.querySelector("input:not(:disabled)"),
|
|
140
|
+
getFirstEnabledAndCheckedInputEl: (ctx) => dom.getRootEl(ctx)?.querySelector("input:not(:disabled):checked"),
|
|
174
141
|
getInputEls: (ctx) => {
|
|
175
142
|
const ownerId = CSS.escape(dom.getRootId(ctx));
|
|
176
143
|
const selector = `input[type=radio][data-ownedby='${ownerId}']:not([disabled])`;
|
|
@@ -215,7 +182,7 @@ function connect(state, send, normalize) {
|
|
|
215
182
|
return;
|
|
216
183
|
}
|
|
217
184
|
const firstEnabledInput = dom.getFirstEnabledInputEl(state.context);
|
|
218
|
-
firstEnabledInput
|
|
185
|
+
firstEnabledInput?.focus();
|
|
219
186
|
};
|
|
220
187
|
return {
|
|
221
188
|
value: state.context.value,
|
|
@@ -228,7 +195,7 @@ function connect(state, send, normalize) {
|
|
|
228
195
|
const inputEls = dom.getInputEls(state.context);
|
|
229
196
|
const radioInputIsFocused = inputEls.some((el) => el === focusedElement);
|
|
230
197
|
if (radioInputIsFocused)
|
|
231
|
-
focusedElement
|
|
198
|
+
focusedElement?.blur();
|
|
232
199
|
},
|
|
233
200
|
rootProps: normalize.element({
|
|
234
201
|
...parts.root.attrs,
|
|
@@ -348,20 +315,18 @@ var import_core = require("@zag-js/core");
|
|
|
348
315
|
|
|
349
316
|
// ../../utilities/form-utils/src/input-event.ts
|
|
350
317
|
function getDescriptor(el, options) {
|
|
351
|
-
var _a;
|
|
352
318
|
const { type, property = "value" } = options;
|
|
353
319
|
const proto = getWindow(el)[type].prototype;
|
|
354
|
-
return
|
|
320
|
+
return Object.getOwnPropertyDescriptor(proto, property) ?? {};
|
|
355
321
|
}
|
|
356
322
|
function dispatchInputCheckedEvent(el, checked) {
|
|
357
|
-
var _a;
|
|
358
323
|
if (!el)
|
|
359
324
|
return;
|
|
360
325
|
const win = getWindow(el);
|
|
361
326
|
if (!(el instanceof win.HTMLInputElement))
|
|
362
327
|
return;
|
|
363
328
|
const desc = getDescriptor(el, { type: "HTMLInputElement", property: "checked" });
|
|
364
|
-
|
|
329
|
+
desc.set?.call(el, checked);
|
|
365
330
|
const event = new win.Event("click", { bubbles: true });
|
|
366
331
|
el.dispatchEvent(event);
|
|
367
332
|
}
|
|
@@ -380,13 +345,13 @@ function trackFormReset(el, callback) {
|
|
|
380
345
|
if (!el)
|
|
381
346
|
return;
|
|
382
347
|
const form = getClosestForm(el);
|
|
383
|
-
form
|
|
348
|
+
form?.addEventListener("reset", callback, { passive: true });
|
|
384
349
|
return () => {
|
|
385
|
-
form
|
|
350
|
+
form?.removeEventListener("reset", callback);
|
|
386
351
|
};
|
|
387
352
|
}
|
|
388
353
|
function trackFieldsetDisabled(el, callback) {
|
|
389
|
-
const fieldset = el
|
|
354
|
+
const fieldset = el?.closest("fieldset");
|
|
390
355
|
if (!fieldset)
|
|
391
356
|
return;
|
|
392
357
|
callback(fieldset.disabled);
|
|
@@ -404,7 +369,7 @@ function trackFormControl(el, options) {
|
|
|
404
369
|
})
|
|
405
370
|
];
|
|
406
371
|
return () => {
|
|
407
|
-
cleanups.forEach((cleanup) => cleanup
|
|
372
|
+
cleanups.forEach((cleanup) => cleanup?.());
|
|
408
373
|
};
|
|
409
374
|
}
|
|
410
375
|
|
|
@@ -481,8 +446,7 @@ function machine(userContext) {
|
|
|
481
446
|
ctx2.focusedId = evt.value;
|
|
482
447
|
},
|
|
483
448
|
invokeOnChange(ctx2, evt) {
|
|
484
|
-
|
|
485
|
-
(_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, { value: evt.value });
|
|
449
|
+
ctx2.onChange?.({ value: evt.value });
|
|
486
450
|
},
|
|
487
451
|
dispatchChangeEvent(ctx2, evt) {
|
|
488
452
|
if (!evt.manual)
|
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
connect
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-F57UWPRI.mjs";
|
|
4
4
|
import {
|
|
5
5
|
anatomy
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-MGLN5L3R.mjs";
|
|
7
7
|
import {
|
|
8
8
|
machine
|
|
9
|
-
} from "./chunk-
|
|
10
|
-
import "./chunk-
|
|
9
|
+
} from "./chunk-IKSLQ33Q.mjs";
|
|
10
|
+
import "./chunk-CYVZAWTC.mjs";
|
|
11
11
|
export {
|
|
12
12
|
anatomy,
|
|
13
13
|
connect,
|
|
@@ -37,27 +37,20 @@ function isDocument(el) {
|
|
|
37
37
|
return el.nodeType === Node.DOCUMENT_NODE;
|
|
38
38
|
}
|
|
39
39
|
function isWindow(value) {
|
|
40
|
-
return
|
|
40
|
+
return value?.toString() === "[object Window]";
|
|
41
41
|
}
|
|
42
42
|
function getDocument(el) {
|
|
43
|
-
var _a;
|
|
44
43
|
if (isWindow(el))
|
|
45
44
|
return el.document;
|
|
46
45
|
if (isDocument(el))
|
|
47
46
|
return el;
|
|
48
|
-
return
|
|
47
|
+
return el?.ownerDocument ?? document;
|
|
49
48
|
}
|
|
50
49
|
function defineDomHelpers(helpers) {
|
|
51
50
|
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
|
-
},
|
|
51
|
+
getRootNode: (ctx) => ctx.getRootNode?.() ?? document,
|
|
56
52
|
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
57
|
-
getWin: (ctx) =>
|
|
58
|
-
var _a;
|
|
59
|
-
return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
|
|
60
|
-
},
|
|
53
|
+
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
61
54
|
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
62
55
|
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
63
56
|
};
|
|
@@ -69,8 +62,7 @@ function defineDomHelpers(helpers) {
|
|
|
69
62
|
|
|
70
63
|
// ../../utilities/dom/src/nodelist.ts
|
|
71
64
|
function queryAll(root, selector) {
|
|
72
|
-
|
|
73
|
-
return Array.from((_a = root == null ? void 0 : root.querySelectorAll(selector)) != null ? _a : []);
|
|
65
|
+
return Array.from(root?.querySelectorAll(selector) ?? []);
|
|
74
66
|
}
|
|
75
67
|
|
|
76
68
|
// ../../utilities/dom/src/visually-hidden.ts
|
|
@@ -101,40 +93,16 @@ var parts = anatomy.build();
|
|
|
101
93
|
|
|
102
94
|
// src/radio-group.dom.ts
|
|
103
95
|
var dom = defineDomHelpers({
|
|
104
|
-
getRootId: (ctx) => {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `radio-group:${ctx.id}:label`;
|
|
111
|
-
},
|
|
112
|
-
getRadioId: (ctx, value) => {
|
|
113
|
-
var _a, _b, _c;
|
|
114
|
-
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}`;
|
|
115
|
-
},
|
|
116
|
-
getRadioInputId: (ctx, value) => {
|
|
117
|
-
var _a, _b, _c;
|
|
118
|
-
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}`;
|
|
119
|
-
},
|
|
120
|
-
getRadioControlId: (ctx, value) => {
|
|
121
|
-
var _a, _b, _c;
|
|
122
|
-
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}`;
|
|
123
|
-
},
|
|
124
|
-
getRadioLabelId: (ctx, value) => {
|
|
125
|
-
var _a, _b, _c;
|
|
126
|
-
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}`;
|
|
127
|
-
},
|
|
96
|
+
getRootId: (ctx) => ctx.ids?.root ?? `radio-group:${ctx.id}`,
|
|
97
|
+
getLabelId: (ctx) => ctx.ids?.label ?? `radio-group:${ctx.id}:label`,
|
|
98
|
+
getRadioId: (ctx, value) => ctx.ids?.radio?.(value) ?? `radio-group:${ctx.id}:radio:${value}`,
|
|
99
|
+
getRadioInputId: (ctx, value) => ctx.ids?.radioInput?.(value) ?? `radio-group:${ctx.id}:radio:input:${value}`,
|
|
100
|
+
getRadioControlId: (ctx, value) => ctx.ids?.radioControl?.(value) ?? `radio-group:${ctx.id}:radio:control:${value}`,
|
|
101
|
+
getRadioLabelId: (ctx, value) => ctx.ids?.radioLabel?.(value) ?? `radio-group:${ctx.id}:radio:label:${value}`,
|
|
128
102
|
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
129
103
|
getRadioInputEl: (ctx, value) => dom.getById(ctx, dom.getRadioInputId(ctx, value)),
|
|
130
|
-
getFirstEnabledInputEl: (ctx) =>
|
|
131
|
-
|
|
132
|
-
return (_a = dom.getRootEl(ctx)) == null ? void 0 : _a.querySelector("input:not(:disabled)");
|
|
133
|
-
},
|
|
134
|
-
getFirstEnabledAndCheckedInputEl: (ctx) => {
|
|
135
|
-
var _a;
|
|
136
|
-
return (_a = dom.getRootEl(ctx)) == null ? void 0 : _a.querySelector("input:not(:disabled):checked");
|
|
137
|
-
},
|
|
104
|
+
getFirstEnabledInputEl: (ctx) => dom.getRootEl(ctx)?.querySelector("input:not(:disabled)"),
|
|
105
|
+
getFirstEnabledAndCheckedInputEl: (ctx) => dom.getRootEl(ctx)?.querySelector("input:not(:disabled):checked"),
|
|
138
106
|
getInputEls: (ctx) => {
|
|
139
107
|
const ownerId = CSS.escape(dom.getRootId(ctx));
|
|
140
108
|
const selector = `input[type=radio][data-ownedby='${ownerId}']:not([disabled])`;
|
|
@@ -179,7 +147,7 @@ function connect(state, send, normalize) {
|
|
|
179
147
|
return;
|
|
180
148
|
}
|
|
181
149
|
const firstEnabledInput = dom.getFirstEnabledInputEl(state.context);
|
|
182
|
-
firstEnabledInput
|
|
150
|
+
firstEnabledInput?.focus();
|
|
183
151
|
};
|
|
184
152
|
return {
|
|
185
153
|
value: state.context.value,
|
|
@@ -192,7 +160,7 @@ function connect(state, send, normalize) {
|
|
|
192
160
|
const inputEls = dom.getInputEls(state.context);
|
|
193
161
|
const radioInputIsFocused = inputEls.some((el) => el === focusedElement);
|
|
194
162
|
if (radioInputIsFocused)
|
|
195
|
-
focusedElement
|
|
163
|
+
focusedElement?.blur();
|
|
196
164
|
},
|
|
197
165
|
rootProps: normalize.element({
|
|
198
166
|
...parts.root.attrs,
|
package/dist/radio-group.dom.js
CHANGED
|
@@ -29,27 +29,20 @@ function isDocument(el) {
|
|
|
29
29
|
return el.nodeType === Node.DOCUMENT_NODE;
|
|
30
30
|
}
|
|
31
31
|
function isWindow(value) {
|
|
32
|
-
return
|
|
32
|
+
return value?.toString() === "[object Window]";
|
|
33
33
|
}
|
|
34
34
|
function getDocument(el) {
|
|
35
|
-
var _a;
|
|
36
35
|
if (isWindow(el))
|
|
37
36
|
return el.document;
|
|
38
37
|
if (isDocument(el))
|
|
39
38
|
return el;
|
|
40
|
-
return
|
|
39
|
+
return el?.ownerDocument ?? document;
|
|
41
40
|
}
|
|
42
41
|
function defineDomHelpers(helpers) {
|
|
43
42
|
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
|
-
},
|
|
43
|
+
getRootNode: (ctx) => ctx.getRootNode?.() ?? document,
|
|
48
44
|
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
49
|
-
getWin: (ctx) =>
|
|
50
|
-
var _a;
|
|
51
|
-
return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
|
|
52
|
-
},
|
|
45
|
+
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
53
46
|
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
54
47
|
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
55
48
|
};
|
|
@@ -61,46 +54,21 @@ function defineDomHelpers(helpers) {
|
|
|
61
54
|
|
|
62
55
|
// ../../utilities/dom/src/nodelist.ts
|
|
63
56
|
function queryAll(root, selector) {
|
|
64
|
-
|
|
65
|
-
return Array.from((_a = root == null ? void 0 : root.querySelectorAll(selector)) != null ? _a : []);
|
|
57
|
+
return Array.from(root?.querySelectorAll(selector) ?? []);
|
|
66
58
|
}
|
|
67
59
|
|
|
68
60
|
// src/radio-group.dom.ts
|
|
69
61
|
var dom = defineDomHelpers({
|
|
70
|
-
getRootId: (ctx) => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `radio-group:${ctx.id}:label`;
|
|
77
|
-
},
|
|
78
|
-
getRadioId: (ctx, value) => {
|
|
79
|
-
var _a, _b, _c;
|
|
80
|
-
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}`;
|
|
81
|
-
},
|
|
82
|
-
getRadioInputId: (ctx, value) => {
|
|
83
|
-
var _a, _b, _c;
|
|
84
|
-
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}`;
|
|
85
|
-
},
|
|
86
|
-
getRadioControlId: (ctx, value) => {
|
|
87
|
-
var _a, _b, _c;
|
|
88
|
-
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}`;
|
|
89
|
-
},
|
|
90
|
-
getRadioLabelId: (ctx, value) => {
|
|
91
|
-
var _a, _b, _c;
|
|
92
|
-
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}`;
|
|
93
|
-
},
|
|
62
|
+
getRootId: (ctx) => ctx.ids?.root ?? `radio-group:${ctx.id}`,
|
|
63
|
+
getLabelId: (ctx) => ctx.ids?.label ?? `radio-group:${ctx.id}:label`,
|
|
64
|
+
getRadioId: (ctx, value) => ctx.ids?.radio?.(value) ?? `radio-group:${ctx.id}:radio:${value}`,
|
|
65
|
+
getRadioInputId: (ctx, value) => ctx.ids?.radioInput?.(value) ?? `radio-group:${ctx.id}:radio:input:${value}`,
|
|
66
|
+
getRadioControlId: (ctx, value) => ctx.ids?.radioControl?.(value) ?? `radio-group:${ctx.id}:radio:control:${value}`,
|
|
67
|
+
getRadioLabelId: (ctx, value) => ctx.ids?.radioLabel?.(value) ?? `radio-group:${ctx.id}:radio:label:${value}`,
|
|
94
68
|
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
95
69
|
getRadioInputEl: (ctx, value) => dom.getById(ctx, dom.getRadioInputId(ctx, value)),
|
|
96
|
-
getFirstEnabledInputEl: (ctx) =>
|
|
97
|
-
|
|
98
|
-
return (_a = dom.getRootEl(ctx)) == null ? void 0 : _a.querySelector("input:not(:disabled)");
|
|
99
|
-
},
|
|
100
|
-
getFirstEnabledAndCheckedInputEl: (ctx) => {
|
|
101
|
-
var _a;
|
|
102
|
-
return (_a = dom.getRootEl(ctx)) == null ? void 0 : _a.querySelector("input:not(:disabled):checked");
|
|
103
|
-
},
|
|
70
|
+
getFirstEnabledInputEl: (ctx) => dom.getRootEl(ctx)?.querySelector("input:not(:disabled)"),
|
|
71
|
+
getFirstEnabledAndCheckedInputEl: (ctx) => dom.getRootEl(ctx)?.querySelector("input:not(:disabled):checked"),
|
|
104
72
|
getInputEls: (ctx) => {
|
|
105
73
|
const ownerId = CSS.escape(dom.getRootId(ctx));
|
|
106
74
|
const selector = `input[type=radio][data-ownedby='${ownerId}']:not([disabled])`;
|
package/dist/radio-group.dom.mjs
CHANGED
|
@@ -43,31 +43,23 @@ function isDocument(el) {
|
|
|
43
43
|
return el.nodeType === Node.DOCUMENT_NODE;
|
|
44
44
|
}
|
|
45
45
|
function isWindow(value) {
|
|
46
|
-
return
|
|
46
|
+
return value?.toString() === "[object Window]";
|
|
47
47
|
}
|
|
48
48
|
function getDocument(el) {
|
|
49
|
-
var _a;
|
|
50
49
|
if (isWindow(el))
|
|
51
50
|
return el.document;
|
|
52
51
|
if (isDocument(el))
|
|
53
52
|
return el;
|
|
54
|
-
return
|
|
53
|
+
return el?.ownerDocument ?? document;
|
|
55
54
|
}
|
|
56
55
|
function getWindow(el) {
|
|
57
|
-
|
|
58
|
-
return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
|
|
56
|
+
return el?.ownerDocument.defaultView ?? window;
|
|
59
57
|
}
|
|
60
58
|
function defineDomHelpers(helpers) {
|
|
61
59
|
const dom2 = {
|
|
62
|
-
getRootNode: (ctx) =>
|
|
63
|
-
var _a, _b;
|
|
64
|
-
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
65
|
-
},
|
|
60
|
+
getRootNode: (ctx) => ctx.getRootNode?.() ?? document,
|
|
66
61
|
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
67
|
-
getWin: (ctx) =>
|
|
68
|
-
var _a;
|
|
69
|
-
return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
|
|
70
|
-
},
|
|
62
|
+
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
71
63
|
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
72
64
|
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
73
65
|
};
|
|
@@ -96,26 +88,23 @@ function observeAttributes(node, attributes, fn) {
|
|
|
96
88
|
|
|
97
89
|
// ../../utilities/dom/src/nodelist.ts
|
|
98
90
|
function queryAll(root, selector) {
|
|
99
|
-
|
|
100
|
-
return Array.from((_a = root == null ? void 0 : root.querySelectorAll(selector)) != null ? _a : []);
|
|
91
|
+
return Array.from(root?.querySelectorAll(selector) ?? []);
|
|
101
92
|
}
|
|
102
93
|
|
|
103
94
|
// ../../utilities/form-utils/src/input-event.ts
|
|
104
95
|
function getDescriptor(el, options) {
|
|
105
|
-
var _a;
|
|
106
96
|
const { type, property = "value" } = options;
|
|
107
97
|
const proto = getWindow(el)[type].prototype;
|
|
108
|
-
return
|
|
98
|
+
return Object.getOwnPropertyDescriptor(proto, property) ?? {};
|
|
109
99
|
}
|
|
110
100
|
function dispatchInputCheckedEvent(el, checked) {
|
|
111
|
-
var _a;
|
|
112
101
|
if (!el)
|
|
113
102
|
return;
|
|
114
103
|
const win = getWindow(el);
|
|
115
104
|
if (!(el instanceof win.HTMLInputElement))
|
|
116
105
|
return;
|
|
117
106
|
const desc = getDescriptor(el, { type: "HTMLInputElement", property: "checked" });
|
|
118
|
-
|
|
107
|
+
desc.set?.call(el, checked);
|
|
119
108
|
const event = new win.Event("click", { bubbles: true });
|
|
120
109
|
el.dispatchEvent(event);
|
|
121
110
|
}
|
|
@@ -134,13 +123,13 @@ function trackFormReset(el, callback) {
|
|
|
134
123
|
if (!el)
|
|
135
124
|
return;
|
|
136
125
|
const form = getClosestForm(el);
|
|
137
|
-
form
|
|
126
|
+
form?.addEventListener("reset", callback, { passive: true });
|
|
138
127
|
return () => {
|
|
139
|
-
form
|
|
128
|
+
form?.removeEventListener("reset", callback);
|
|
140
129
|
};
|
|
141
130
|
}
|
|
142
131
|
function trackFieldsetDisabled(el, callback) {
|
|
143
|
-
const fieldset = el
|
|
132
|
+
const fieldset = el?.closest("fieldset");
|
|
144
133
|
if (!fieldset)
|
|
145
134
|
return;
|
|
146
135
|
callback(fieldset.disabled);
|
|
@@ -158,46 +147,22 @@ function trackFormControl(el, options) {
|
|
|
158
147
|
})
|
|
159
148
|
];
|
|
160
149
|
return () => {
|
|
161
|
-
cleanups.forEach((cleanup) => cleanup
|
|
150
|
+
cleanups.forEach((cleanup) => cleanup?.());
|
|
162
151
|
};
|
|
163
152
|
}
|
|
164
153
|
|
|
165
154
|
// src/radio-group.dom.ts
|
|
166
155
|
var dom = defineDomHelpers({
|
|
167
|
-
getRootId: (ctx) => {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `radio-group:${ctx.id}:label`;
|
|
174
|
-
},
|
|
175
|
-
getRadioId: (ctx, value) => {
|
|
176
|
-
var _a, _b, _c;
|
|
177
|
-
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}`;
|
|
178
|
-
},
|
|
179
|
-
getRadioInputId: (ctx, value) => {
|
|
180
|
-
var _a, _b, _c;
|
|
181
|
-
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}`;
|
|
182
|
-
},
|
|
183
|
-
getRadioControlId: (ctx, value) => {
|
|
184
|
-
var _a, _b, _c;
|
|
185
|
-
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}`;
|
|
186
|
-
},
|
|
187
|
-
getRadioLabelId: (ctx, value) => {
|
|
188
|
-
var _a, _b, _c;
|
|
189
|
-
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}`;
|
|
190
|
-
},
|
|
156
|
+
getRootId: (ctx) => ctx.ids?.root ?? `radio-group:${ctx.id}`,
|
|
157
|
+
getLabelId: (ctx) => ctx.ids?.label ?? `radio-group:${ctx.id}:label`,
|
|
158
|
+
getRadioId: (ctx, value) => ctx.ids?.radio?.(value) ?? `radio-group:${ctx.id}:radio:${value}`,
|
|
159
|
+
getRadioInputId: (ctx, value) => ctx.ids?.radioInput?.(value) ?? `radio-group:${ctx.id}:radio:input:${value}`,
|
|
160
|
+
getRadioControlId: (ctx, value) => ctx.ids?.radioControl?.(value) ?? `radio-group:${ctx.id}:radio:control:${value}`,
|
|
161
|
+
getRadioLabelId: (ctx, value) => ctx.ids?.radioLabel?.(value) ?? `radio-group:${ctx.id}:radio:label:${value}`,
|
|
191
162
|
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
192
163
|
getRadioInputEl: (ctx, value) => dom.getById(ctx, dom.getRadioInputId(ctx, value)),
|
|
193
|
-
getFirstEnabledInputEl: (ctx) =>
|
|
194
|
-
|
|
195
|
-
return (_a = dom.getRootEl(ctx)) == null ? void 0 : _a.querySelector("input:not(:disabled)");
|
|
196
|
-
},
|
|
197
|
-
getFirstEnabledAndCheckedInputEl: (ctx) => {
|
|
198
|
-
var _a;
|
|
199
|
-
return (_a = dom.getRootEl(ctx)) == null ? void 0 : _a.querySelector("input:not(:disabled):checked");
|
|
200
|
-
},
|
|
164
|
+
getFirstEnabledInputEl: (ctx) => dom.getRootEl(ctx)?.querySelector("input:not(:disabled)"),
|
|
165
|
+
getFirstEnabledAndCheckedInputEl: (ctx) => dom.getRootEl(ctx)?.querySelector("input:not(:disabled):checked"),
|
|
201
166
|
getInputEls: (ctx) => {
|
|
202
167
|
const ownerId = CSS.escape(dom.getRootId(ctx));
|
|
203
168
|
const selector = `input[type=radio][data-ownedby='${ownerId}']:not([disabled])`;
|
|
@@ -278,8 +243,7 @@ function machine(userContext) {
|
|
|
278
243
|
ctx2.focusedId = evt.value;
|
|
279
244
|
},
|
|
280
245
|
invokeOnChange(ctx2, evt) {
|
|
281
|
-
|
|
282
|
-
(_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, { value: evt.value });
|
|
246
|
+
ctx2.onChange?.({ value: evt.value });
|
|
283
247
|
},
|
|
284
248
|
dispatchChangeEvent(ctx2, evt) {
|
|
285
249
|
if (!evt.manual)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/radio-group",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20230201190914",
|
|
4
4
|
"description": "Core logic for the radio group widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -27,15 +27,15 @@
|
|
|
27
27
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@zag-js/anatomy": "0.
|
|
31
|
-
"@zag-js/core": "0.0.0-dev-
|
|
32
|
-
"@zag-js/types": "0.0.0-dev-
|
|
30
|
+
"@zag-js/anatomy": "0.0.0-dev-20230201190914",
|
|
31
|
+
"@zag-js/core": "0.0.0-dev-20230201190914",
|
|
32
|
+
"@zag-js/types": "0.0.0-dev-20230201190914"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"clean-package": "2.2.0",
|
|
36
|
-
"@zag-js/dom-utils": "0.0.0-dev-
|
|
37
|
-
"@zag-js/form-utils": "0.
|
|
38
|
-
"@zag-js/utils": "0.
|
|
36
|
+
"@zag-js/dom-utils": "0.0.0-dev-20230201190914",
|
|
37
|
+
"@zag-js/form-utils": "0.0.0-dev-20230201190914",
|
|
38
|
+
"@zag-js/utils": "0.0.0-dev-20230201190914"
|
|
39
39
|
},
|
|
40
40
|
"clean-package": "../../../clean-package.config.json",
|
|
41
41
|
"main": "dist/index.js",
|
package/dist/chunk-ZTD6B547.mjs
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
// ../../utilities/dom/src/query.ts
|
|
2
|
-
function isDocument(el) {
|
|
3
|
-
return el.nodeType === Node.DOCUMENT_NODE;
|
|
4
|
-
}
|
|
5
|
-
function isWindow(value) {
|
|
6
|
-
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
7
|
-
}
|
|
8
|
-
function getDocument(el) {
|
|
9
|
-
var _a;
|
|
10
|
-
if (isWindow(el))
|
|
11
|
-
return el.document;
|
|
12
|
-
if (isDocument(el))
|
|
13
|
-
return el;
|
|
14
|
-
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
15
|
-
}
|
|
16
|
-
function getWindow(el) {
|
|
17
|
-
var _a;
|
|
18
|
-
return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
|
|
19
|
-
}
|
|
20
|
-
function defineDomHelpers(helpers) {
|
|
21
|
-
const dom2 = {
|
|
22
|
-
getRootNode: (ctx) => {
|
|
23
|
-
var _a, _b;
|
|
24
|
-
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
25
|
-
},
|
|
26
|
-
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
27
|
-
getWin: (ctx) => {
|
|
28
|
-
var _a;
|
|
29
|
-
return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
|
|
30
|
-
},
|
|
31
|
-
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
32
|
-
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
33
|
-
};
|
|
34
|
-
return {
|
|
35
|
-
...dom2,
|
|
36
|
-
...helpers
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// ../../utilities/dom/src/nodelist.ts
|
|
41
|
-
function queryAll(root, selector) {
|
|
42
|
-
var _a;
|
|
43
|
-
return Array.from((_a = root == null ? void 0 : root.querySelectorAll(selector)) != null ? _a : []);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// src/radio-group.dom.ts
|
|
47
|
-
var dom = defineDomHelpers({
|
|
48
|
-
getRootId: (ctx) => {
|
|
49
|
-
var _a, _b;
|
|
50
|
-
return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `radio-group:${ctx.id}`;
|
|
51
|
-
},
|
|
52
|
-
getLabelId: (ctx) => {
|
|
53
|
-
var _a, _b;
|
|
54
|
-
return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `radio-group:${ctx.id}:label`;
|
|
55
|
-
},
|
|
56
|
-
getRadioId: (ctx, value) => {
|
|
57
|
-
var _a, _b, _c;
|
|
58
|
-
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}`;
|
|
59
|
-
},
|
|
60
|
-
getRadioInputId: (ctx, value) => {
|
|
61
|
-
var _a, _b, _c;
|
|
62
|
-
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}`;
|
|
63
|
-
},
|
|
64
|
-
getRadioControlId: (ctx, value) => {
|
|
65
|
-
var _a, _b, _c;
|
|
66
|
-
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}`;
|
|
67
|
-
},
|
|
68
|
-
getRadioLabelId: (ctx, value) => {
|
|
69
|
-
var _a, _b, _c;
|
|
70
|
-
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}`;
|
|
71
|
-
},
|
|
72
|
-
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
73
|
-
getRadioInputEl: (ctx, value) => dom.getById(ctx, dom.getRadioInputId(ctx, value)),
|
|
74
|
-
getFirstEnabledInputEl: (ctx) => {
|
|
75
|
-
var _a;
|
|
76
|
-
return (_a = dom.getRootEl(ctx)) == null ? void 0 : _a.querySelector("input:not(:disabled)");
|
|
77
|
-
},
|
|
78
|
-
getFirstEnabledAndCheckedInputEl: (ctx) => {
|
|
79
|
-
var _a;
|
|
80
|
-
return (_a = dom.getRootEl(ctx)) == null ? void 0 : _a.querySelector("input:not(:disabled):checked");
|
|
81
|
-
},
|
|
82
|
-
getInputEls: (ctx) => {
|
|
83
|
-
const ownerId = CSS.escape(dom.getRootId(ctx));
|
|
84
|
-
const selector = `input[type=radio][data-ownedby='${ownerId}']:not([disabled])`;
|
|
85
|
-
return queryAll(dom.getRootEl(ctx), selector);
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
export {
|
|
90
|
-
getWindow,
|
|
91
|
-
dom
|
|
92
|
-
};
|