@zag-js/radio-group 2.0.0-next.2 → 2.0.0-next.4
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/index.d.mts +6 -8
- package/dist/index.d.ts +6 -8
- package/dist/index.js +14 -38
- package/dist/index.mjs +2 -7
- package/dist/radio-group.anatomy.d.mts +2 -6
- package/dist/radio-group.anatomy.d.ts +2 -6
- package/dist/radio-group.anatomy.js +8 -40
- package/dist/radio-group.anatomy.mjs +4 -14
- package/dist/radio-group.connect.d.mts +3 -7
- package/dist/radio-group.connect.d.ts +3 -7
- package/dist/radio-group.connect.js +247 -257
- package/dist/radio-group.connect.mjs +242 -221
- package/dist/radio-group.dom.d.mts +26 -29
- package/dist/radio-group.dom.d.ts +26 -29
- package/dist/radio-group.dom.js +47 -85
- package/dist/radio-group.dom.mjs +28 -45
- package/dist/radio-group.machine.d.mts +2 -7
- package/dist/radio-group.machine.d.ts +2 -7
- package/dist/radio-group.machine.js +159 -217
- package/dist/radio-group.machine.mjs +155 -182
- package/dist/radio-group.props.d.mts +5 -10
- package/dist/radio-group.props.d.ts +5 -10
- package/dist/radio-group.props.js +32 -54
- package/dist/radio-group.props.mjs +25 -26
- package/dist/radio-group.types.d.mts +212 -213
- package/dist/radio-group.types.d.ts +212 -213
- package/dist/radio-group.types.js +4 -18
- package/dist/radio-group.types.mjs +1 -0
- package/package.json +8 -8
package/dist/radio-group.dom.js
CHANGED
|
@@ -1,90 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
getFirstEnabledAndCheckedInputEl: () => getFirstEnabledAndCheckedInputEl,
|
|
24
|
-
getFirstEnabledInputEl: () => getFirstEnabledInputEl,
|
|
25
|
-
getIndicatorEl: () => getIndicatorEl,
|
|
26
|
-
getIndicatorId: () => getIndicatorId,
|
|
27
|
-
getInputEls: () => getInputEls,
|
|
28
|
-
getItemControlId: () => getItemControlId,
|
|
29
|
-
getItemHiddenInputEl: () => getItemHiddenInputEl,
|
|
30
|
-
getItemHiddenInputId: () => getItemHiddenInputId,
|
|
31
|
-
getItemId: () => getItemId,
|
|
32
|
-
getItemLabelId: () => getItemLabelId,
|
|
33
|
-
getLabelId: () => getLabelId,
|
|
34
|
-
getOffsetRect: () => getOffsetRect,
|
|
35
|
-
getRadioEl: () => getRadioEl,
|
|
36
|
-
getRectById: () => getRectById,
|
|
37
|
-
getRootEl: () => getRootEl,
|
|
38
|
-
getRootId: () => getRootId
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
39
4
|
});
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
5
|
+
const require_radio_group_anatomy = require("./radio-group.anatomy.js");
|
|
6
|
+
// src/radio-group.dom.ts
|
|
7
|
+
const getRootId = (ctx) => ctx.ids?.root ?? `${ctx.id}`;
|
|
8
|
+
const getLabelId = (ctx) => ctx.ids?.label ?? `${ctx.id}:label`;
|
|
9
|
+
const getItemId = (ctx, value) => ctx.ids?.item?.(value) ?? `${ctx.id}:radio:${value}`;
|
|
10
|
+
const getItemHiddenInputId = (ctx, value) => ctx.ids?.itemHiddenInput?.(value) ?? `${ctx.id}:radio-input:${value}`;
|
|
11
|
+
const getItemControlId = (ctx, value) => ctx.ids?.itemControl?.(value) ?? `${ctx.id}:radio-control:${value}`;
|
|
12
|
+
const getItemLabelId = (ctx, value) => ctx.ids?.itemLabel?.(value) ?? `${ctx.id}:radio-label:${value}`;
|
|
13
|
+
const getIndicatorId = (ctx) => ctx.ids?.indicator ?? `${ctx.id}:indicator`;
|
|
14
|
+
const getRootEl = (ctx) => ctx.query(ctx.selector(require_radio_group_anatomy.parts.root));
|
|
15
|
+
const getItemHiddenInputEl = (ctx, value) => ctx.getById(getItemHiddenInputId(ctx, value));
|
|
16
|
+
const getIndicatorEl = (ctx) => ctx.query(ctx.selector(require_radio_group_anatomy.parts.indicator));
|
|
17
|
+
const getFirstEnabledInputEl = (ctx) => getRootEl(ctx)?.querySelector("input:not(:disabled)");
|
|
18
|
+
const getFirstEnabledAndCheckedInputEl = (ctx) => getRootEl(ctx)?.querySelector("input:not(:disabled):checked");
|
|
19
|
+
const getInputEls = (ctx) => {
|
|
20
|
+
return ctx.queryAll(`${ctx.selector(require_radio_group_anatomy.parts.item)} input[type=radio]`);
|
|
56
21
|
};
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
22
|
+
const getRadioEl = (ctx, value) => {
|
|
23
|
+
if (!value) return;
|
|
24
|
+
return ctx.getById(getItemId(ctx, value));
|
|
60
25
|
};
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
26
|
+
const getOffsetRect = (el) => ({
|
|
27
|
+
x: el?.offsetLeft ?? 0,
|
|
28
|
+
y: el?.offsetTop ?? 0,
|
|
29
|
+
width: el?.offsetWidth ?? 0,
|
|
30
|
+
height: el?.offsetHeight ?? 0
|
|
66
31
|
});
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
32
|
+
const getRectById = (ctx, id) => {
|
|
33
|
+
const radioEl = ctx.getById(getItemId(ctx, id));
|
|
34
|
+
if (!radioEl) return;
|
|
35
|
+
return getOffsetRect(radioEl);
|
|
71
36
|
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
getRootEl,
|
|
89
|
-
getRootId
|
|
90
|
-
});
|
|
37
|
+
exports.getFirstEnabledAndCheckedInputEl = getFirstEnabledAndCheckedInputEl;
|
|
38
|
+
exports.getFirstEnabledInputEl = getFirstEnabledInputEl;
|
|
39
|
+
exports.getIndicatorEl = getIndicatorEl;
|
|
40
|
+
exports.getIndicatorId = getIndicatorId;
|
|
41
|
+
exports.getInputEls = getInputEls;
|
|
42
|
+
exports.getItemControlId = getItemControlId;
|
|
43
|
+
exports.getItemHiddenInputEl = getItemHiddenInputEl;
|
|
44
|
+
exports.getItemHiddenInputId = getItemHiddenInputId;
|
|
45
|
+
exports.getItemId = getItemId;
|
|
46
|
+
exports.getItemLabelId = getItemLabelId;
|
|
47
|
+
exports.getLabelId = getLabelId;
|
|
48
|
+
exports.getOffsetRect = getOffsetRect;
|
|
49
|
+
exports.getRadioEl = getRadioEl;
|
|
50
|
+
exports.getRectById = getRectById;
|
|
51
|
+
exports.getRootEl = getRootEl;
|
|
52
|
+
exports.getRootId = getRootId;
|
package/dist/radio-group.dom.mjs
CHANGED
|
@@ -1,50 +1,33 @@
|
|
|
1
|
-
// src/radio-group.dom.ts
|
|
2
1
|
import { parts } from "./radio-group.anatomy.mjs";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
2
|
+
// src/radio-group.dom.ts
|
|
3
|
+
const getRootId = (ctx) => ctx.ids?.root ?? `${ctx.id}`;
|
|
4
|
+
const getLabelId = (ctx) => ctx.ids?.label ?? `${ctx.id}:label`;
|
|
5
|
+
const getItemId = (ctx, value) => ctx.ids?.item?.(value) ?? `${ctx.id}:radio:${value}`;
|
|
6
|
+
const getItemHiddenInputId = (ctx, value) => ctx.ids?.itemHiddenInput?.(value) ?? `${ctx.id}:radio-input:${value}`;
|
|
7
|
+
const getItemControlId = (ctx, value) => ctx.ids?.itemControl?.(value) ?? `${ctx.id}:radio-control:${value}`;
|
|
8
|
+
const getItemLabelId = (ctx, value) => ctx.ids?.itemLabel?.(value) ?? `${ctx.id}:radio-label:${value}`;
|
|
9
|
+
const getIndicatorId = (ctx) => ctx.ids?.indicator ?? `${ctx.id}:indicator`;
|
|
10
|
+
const getRootEl = (ctx) => ctx.query(ctx.selector(parts.root));
|
|
11
|
+
const getItemHiddenInputEl = (ctx, value) => ctx.getById(getItemHiddenInputId(ctx, value));
|
|
12
|
+
const getIndicatorEl = (ctx) => ctx.query(ctx.selector(parts.indicator));
|
|
13
|
+
const getFirstEnabledInputEl = (ctx) => getRootEl(ctx)?.querySelector("input:not(:disabled)");
|
|
14
|
+
const getFirstEnabledAndCheckedInputEl = (ctx) => getRootEl(ctx)?.querySelector("input:not(:disabled):checked");
|
|
15
|
+
const getInputEls = (ctx) => {
|
|
16
|
+
return ctx.queryAll(`${ctx.selector(parts.item)} input[type=radio]`);
|
|
17
17
|
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
const getRadioEl = (ctx, value) => {
|
|
19
|
+
if (!value) return;
|
|
20
|
+
return ctx.getById(getItemId(ctx, value));
|
|
21
21
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
const getOffsetRect = (el) => ({
|
|
23
|
+
x: el?.offsetLeft ?? 0,
|
|
24
|
+
y: el?.offsetTop ?? 0,
|
|
25
|
+
width: el?.offsetWidth ?? 0,
|
|
26
|
+
height: el?.offsetHeight ?? 0
|
|
27
27
|
});
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
};
|
|
33
|
-
export {
|
|
34
|
-
getFirstEnabledAndCheckedInputEl,
|
|
35
|
-
getFirstEnabledInputEl,
|
|
36
|
-
getIndicatorEl,
|
|
37
|
-
getIndicatorId,
|
|
38
|
-
getInputEls,
|
|
39
|
-
getItemControlId,
|
|
40
|
-
getItemHiddenInputEl,
|
|
41
|
-
getItemHiddenInputId,
|
|
42
|
-
getItemId,
|
|
43
|
-
getItemLabelId,
|
|
44
|
-
getLabelId,
|
|
45
|
-
getOffsetRect,
|
|
46
|
-
getRadioEl,
|
|
47
|
-
getRectById,
|
|
48
|
-
getRootEl,
|
|
49
|
-
getRootId
|
|
28
|
+
const getRectById = (ctx, id) => {
|
|
29
|
+
const radioEl = ctx.getById(getItemId(ctx, id));
|
|
30
|
+
if (!radioEl) return;
|
|
31
|
+
return getOffsetRect(radioEl);
|
|
50
32
|
};
|
|
33
|
+
export { getFirstEnabledAndCheckedInputEl, getFirstEnabledInputEl, getIndicatorEl, getIndicatorId, getInputEls, getItemControlId, getItemHiddenInputEl, getItemHiddenInputId, getItemId, getItemLabelId, getLabelId, getOffsetRect, getRadioEl, getRectById, getRootEl, getRootId };
|
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import '@zag-js/types';
|
|
4
|
-
|
|
5
|
-
declare const machine: _zag_js_core.Machine<RadioGroupSchema>;
|
|
6
|
-
|
|
7
|
-
export { machine };
|
|
1
|
+
import { RadioGroupSchema } from "./radio-group.types.mjs";
|
|
2
|
+
export declare const machine: import("@zag-js/core").Machine<RadioGroupSchema>;
|
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import '@zag-js/types';
|
|
4
|
-
|
|
5
|
-
declare const machine: _zag_js_core.Machine<RadioGroupSchema>;
|
|
6
|
-
|
|
7
|
-
export { machine };
|
|
1
|
+
import { RadioGroupSchema } from "./radio-group.types.js";
|
|
2
|
+
export declare const machine: import("@zag-js/core").Machine<RadioGroupSchema>;
|
|
@@ -1,219 +1,161 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/radio-group.machine.ts
|
|
31
|
-
var radio_group_machine_exports = {};
|
|
32
|
-
__export(radio_group_machine_exports, {
|
|
33
|
-
machine: () => machine
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(radio_group_machine_exports);
|
|
36
|
-
var import_core = require("@zag-js/core");
|
|
37
|
-
var import_dom_query = require("@zag-js/dom-query");
|
|
38
|
-
var import_focus_visible = require("@zag-js/focus-visible");
|
|
39
|
-
var dom = __toESM(require("./radio-group.dom.js"));
|
|
40
|
-
var { not } = (0, import_core.createGuards)();
|
|
41
|
-
var machine = (0, import_core.createMachine)({
|
|
42
|
-
props({ props }) {
|
|
43
|
-
return {
|
|
44
|
-
orientation: "vertical",
|
|
45
|
-
...props
|
|
46
|
-
};
|
|
47
|
-
},
|
|
48
|
-
initialState() {
|
|
49
|
-
return "idle";
|
|
50
|
-
},
|
|
51
|
-
context({ prop, bindable }) {
|
|
52
|
-
return {
|
|
53
|
-
value: bindable(() => ({
|
|
54
|
-
defaultValue: prop("defaultValue"),
|
|
55
|
-
value: prop("value"),
|
|
56
|
-
onChange(value) {
|
|
57
|
-
prop("onValueChange")?.({ value });
|
|
58
|
-
}
|
|
59
|
-
})),
|
|
60
|
-
activeValue: bindable(() => ({
|
|
61
|
-
defaultValue: null
|
|
62
|
-
})),
|
|
63
|
-
focusedValue: bindable(() => ({
|
|
64
|
-
defaultValue: null
|
|
65
|
-
})),
|
|
66
|
-
focusVisibleValue: bindable(() => ({
|
|
67
|
-
defaultValue: null
|
|
68
|
-
})),
|
|
69
|
-
hoveredValue: bindable(() => ({
|
|
70
|
-
defaultValue: null
|
|
71
|
-
})),
|
|
72
|
-
indicatorRect: bindable(() => ({
|
|
73
|
-
defaultValue: null
|
|
74
|
-
})),
|
|
75
|
-
animateIndicator: bindable(() => ({
|
|
76
|
-
defaultValue: false
|
|
77
|
-
})),
|
|
78
|
-
fieldsetDisabled: bindable(() => ({
|
|
79
|
-
defaultValue: false
|
|
80
|
-
})),
|
|
81
|
-
ssr: bindable(() => ({
|
|
82
|
-
defaultValue: true
|
|
83
|
-
}))
|
|
84
|
-
};
|
|
85
|
-
},
|
|
86
|
-
refs() {
|
|
87
|
-
return {
|
|
88
|
-
indicatorCleanup: null,
|
|
89
|
-
focusVisibleValue: null,
|
|
90
|
-
prevValue: null
|
|
91
|
-
};
|
|
92
|
-
},
|
|
93
|
-
computed: {
|
|
94
|
-
isDisabled: ({ prop, context }) => !!prop("disabled") || context.get("fieldsetDisabled")
|
|
95
|
-
},
|
|
96
|
-
entry: ["syncPrevValue", "syncIndicatorRect", "syncSsr"],
|
|
97
|
-
exit: ["cleanupObserver"],
|
|
98
|
-
effects: ["trackFormControlState", "trackFocusVisible"],
|
|
99
|
-
watch({ track, action, context }) {
|
|
100
|
-
track([() => context.get("value")], () => {
|
|
101
|
-
action(["syncIndicatorAnimation", "syncIndicatorRect", "syncInputElements"]);
|
|
102
|
-
});
|
|
103
|
-
},
|
|
104
|
-
on: {
|
|
105
|
-
SET_VALUE: [
|
|
106
|
-
{
|
|
107
|
-
guard: not("isTrusted"),
|
|
108
|
-
actions: ["setValue", "dispatchChangeEvent"]
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
actions: ["setValue"]
|
|
112
|
-
}
|
|
113
|
-
],
|
|
114
|
-
SET_HOVERED: {
|
|
115
|
-
actions: ["setHovered"]
|
|
116
|
-
},
|
|
117
|
-
SET_ACTIVE: {
|
|
118
|
-
actions: ["setActive"]
|
|
119
|
-
},
|
|
120
|
-
SET_FOCUSED: {
|
|
121
|
-
actions: ["setFocused"]
|
|
122
|
-
},
|
|
123
|
-
INDICATOR_TRANSITION_END: {
|
|
124
|
-
actions: ["clearIndicatorAnimation"]
|
|
125
|
-
}
|
|
126
|
-
},
|
|
127
|
-
states: {
|
|
128
|
-
idle: {}
|
|
129
|
-
},
|
|
130
|
-
implementations: {
|
|
131
|
-
guards: {
|
|
132
|
-
isTrusted: ({ event }) => !!event.isTrusted
|
|
133
|
-
},
|
|
134
|
-
effects: {
|
|
135
|
-
trackFormControlState({ context, scope }) {
|
|
136
|
-
return (0, import_dom_query.trackFormControl)(dom.getRootEl(scope), {
|
|
137
|
-
onFieldsetDisabledChange(disabled) {
|
|
138
|
-
context.set("fieldsetDisabled", disabled);
|
|
139
|
-
},
|
|
140
|
-
onFormReset() {
|
|
141
|
-
context.set("value", context.initial("value"));
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
},
|
|
145
|
-
trackFocusVisible({ scope }) {
|
|
146
|
-
return (0, import_focus_visible.trackFocusVisible)({ root: scope.getRootNode?.() });
|
|
147
|
-
}
|
|
148
|
-
},
|
|
149
|
-
actions: {
|
|
150
|
-
setValue({ context, event }) {
|
|
151
|
-
context.set("value", event.value);
|
|
152
|
-
},
|
|
153
|
-
setHovered({ context, event }) {
|
|
154
|
-
context.set("hoveredValue", event.value);
|
|
155
|
-
},
|
|
156
|
-
setActive({ context, event }) {
|
|
157
|
-
context.set("activeValue", event.value);
|
|
158
|
-
},
|
|
159
|
-
setFocused({ context, event }) {
|
|
160
|
-
context.set("focusedValue", event.value);
|
|
161
|
-
const focusVisibleValue = event.value != null && event.focusVisible ? event.value : null;
|
|
162
|
-
context.set("focusVisibleValue", focusVisibleValue);
|
|
163
|
-
},
|
|
164
|
-
syncPrevValue({ context, refs }) {
|
|
165
|
-
refs.set("prevValue", context.get("value"));
|
|
166
|
-
},
|
|
167
|
-
syncIndicatorAnimation({ context, refs }) {
|
|
168
|
-
const prevValue = refs.get("prevValue");
|
|
169
|
-
const nextValue = context.get("value");
|
|
170
|
-
const animate = prevValue != null && nextValue != null && prevValue !== nextValue;
|
|
171
|
-
context.set("animateIndicator", animate);
|
|
172
|
-
refs.set("prevValue", nextValue);
|
|
173
|
-
},
|
|
174
|
-
clearIndicatorAnimation({ context }) {
|
|
175
|
-
context.set("animateIndicator", false);
|
|
176
|
-
},
|
|
177
|
-
syncInputElements({ context, scope }) {
|
|
178
|
-
const inputs = dom.getInputEls(scope);
|
|
179
|
-
inputs.forEach((input) => {
|
|
180
|
-
input.checked = input.value === context.get("value");
|
|
181
|
-
});
|
|
182
|
-
},
|
|
183
|
-
cleanupObserver({ refs }) {
|
|
184
|
-
refs.get("indicatorCleanup")?.();
|
|
185
|
-
},
|
|
186
|
-
syncSsr({ context }) {
|
|
187
|
-
context.set("ssr", false);
|
|
188
|
-
},
|
|
189
|
-
syncIndicatorRect({ context, scope, refs }) {
|
|
190
|
-
refs.get("indicatorCleanup")?.();
|
|
191
|
-
if (!dom.getIndicatorEl(scope)) return;
|
|
192
|
-
const value = context.get("value");
|
|
193
|
-
const radioEl = dom.getRadioEl(scope, value);
|
|
194
|
-
if (value == null || !radioEl) {
|
|
195
|
-
context.set("indicatorRect", null);
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
const exec = () => {
|
|
199
|
-
context.set("indicatorRect", dom.getOffsetRect(radioEl));
|
|
200
|
-
};
|
|
201
|
-
exec();
|
|
202
|
-
const indicatorCleanup = import_dom_query.resizeObserverBorderBox.observe(radioEl, exec);
|
|
203
|
-
refs.set("indicatorCleanup", indicatorCleanup);
|
|
204
|
-
},
|
|
205
|
-
dispatchChangeEvent({ context, scope }) {
|
|
206
|
-
const inputEls = dom.getInputEls(scope);
|
|
207
|
-
inputEls.forEach((inputEl) => {
|
|
208
|
-
const checked = inputEl.value === context.get("value");
|
|
209
|
-
if (checked === inputEl.checked) return;
|
|
210
|
-
(0, import_dom_query.dispatchInputCheckedEvent)(inputEl, { checked });
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
215
4
|
});
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
5
|
+
const require_radio_group_dom = require("./radio-group.dom.js");
|
|
6
|
+
let _zag_js_dom_query = require("@zag-js/dom-query");
|
|
7
|
+
let _zag_js_focus_visible = require("@zag-js/focus-visible");
|
|
8
|
+
let _zag_js_utils = require("@zag-js/utils");
|
|
9
|
+
let _zag_js_core = require("@zag-js/core");
|
|
10
|
+
// src/radio-group.machine.ts
|
|
11
|
+
const { not } = (0, _zag_js_core.createGuards)();
|
|
12
|
+
const machine = (0, _zag_js_core.createMachine)({
|
|
13
|
+
props({ props }) {
|
|
14
|
+
return {
|
|
15
|
+
orientation: "vertical",
|
|
16
|
+
...props
|
|
17
|
+
};
|
|
18
|
+
},
|
|
19
|
+
initialState() {
|
|
20
|
+
return "idle";
|
|
21
|
+
},
|
|
22
|
+
context({ prop, bindable }) {
|
|
23
|
+
return {
|
|
24
|
+
value: bindable(() => ({
|
|
25
|
+
defaultValue: prop("defaultValue"),
|
|
26
|
+
value: prop("value"),
|
|
27
|
+
onChange(value) {
|
|
28
|
+
prop("onValueChange")?.({ value });
|
|
29
|
+
}
|
|
30
|
+
})),
|
|
31
|
+
activeValue: bindable(() => ({ defaultValue: null })),
|
|
32
|
+
focusedValue: bindable(() => ({ defaultValue: null })),
|
|
33
|
+
focusVisibleValue: bindable(() => ({ defaultValue: null })),
|
|
34
|
+
hoveredValue: bindable(() => ({ defaultValue: null })),
|
|
35
|
+
indicatorRect: bindable(() => ({ defaultValue: null })),
|
|
36
|
+
indicatorInstant: bindable(() => ({ defaultValue: false })),
|
|
37
|
+
fieldsetDisabled: bindable(() => ({ defaultValue: false })),
|
|
38
|
+
ssr: bindable(() => ({ defaultValue: true }))
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
refs() {
|
|
42
|
+
return {
|
|
43
|
+
indicatorCleanup: null,
|
|
44
|
+
indicatorFrame: _zag_js_dom_query.AnimationFrame.create(),
|
|
45
|
+
focusVisibleValue: null
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
computed: { isDisabled: ({ prop, context }) => !!prop("disabled") || context.get("fieldsetDisabled") },
|
|
49
|
+
entry: ["syncIndicatorRect", "syncSsr"],
|
|
50
|
+
exit: ["cleanupObserver", "cancelIndicatorFrame"],
|
|
51
|
+
effects: ["trackFormControlState", "trackFocusVisible"],
|
|
52
|
+
watch({ track, action, context }) {
|
|
53
|
+
track([() => context.get("value")], () => {
|
|
54
|
+
action(["syncIndicatorRect", "syncInputElements"]);
|
|
55
|
+
});
|
|
56
|
+
},
|
|
57
|
+
on: {
|
|
58
|
+
SET_VALUE: [{
|
|
59
|
+
guard: not("isTrusted"),
|
|
60
|
+
actions: ["setValue", "dispatchChangeEvent"]
|
|
61
|
+
}, { actions: ["setValue"] }],
|
|
62
|
+
SET_HOVERED: { actions: ["setHovered"] },
|
|
63
|
+
SET_ACTIVE: { actions: ["setActive"] },
|
|
64
|
+
SET_FOCUSED: { actions: ["setFocused"] },
|
|
65
|
+
INDICATOR_RESIZE: [{
|
|
66
|
+
guard: "isIndicatorTransitioning",
|
|
67
|
+
actions: ["setResizedIndicatorRect"]
|
|
68
|
+
}, { actions: ["snapIndicator", "setResizedIndicatorRect"] }]
|
|
69
|
+
},
|
|
70
|
+
states: { idle: {} },
|
|
71
|
+
implementations: {
|
|
72
|
+
guards: {
|
|
73
|
+
isTrusted: ({ event }) => !!event.isTrusted,
|
|
74
|
+
isIndicatorTransitioning: ({ event }) => !!event.transitioning
|
|
75
|
+
},
|
|
76
|
+
effects: {
|
|
77
|
+
trackFormControlState({ context, scope }) {
|
|
78
|
+
return (0, _zag_js_dom_query.trackFormControl)(require_radio_group_dom.getRootEl(scope), {
|
|
79
|
+
onFieldsetDisabledChange(disabled) {
|
|
80
|
+
context.set("fieldsetDisabled", disabled);
|
|
81
|
+
},
|
|
82
|
+
onFormReset() {
|
|
83
|
+
context.set("value", context.initial("value"));
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
trackFocusVisible({ scope }) {
|
|
88
|
+
return (0, _zag_js_focus_visible.trackFocusVisible)({ root: scope.getRootNode?.() });
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
actions: {
|
|
92
|
+
setValue({ context, event }) {
|
|
93
|
+
context.set("value", event.value);
|
|
94
|
+
},
|
|
95
|
+
setHovered({ context, event }) {
|
|
96
|
+
context.set("hoveredValue", event.value);
|
|
97
|
+
},
|
|
98
|
+
setActive({ context, event }) {
|
|
99
|
+
context.set("activeValue", event.value);
|
|
100
|
+
},
|
|
101
|
+
setFocused({ context, event }) {
|
|
102
|
+
context.set("focusedValue", event.value);
|
|
103
|
+
const focusVisibleValue = event.value != null && event.focusVisible ? event.value : null;
|
|
104
|
+
context.set("focusVisibleValue", focusVisibleValue);
|
|
105
|
+
},
|
|
106
|
+
snapIndicator({ context, refs }) {
|
|
107
|
+
const frame = refs.get("indicatorFrame");
|
|
108
|
+
context.set("indicatorInstant", true);
|
|
109
|
+
frame.request(() => frame.request(() => context.set("indicatorInstant", false)));
|
|
110
|
+
},
|
|
111
|
+
cancelIndicatorFrame({ refs }) {
|
|
112
|
+
refs.get("indicatorFrame").cancel();
|
|
113
|
+
},
|
|
114
|
+
syncInputElements({ context, scope }) {
|
|
115
|
+
require_radio_group_dom.getInputEls(scope).forEach((input) => {
|
|
116
|
+
input.checked = input.value === context.get("value");
|
|
117
|
+
});
|
|
118
|
+
},
|
|
119
|
+
cleanupObserver({ refs }) {
|
|
120
|
+
refs.get("indicatorCleanup")?.();
|
|
121
|
+
},
|
|
122
|
+
syncSsr({ context }) {
|
|
123
|
+
context.set("ssr", false);
|
|
124
|
+
},
|
|
125
|
+
setResizedIndicatorRect({ context, event }) {
|
|
126
|
+
context.set("indicatorRect", event.rect);
|
|
127
|
+
},
|
|
128
|
+
syncIndicatorRect({ context, scope, refs, send }) {
|
|
129
|
+
refs.get("indicatorCleanup")?.();
|
|
130
|
+
const indicatorEl = require_radio_group_dom.getIndicatorEl(scope);
|
|
131
|
+
if (!indicatorEl) return;
|
|
132
|
+
const value = context.get("value");
|
|
133
|
+
const radioEl = require_radio_group_dom.getRadioEl(scope, value);
|
|
134
|
+
if (value == null || !radioEl) {
|
|
135
|
+
context.set("indicatorRect", null);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
context.set("indicatorRect", require_radio_group_dom.getOffsetRect(radioEl));
|
|
139
|
+
const onResize = () => {
|
|
140
|
+
const rect = require_radio_group_dom.getOffsetRect(radioEl);
|
|
141
|
+
if ((0, _zag_js_utils.isEqual)(context.get("indicatorRect"), rect)) return;
|
|
142
|
+
send({
|
|
143
|
+
type: "INDICATOR_RESIZE",
|
|
144
|
+
rect,
|
|
145
|
+
transitioning: indicatorEl.getAnimations?.().length > 0
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
const indicatorCleanup = _zag_js_dom_query.resizeObserverBorderBox.observe(radioEl, onResize);
|
|
149
|
+
refs.set("indicatorCleanup", indicatorCleanup);
|
|
150
|
+
},
|
|
151
|
+
dispatchChangeEvent({ context, scope }) {
|
|
152
|
+
require_radio_group_dom.getInputEls(scope).forEach((inputEl) => {
|
|
153
|
+
const checked = inputEl.value === context.get("value");
|
|
154
|
+
if (checked === inputEl.checked) return;
|
|
155
|
+
(0, _zag_js_dom_query.dispatchInputCheckedEvent)(inputEl, { checked });
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
219
160
|
});
|
|
161
|
+
exports.machine = machine;
|