@destyler/checkbox 0.0.7-beta.7 → 0.0.7-beta.9
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.ts +141 -137
- package/dist/index.js +302 -0
- package/package.json +12 -18
- package/dist/index.cjs +0 -294
- package/dist/index.d.cts +0 -155
- package/dist/index.d.mts +0 -155
- package/dist/index.mjs +0 -288
package/dist/index.d.ts
CHANGED
|
@@ -1,155 +1,159 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
declare const anatomy: _zag_js_anatomy.AnatomyInstance<"root" | "label" | "control" | "indicator">;
|
|
1
|
+
import * as _destyler_anatomy0 from "@destyler/anatomy";
|
|
2
|
+
import * as _destyler_xstate0 from "@destyler/xstate";
|
|
3
|
+
import { AnyEventObject, Machine, XSend, XState } from "@destyler/xstate";
|
|
4
|
+
import { CommonProperties, DirectionProperty, NormalizeProps, PropTypes, RequiredBy } from "@destyler/types";
|
|
7
5
|
|
|
6
|
+
//#region src/anatomy.d.ts
|
|
7
|
+
declare const anatomy: _destyler_anatomy0.AnatomyInstance<"root" | "label" | "control" | "indicator">;
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/types.d.ts
|
|
8
10
|
type CheckedState = boolean | 'indeterminate';
|
|
9
11
|
interface CheckedChangeDetails {
|
|
10
|
-
|
|
12
|
+
checked: CheckedState;
|
|
11
13
|
}
|
|
12
14
|
type ElementIds = Partial<{
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
root: string;
|
|
16
|
+
hiddenInput: string;
|
|
17
|
+
control: string;
|
|
18
|
+
label: string;
|
|
17
19
|
}>;
|
|
18
20
|
interface PublicContext extends DirectionProperty, CommonProperties {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
21
|
+
/**
|
|
22
|
+
* The ids of the elements in the checkbox. Useful for composition.
|
|
23
|
+
*/
|
|
24
|
+
ids?: ElementIds | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Whether the checkbox is disabled
|
|
27
|
+
*/
|
|
28
|
+
disabled?: boolean | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Whether the checkbox is invalid
|
|
31
|
+
*/
|
|
32
|
+
invalid?: boolean | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Whether the checkbox is required
|
|
35
|
+
*/
|
|
36
|
+
required?: boolean | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* The checked state of the checkbox
|
|
39
|
+
*/
|
|
40
|
+
checked: CheckedState;
|
|
41
|
+
/**
|
|
42
|
+
* Whether the checkbox is read-only
|
|
43
|
+
*/
|
|
44
|
+
readOnly?: boolean | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* The callback invoked when the checked state changes.
|
|
47
|
+
*/
|
|
48
|
+
onCheckedChange?: (details: CheckedChangeDetails) => void;
|
|
49
|
+
/**
|
|
50
|
+
* The name of the input field in a checkbox.
|
|
51
|
+
* Useful for form submission.
|
|
52
|
+
*/
|
|
53
|
+
name?: string | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* The id of the form that the checkbox belongs to.
|
|
56
|
+
*/
|
|
57
|
+
form?: string | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* The value of checkbox input. Useful for form submission.
|
|
60
|
+
* @default "on"
|
|
61
|
+
*/
|
|
62
|
+
value: string;
|
|
61
63
|
}
|
|
62
64
|
type UserDefinedContext = RequiredBy<PublicContext, 'id'>;
|
|
63
65
|
type ComputedContext = Readonly<{
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Whether the checkbox is checked
|
|
68
|
+
*/
|
|
69
|
+
isIndeterminate: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Whether the checkbox is checked
|
|
72
|
+
*/
|
|
73
|
+
isChecked: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Whether the checkbox is disabled
|
|
76
|
+
*/
|
|
77
|
+
isDisabled: boolean;
|
|
76
78
|
}>;
|
|
77
79
|
interface PrivateContext {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
interface MachineContext extends PublicContext, PrivateContext, ComputedContext {
|
|
80
|
+
/**
|
|
81
|
+
* @internal
|
|
82
|
+
* Whether the checkbox is pressed
|
|
83
|
+
*/
|
|
84
|
+
active?: boolean | undefined;
|
|
85
|
+
/**
|
|
86
|
+
* @internal
|
|
87
|
+
* Whether the checkbox has focus
|
|
88
|
+
*/
|
|
89
|
+
focused?: boolean | undefined;
|
|
90
|
+
/**
|
|
91
|
+
* @internal
|
|
92
|
+
* Whether the checkbox is focus visible
|
|
93
|
+
*/
|
|
94
|
+
focusVisible?: boolean | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* @internal
|
|
97
|
+
* Whether the checkbox is hovered
|
|
98
|
+
*/
|
|
99
|
+
hovered?: boolean | undefined;
|
|
100
|
+
/**
|
|
101
|
+
* @internal
|
|
102
|
+
* Whether the checkbox's fieldset is disabled
|
|
103
|
+
*/
|
|
104
|
+
fieldsetDisabled: boolean;
|
|
105
105
|
}
|
|
106
|
+
interface MachineContext extends PublicContext, PrivateContext, ComputedContext {}
|
|
106
107
|
interface MachineState {
|
|
107
|
-
|
|
108
|
+
value: 'ready';
|
|
108
109
|
}
|
|
109
|
-
type State =
|
|
110
|
-
type Send =
|
|
111
|
-
type Service = Machine<MachineContext, MachineState,
|
|
110
|
+
type State = XState<MachineContext, MachineState>;
|
|
111
|
+
type Send = XSend<AnyEventObject>;
|
|
112
|
+
type Service = Machine<MachineContext, MachineState, AnyEventObject>;
|
|
112
113
|
interface MachineApi<T extends PropTypes = PropTypes> {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
114
|
+
/**
|
|
115
|
+
* Whether the checkbox is checked
|
|
116
|
+
*/
|
|
117
|
+
checked: boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Whether the checkbox is disabled
|
|
120
|
+
*/
|
|
121
|
+
disabled: boolean | undefined;
|
|
122
|
+
/**
|
|
123
|
+
* Whether the checkbox is indeterminate
|
|
124
|
+
*/
|
|
125
|
+
indeterminate: boolean;
|
|
126
|
+
/**
|
|
127
|
+
* Whether the checkbox is focused
|
|
128
|
+
*/
|
|
129
|
+
focused: boolean | undefined;
|
|
130
|
+
/**
|
|
131
|
+
* The checked state of the checkbox
|
|
132
|
+
*/
|
|
133
|
+
checkedState: CheckedState;
|
|
134
|
+
/**
|
|
135
|
+
* Function to set the checked state of the checkbox
|
|
136
|
+
*/
|
|
137
|
+
setChecked: (checked: CheckedState) => void;
|
|
138
|
+
/**
|
|
139
|
+
* Function to toggle the checked state of the checkbox
|
|
140
|
+
*/
|
|
141
|
+
toggleChecked: () => void;
|
|
142
|
+
getRootProps: () => T['label'];
|
|
143
|
+
getLabelProps: () => T['element'];
|
|
144
|
+
getControlProps: () => T['element'];
|
|
145
|
+
getHiddenInputProps: () => T['input'];
|
|
146
|
+
getIndicatorProps: () => T['element'];
|
|
146
147
|
}
|
|
147
|
-
|
|
148
|
+
//#endregion
|
|
149
|
+
//#region src/connect.d.ts
|
|
148
150
|
declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
151
|
+
//#endregion
|
|
152
|
+
//#region src/machine.d.ts
|
|
153
|
+
declare function machine(userContext: UserDefinedContext): _destyler_xstate0.Machine<MachineContext, MachineState, _destyler_xstate0.AnyEventObject>;
|
|
154
|
+
//#endregion
|
|
155
|
+
//#region src/props.d.ts
|
|
156
|
+
declare const props: ("value" | "ids" | "disabled" | "invalid" | "required" | "checked" | "readOnly" | "onCheckedChange" | "name" | "form" | "dir" | "id" | "getRootNode")[];
|
|
157
|
+
declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "value" | "ids" | "disabled" | "invalid" | "required" | "checked" | "readOnly" | "onCheckedChange" | "name" | "form" | "dir" | "id" | "getRootNode">];
|
|
158
|
+
//#endregion
|
|
159
|
+
export { type MachineApi as Api, type CheckedChangeDetails, type CheckedState, type UserDefinedContext as Context, type ElementIds, type Service, anatomy, connect, machine, props, splitProps };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import { createAnatomy } from "@destyler/anatomy";
|
|
2
|
+
import { createScope, dataAttr, dispatchInputCheckedEvent, getEventTarget, setElementChecked, trackFormControl, trackPress, visuallyHiddenStyle } from "@destyler/dom";
|
|
3
|
+
import { isFocusVisible, trackFocusVisible } from "@destyler/focus-visible";
|
|
4
|
+
import { compact, createSplitProps, isEqual } from "@destyler/utils";
|
|
5
|
+
import { createMachine, guards } from "@destyler/xstate";
|
|
6
|
+
import { createProps } from "@destyler/types";
|
|
7
|
+
|
|
8
|
+
//#region src/anatomy.ts
|
|
9
|
+
const anatomy = createAnatomy("checkbox").parts("root", "label", "control", "indicator");
|
|
10
|
+
const parts = anatomy.build();
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/dom.ts
|
|
14
|
+
const dom = createScope({
|
|
15
|
+
getRootId: (ctx) => ctx.ids?.root ?? `checkbox:${ctx.id}`,
|
|
16
|
+
getLabelId: (ctx) => ctx.ids?.label ?? `checkbox:${ctx.id}:label`,
|
|
17
|
+
getControlId: (ctx) => ctx.ids?.control ?? `checkbox:${ctx.id}:control`,
|
|
18
|
+
getHiddenInputId: (ctx) => ctx.ids?.hiddenInput ?? `checkbox:${ctx.id}:input`,
|
|
19
|
+
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
20
|
+
getHiddenInputEl: (ctx) => dom.getById(ctx, dom.getHiddenInputId(ctx))
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/connect.ts
|
|
25
|
+
function connect(state, send, normalize) {
|
|
26
|
+
const disabled = state.context.isDisabled;
|
|
27
|
+
const readOnly = state.context.readOnly;
|
|
28
|
+
const focused = !disabled && state.context.focused;
|
|
29
|
+
const focusVisible = !disabled && state.context.focusVisible;
|
|
30
|
+
const checked = state.context.isChecked;
|
|
31
|
+
const indeterminate = state.context.isIndeterminate;
|
|
32
|
+
const dataAttrs = {
|
|
33
|
+
"data-active": dataAttr(state.context.active),
|
|
34
|
+
"data-focus": dataAttr(focused),
|
|
35
|
+
"data-focus-visible": dataAttr(focusVisible),
|
|
36
|
+
"data-readonly": dataAttr(readOnly),
|
|
37
|
+
"data-hover": dataAttr(state.context.hovered),
|
|
38
|
+
"data-disabled": dataAttr(disabled),
|
|
39
|
+
"data-state": indeterminate ? "indeterminate" : state.context.checked ? "checked" : "unchecked",
|
|
40
|
+
"data-invalid": dataAttr(state.context.invalid)
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
checked,
|
|
44
|
+
disabled,
|
|
45
|
+
indeterminate,
|
|
46
|
+
focused,
|
|
47
|
+
checkedState: state.context.checked,
|
|
48
|
+
setChecked(checked$1) {
|
|
49
|
+
send({
|
|
50
|
+
type: "CHECKED.SET",
|
|
51
|
+
checked: checked$1,
|
|
52
|
+
isTrusted: false
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
toggleChecked() {
|
|
56
|
+
send({
|
|
57
|
+
type: "CHECKED.TOGGLE",
|
|
58
|
+
checked,
|
|
59
|
+
isTrusted: false
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
getRootProps() {
|
|
63
|
+
return normalize.label({
|
|
64
|
+
...parts.root.attrs,
|
|
65
|
+
...dataAttrs,
|
|
66
|
+
dir: state.context.dir,
|
|
67
|
+
id: dom.getRootId(state.context),
|
|
68
|
+
htmlFor: dom.getHiddenInputId(state.context),
|
|
69
|
+
onPointerMove() {
|
|
70
|
+
if (disabled) return;
|
|
71
|
+
send({
|
|
72
|
+
type: "CONTEXT.SET",
|
|
73
|
+
context: { hovered: true }
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
|
+
onPointerLeave() {
|
|
77
|
+
if (disabled) return;
|
|
78
|
+
send({
|
|
79
|
+
type: "CONTEXT.SET",
|
|
80
|
+
context: { hovered: false }
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
onClick(event) {
|
|
84
|
+
const target = getEventTarget(event);
|
|
85
|
+
if (target === dom.getHiddenInputEl(state.context)) event.stopPropagation();
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
},
|
|
89
|
+
getLabelProps() {
|
|
90
|
+
return normalize.element({
|
|
91
|
+
...parts.label.attrs,
|
|
92
|
+
...dataAttrs,
|
|
93
|
+
dir: state.context.dir,
|
|
94
|
+
id: dom.getLabelId(state.context)
|
|
95
|
+
});
|
|
96
|
+
},
|
|
97
|
+
getControlProps() {
|
|
98
|
+
return normalize.element({
|
|
99
|
+
...parts.control.attrs,
|
|
100
|
+
...dataAttrs,
|
|
101
|
+
"dir": state.context.dir,
|
|
102
|
+
"id": dom.getControlId(state.context),
|
|
103
|
+
"aria-hidden": true
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
getIndicatorProps() {
|
|
107
|
+
return normalize.element({
|
|
108
|
+
...parts.indicator.attrs,
|
|
109
|
+
...dataAttrs,
|
|
110
|
+
dir: state.context.dir,
|
|
111
|
+
hidden: !indeterminate && !state.context.checked
|
|
112
|
+
});
|
|
113
|
+
},
|
|
114
|
+
getHiddenInputProps() {
|
|
115
|
+
return normalize.input({
|
|
116
|
+
"id": dom.getHiddenInputId(state.context),
|
|
117
|
+
"type": "checkbox",
|
|
118
|
+
"required": state.context.required,
|
|
119
|
+
"defaultChecked": checked,
|
|
120
|
+
"disabled": disabled,
|
|
121
|
+
"aria-labelledby": dom.getLabelId(state.context),
|
|
122
|
+
"aria-invalid": state.context.invalid,
|
|
123
|
+
"name": state.context.name,
|
|
124
|
+
"form": state.context.form,
|
|
125
|
+
"value": state.context.value,
|
|
126
|
+
"style": visuallyHiddenStyle,
|
|
127
|
+
onFocus() {
|
|
128
|
+
const focusVisible$1 = isFocusVisible();
|
|
129
|
+
send({
|
|
130
|
+
type: "CONTEXT.SET",
|
|
131
|
+
context: {
|
|
132
|
+
focused: true,
|
|
133
|
+
focusVisible: focusVisible$1
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
},
|
|
137
|
+
onBlur() {
|
|
138
|
+
send({
|
|
139
|
+
type: "CONTEXT.SET",
|
|
140
|
+
context: {
|
|
141
|
+
focused: false,
|
|
142
|
+
focusVisible: false
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
},
|
|
146
|
+
onClick(event) {
|
|
147
|
+
if (readOnly) {
|
|
148
|
+
event.preventDefault();
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const checked$1 = event.currentTarget.checked;
|
|
152
|
+
send({
|
|
153
|
+
type: "CHECKED.SET",
|
|
154
|
+
checked: checked$1,
|
|
155
|
+
isTrusted: true
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
//#endregion
|
|
164
|
+
//#region src/machine.ts
|
|
165
|
+
const { not } = guards;
|
|
166
|
+
function isIndeterminate(checked) {
|
|
167
|
+
return checked === "indeterminate";
|
|
168
|
+
}
|
|
169
|
+
function isChecked(checked) {
|
|
170
|
+
return isIndeterminate(checked) ? false : !!checked;
|
|
171
|
+
}
|
|
172
|
+
const invoke = { change: (ctx) => {
|
|
173
|
+
ctx.onCheckedChange?.({ checked: ctx.checked });
|
|
174
|
+
} };
|
|
175
|
+
const set = { checked: (ctx, checked) => {
|
|
176
|
+
if (isEqual(ctx.checked, checked)) return;
|
|
177
|
+
ctx.checked = checked;
|
|
178
|
+
invoke.change(ctx);
|
|
179
|
+
} };
|
|
180
|
+
function machine(userContext) {
|
|
181
|
+
const ctx = compact(userContext);
|
|
182
|
+
return createMachine({
|
|
183
|
+
id: "checkbox",
|
|
184
|
+
initial: "ready",
|
|
185
|
+
context: {
|
|
186
|
+
checked: false,
|
|
187
|
+
value: "on",
|
|
188
|
+
disabled: false,
|
|
189
|
+
...ctx,
|
|
190
|
+
fieldsetDisabled: false,
|
|
191
|
+
focusVisible: false
|
|
192
|
+
},
|
|
193
|
+
watch: {
|
|
194
|
+
disabled: "removeFocusIfNeeded",
|
|
195
|
+
checked: "syncInputElement"
|
|
196
|
+
},
|
|
197
|
+
activities: [
|
|
198
|
+
"trackFormControlState",
|
|
199
|
+
"trackPressEvent",
|
|
200
|
+
"trackFocusVisible"
|
|
201
|
+
],
|
|
202
|
+
on: {
|
|
203
|
+
"CHECKED.TOGGLE": [{
|
|
204
|
+
guard: not("isTrusted"),
|
|
205
|
+
actions: ["toggleChecked", "dispatchChangeEvent"]
|
|
206
|
+
}, { actions: ["toggleChecked"] }],
|
|
207
|
+
"CHECKED.SET": [{
|
|
208
|
+
guard: not("isTrusted"),
|
|
209
|
+
actions: ["setChecked", "dispatchChangeEvent"]
|
|
210
|
+
}, { actions: ["setChecked"] }],
|
|
211
|
+
"CONTEXT.SET": { actions: ["setContext"] }
|
|
212
|
+
},
|
|
213
|
+
computed: {
|
|
214
|
+
isIndeterminate: (ctx$1) => isIndeterminate(ctx$1.checked),
|
|
215
|
+
isChecked: (ctx$1) => isChecked(ctx$1.checked),
|
|
216
|
+
isDisabled: (ctx$1) => !!ctx$1.disabled || ctx$1.fieldsetDisabled
|
|
217
|
+
},
|
|
218
|
+
states: { ready: {} }
|
|
219
|
+
}, {
|
|
220
|
+
guards: { isTrusted: (_ctx, evt) => !!evt.isTrusted },
|
|
221
|
+
activities: {
|
|
222
|
+
trackPressEvent(ctx$1) {
|
|
223
|
+
if (ctx$1.isDisabled) return;
|
|
224
|
+
return trackPress({
|
|
225
|
+
pointerNode: dom.getRootEl(ctx$1),
|
|
226
|
+
keyboardNode: dom.getHiddenInputEl(ctx$1),
|
|
227
|
+
isValidKey: (event) => event.key === " ",
|
|
228
|
+
onPress: () => ctx$1.active = false,
|
|
229
|
+
onPressStart: () => ctx$1.active = true,
|
|
230
|
+
onPressEnd: () => ctx$1.active = false
|
|
231
|
+
});
|
|
232
|
+
},
|
|
233
|
+
trackFocusVisible(ctx$1) {
|
|
234
|
+
if (ctx$1.isDisabled) return;
|
|
235
|
+
return trackFocusVisible({ root: dom.getRootNode(ctx$1) });
|
|
236
|
+
},
|
|
237
|
+
trackFormControlState(ctx$1, _evt, { send, initialContext }) {
|
|
238
|
+
return trackFormControl(dom.getHiddenInputEl(ctx$1), {
|
|
239
|
+
onFieldsetDisabledChange(disabled) {
|
|
240
|
+
ctx$1.fieldsetDisabled = disabled;
|
|
241
|
+
},
|
|
242
|
+
onFormReset() {
|
|
243
|
+
send({
|
|
244
|
+
type: "CHECKED.SET",
|
|
245
|
+
checked: !!initialContext.checked
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
actions: {
|
|
252
|
+
setContext(ctx$1, evt) {
|
|
253
|
+
Object.assign(ctx$1, evt.context);
|
|
254
|
+
},
|
|
255
|
+
syncInputElement(ctx$1) {
|
|
256
|
+
const inputEl = dom.getHiddenInputEl(ctx$1);
|
|
257
|
+
if (!inputEl) return;
|
|
258
|
+
setElementChecked(inputEl, ctx$1.isChecked);
|
|
259
|
+
inputEl.indeterminate = ctx$1.isIndeterminate;
|
|
260
|
+
},
|
|
261
|
+
removeFocusIfNeeded(ctx$1) {
|
|
262
|
+
if (ctx$1.disabled && ctx$1.focused) {
|
|
263
|
+
ctx$1.focused = false;
|
|
264
|
+
ctx$1.focusVisible = false;
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
setChecked(ctx$1, evt) {
|
|
268
|
+
set.checked(ctx$1, evt.checked);
|
|
269
|
+
},
|
|
270
|
+
toggleChecked(ctx$1) {
|
|
271
|
+
const checked = isIndeterminate(ctx$1.checked) ? true : !ctx$1.checked;
|
|
272
|
+
set.checked(ctx$1, checked);
|
|
273
|
+
},
|
|
274
|
+
dispatchChangeEvent(ctx$1) {
|
|
275
|
+
const inputEl = dom.getHiddenInputEl(ctx$1);
|
|
276
|
+
dispatchInputCheckedEvent(inputEl, { checked: isChecked(ctx$1.checked) });
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
//#endregion
|
|
283
|
+
//#region src/props.ts
|
|
284
|
+
const props = createProps()([
|
|
285
|
+
"checked",
|
|
286
|
+
"dir",
|
|
287
|
+
"disabled",
|
|
288
|
+
"form",
|
|
289
|
+
"getRootNode",
|
|
290
|
+
"id",
|
|
291
|
+
"ids",
|
|
292
|
+
"invalid",
|
|
293
|
+
"name",
|
|
294
|
+
"onCheckedChange",
|
|
295
|
+
"readOnly",
|
|
296
|
+
"required",
|
|
297
|
+
"value"
|
|
298
|
+
]);
|
|
299
|
+
const splitProps = createSplitProps(props);
|
|
300
|
+
|
|
301
|
+
//#endregion
|
|
302
|
+
export { anatomy, connect, machine, props, splitProps };
|
package/package.json
CHANGED
|
@@ -1,38 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@destyler/checkbox",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.7-beta.
|
|
4
|
+
"version": "0.0.7-beta.9",
|
|
5
5
|
"description": "a control that allows the user to toggle between checked and not checked.",
|
|
6
6
|
"author": "Elone Hoo <elonehoo@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"exports": {
|
|
9
|
-
".":
|
|
10
|
-
"types": "./dist/index.d.mts",
|
|
11
|
-
"default": "./dist/index.mjs"
|
|
12
|
-
},
|
|
13
|
-
"./*": "./*"
|
|
9
|
+
".": "./dist/index.js"
|
|
14
10
|
},
|
|
15
|
-
"main": "dist/index.
|
|
16
|
-
"module": "dist/index.
|
|
11
|
+
"main": "dist/index.js",
|
|
12
|
+
"module": "dist/index.js",
|
|
17
13
|
"types": "dist/index.d.ts",
|
|
18
14
|
"files": [
|
|
19
15
|
"*.d.ts",
|
|
20
16
|
"dist"
|
|
21
17
|
],
|
|
22
18
|
"dependencies": {
|
|
23
|
-
"@
|
|
24
|
-
"@
|
|
25
|
-
"@
|
|
26
|
-
"@
|
|
27
|
-
"@
|
|
28
|
-
"@
|
|
29
|
-
"@zag-js/types": "^0.82.1",
|
|
30
|
-
"@zag-js/utils": "^0.82.1"
|
|
19
|
+
"@destyler/anatomy": "0.0.7-beta.9",
|
|
20
|
+
"@destyler/dom": "0.0.7-beta.9",
|
|
21
|
+
"@destyler/focus-visible": "0.0.7-beta.9",
|
|
22
|
+
"@destyler/types": "0.0.7-beta.9",
|
|
23
|
+
"@destyler/utils": "0.0.7-beta.9",
|
|
24
|
+
"@destyler/xstate": "0.0.7-beta.9"
|
|
31
25
|
},
|
|
32
26
|
"scripts": {
|
|
33
27
|
"clear": "rimraf ./dist",
|
|
34
28
|
"clear:node_modules": "rimraf ./node_modules",
|
|
35
|
-
"build": "pnpm run clear &&
|
|
36
|
-
"
|
|
29
|
+
"build": "pnpm run clear && tsdown",
|
|
30
|
+
"watch": "tsdown --watch"
|
|
37
31
|
}
|
|
38
32
|
}
|