@destyler/checkbox 0.1.0 → 0.2.0-beta.5
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 → index.d.mts} +1 -1
- package/dist/{index.js → index.mjs} +36 -40
- package/package.json +20 -11
|
@@ -156,4 +156,4 @@ declare function machine(userContext: UserDefinedContext): _destyler_xstate0.Mac
|
|
|
156
156
|
declare const props: ("value" | "ids" | "disabled" | "invalid" | "required" | "checked" | "readOnly" | "onCheckedChange" | "name" | "form" | "dir" | "id" | "getRootNode")[];
|
|
157
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
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 };
|
|
159
|
+
export { type MachineApi as Api, type CheckedChangeDetails, type CheckedState, type UserDefinedContext as Context, type ElementIds, type MachineState, type Service, type State, anatomy, connect, machine, props, splitProps };
|
|
@@ -81,8 +81,7 @@ function connect(state, send, normalize) {
|
|
|
81
81
|
});
|
|
82
82
|
},
|
|
83
83
|
onClick(event) {
|
|
84
|
-
|
|
85
|
-
if (target === dom.getHiddenInputEl(state.context)) event.stopPropagation();
|
|
84
|
+
if (getEventTarget(event) === dom.getHiddenInputEl(state.context)) event.stopPropagation();
|
|
86
85
|
}
|
|
87
86
|
});
|
|
88
87
|
},
|
|
@@ -125,12 +124,11 @@ function connect(state, send, normalize) {
|
|
|
125
124
|
"value": state.context.value,
|
|
126
125
|
"style": visuallyHiddenStyle,
|
|
127
126
|
onFocus() {
|
|
128
|
-
const focusVisible$1 = isFocusVisible();
|
|
129
127
|
send({
|
|
130
128
|
type: "CONTEXT.SET",
|
|
131
129
|
context: {
|
|
132
130
|
focused: true,
|
|
133
|
-
focusVisible:
|
|
131
|
+
focusVisible: isFocusVisible()
|
|
134
132
|
}
|
|
135
133
|
});
|
|
136
134
|
},
|
|
@@ -178,7 +176,6 @@ const set = { checked: (ctx, checked) => {
|
|
|
178
176
|
invoke.change(ctx);
|
|
179
177
|
} };
|
|
180
178
|
function machine(userContext) {
|
|
181
|
-
const ctx = compact(userContext);
|
|
182
179
|
return createMachine({
|
|
183
180
|
id: "checkbox",
|
|
184
181
|
initial: "ready",
|
|
@@ -186,7 +183,7 @@ function machine(userContext) {
|
|
|
186
183
|
checked: false,
|
|
187
184
|
value: "on",
|
|
188
185
|
disabled: false,
|
|
189
|
-
...
|
|
186
|
+
...compact(userContext),
|
|
190
187
|
fieldsetDisabled: false,
|
|
191
188
|
focusVisible: false
|
|
192
189
|
},
|
|
@@ -211,33 +208,33 @@ function machine(userContext) {
|
|
|
211
208
|
"CONTEXT.SET": { actions: ["setContext"] }
|
|
212
209
|
},
|
|
213
210
|
computed: {
|
|
214
|
-
isIndeterminate: (ctx
|
|
215
|
-
isChecked: (ctx
|
|
216
|
-
isDisabled: (ctx
|
|
211
|
+
isIndeterminate: (ctx) => isIndeterminate(ctx.checked),
|
|
212
|
+
isChecked: (ctx) => isChecked(ctx.checked),
|
|
213
|
+
isDisabled: (ctx) => !!ctx.disabled || ctx.fieldsetDisabled
|
|
217
214
|
},
|
|
218
215
|
states: { ready: {} }
|
|
219
216
|
}, {
|
|
220
217
|
guards: { isTrusted: (_ctx, evt) => !!evt.isTrusted },
|
|
221
218
|
activities: {
|
|
222
|
-
trackPressEvent(ctx
|
|
223
|
-
if (ctx
|
|
219
|
+
trackPressEvent(ctx) {
|
|
220
|
+
if (ctx.isDisabled) return;
|
|
224
221
|
return trackPress({
|
|
225
|
-
pointerNode: dom.getRootEl(ctx
|
|
226
|
-
keyboardNode: dom.getHiddenInputEl(ctx
|
|
222
|
+
pointerNode: dom.getRootEl(ctx),
|
|
223
|
+
keyboardNode: dom.getHiddenInputEl(ctx),
|
|
227
224
|
isValidKey: (event) => event.key === " ",
|
|
228
|
-
onPress: () => ctx
|
|
229
|
-
onPressStart: () => ctx
|
|
230
|
-
onPressEnd: () => ctx
|
|
225
|
+
onPress: () => ctx.active = false,
|
|
226
|
+
onPressStart: () => ctx.active = true,
|
|
227
|
+
onPressEnd: () => ctx.active = false
|
|
231
228
|
});
|
|
232
229
|
},
|
|
233
|
-
trackFocusVisible(ctx
|
|
234
|
-
if (ctx
|
|
235
|
-
return trackFocusVisible({ root: dom.getRootNode(ctx
|
|
230
|
+
trackFocusVisible(ctx) {
|
|
231
|
+
if (ctx.isDisabled) return;
|
|
232
|
+
return trackFocusVisible({ root: dom.getRootNode(ctx) });
|
|
236
233
|
},
|
|
237
|
-
trackFormControlState(ctx
|
|
238
|
-
return trackFormControl(dom.getHiddenInputEl(ctx
|
|
234
|
+
trackFormControlState(ctx, _evt, { send, initialContext }) {
|
|
235
|
+
return trackFormControl(dom.getHiddenInputEl(ctx), {
|
|
239
236
|
onFieldsetDisabledChange(disabled) {
|
|
240
|
-
ctx
|
|
237
|
+
ctx.fieldsetDisabled = disabled;
|
|
241
238
|
},
|
|
242
239
|
onFormReset() {
|
|
243
240
|
send({
|
|
@@ -249,31 +246,30 @@ function machine(userContext) {
|
|
|
249
246
|
}
|
|
250
247
|
},
|
|
251
248
|
actions: {
|
|
252
|
-
setContext(ctx
|
|
253
|
-
Object.assign(ctx
|
|
249
|
+
setContext(ctx, evt) {
|
|
250
|
+
Object.assign(ctx, evt.context);
|
|
254
251
|
},
|
|
255
|
-
syncInputElement(ctx
|
|
256
|
-
const inputEl = dom.getHiddenInputEl(ctx
|
|
252
|
+
syncInputElement(ctx) {
|
|
253
|
+
const inputEl = dom.getHiddenInputEl(ctx);
|
|
257
254
|
if (!inputEl) return;
|
|
258
|
-
setElementChecked(inputEl, ctx
|
|
259
|
-
inputEl.indeterminate = ctx
|
|
255
|
+
setElementChecked(inputEl, ctx.isChecked);
|
|
256
|
+
inputEl.indeterminate = ctx.isIndeterminate;
|
|
260
257
|
},
|
|
261
|
-
removeFocusIfNeeded(ctx
|
|
262
|
-
if (ctx
|
|
263
|
-
ctx
|
|
264
|
-
ctx
|
|
258
|
+
removeFocusIfNeeded(ctx) {
|
|
259
|
+
if (ctx.disabled && ctx.focused) {
|
|
260
|
+
ctx.focused = false;
|
|
261
|
+
ctx.focusVisible = false;
|
|
265
262
|
}
|
|
266
263
|
},
|
|
267
|
-
setChecked(ctx
|
|
268
|
-
set.checked(ctx
|
|
264
|
+
setChecked(ctx, evt) {
|
|
265
|
+
set.checked(ctx, evt.checked);
|
|
269
266
|
},
|
|
270
|
-
toggleChecked(ctx
|
|
271
|
-
const checked = isIndeterminate(ctx
|
|
272
|
-
set.checked(ctx
|
|
267
|
+
toggleChecked(ctx) {
|
|
268
|
+
const checked = isIndeterminate(ctx.checked) ? true : !ctx.checked;
|
|
269
|
+
set.checked(ctx, checked);
|
|
273
270
|
},
|
|
274
|
-
dispatchChangeEvent(ctx
|
|
275
|
-
|
|
276
|
-
dispatchInputCheckedEvent(inputEl, { checked: isChecked(ctx$1.checked) });
|
|
271
|
+
dispatchChangeEvent(ctx) {
|
|
272
|
+
dispatchInputCheckedEvent(dom.getHiddenInputEl(ctx), { checked: isChecked(ctx.checked) });
|
|
277
273
|
}
|
|
278
274
|
}
|
|
279
275
|
});
|
package/package.json
CHANGED
|
@@ -1,27 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@destyler/checkbox",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0-beta.5",
|
|
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
|
+
"homepage": "https://github.com/destyler/destyler",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/destyler/destyler.git",
|
|
12
|
+
"directory": "packages/components/checkbox"
|
|
13
|
+
},
|
|
8
14
|
"exports": {
|
|
9
|
-
".": "./dist/index.
|
|
15
|
+
".": "./dist/index.mjs"
|
|
10
16
|
},
|
|
11
|
-
"main": "dist/index.
|
|
12
|
-
"module": "dist/index.
|
|
13
|
-
"types": "dist/index.d.
|
|
17
|
+
"main": "dist/index.mjs",
|
|
18
|
+
"module": "dist/index.mjs",
|
|
19
|
+
"types": "dist/index.d.mts",
|
|
14
20
|
"files": [
|
|
15
21
|
"*.d.ts",
|
|
16
22
|
"dist"
|
|
17
23
|
],
|
|
18
24
|
"dependencies": {
|
|
19
|
-
"@destyler/anatomy": "0.
|
|
20
|
-
"@destyler/
|
|
21
|
-
"@destyler/
|
|
22
|
-
"@destyler/utils": "0.
|
|
23
|
-
"@destyler/xstate": "0.
|
|
24
|
-
"@destyler/
|
|
25
|
+
"@destyler/anatomy": "0.2.0-beta.5",
|
|
26
|
+
"@destyler/dom": "0.2.0-beta.5",
|
|
27
|
+
"@destyler/focus-visible": "0.2.0-beta.5",
|
|
28
|
+
"@destyler/utils": "0.2.0-beta.5",
|
|
29
|
+
"@destyler/xstate": "0.2.0-beta.5",
|
|
30
|
+
"@destyler/types": "0.2.0-beta.5"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
25
34
|
},
|
|
26
35
|
"scripts": {
|
|
27
36
|
"clear": "rimraf ./dist",
|