@destyler/toggle 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.js → index.mjs} +37 -42
- package/package.json +19 -10
- /package/dist/{index.d.ts → index.d.mts} +0 -0
|
@@ -15,8 +15,7 @@ const dom = createScope({
|
|
|
15
15
|
getItemId: (ctx, value) => ctx.ids?.item?.(value) ?? `toggle:${ctx.id}:${value}`,
|
|
16
16
|
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
17
17
|
getElements: (ctx) => {
|
|
18
|
-
const
|
|
19
|
-
const selector = `[data-ownedby='${ownerId}']:not([data-disabled])`;
|
|
18
|
+
const selector = `[data-ownedby='${CSS.escape(dom.getRootId(ctx))}']:not([data-disabled])`;
|
|
20
19
|
return queryAll(dom.getRootEl(ctx), selector);
|
|
21
20
|
},
|
|
22
21
|
getFirstEl: (ctx) => first(dom.getElements(ctx)),
|
|
@@ -67,8 +66,7 @@ function connect(state, send, normalize) {
|
|
|
67
66
|
},
|
|
68
67
|
onFocus(event) {
|
|
69
68
|
if (disabled) return;
|
|
70
|
-
|
|
71
|
-
if (!isSelfTarget(evt) || !!state.context.isClickFocus || state.context.isTabbingBackward) return;
|
|
69
|
+
if (!isSelfTarget(event.nativeEvent || event) || !!state.context.isClickFocus || state.context.isTabbingBackward) return;
|
|
72
70
|
send("ROOT.FOCUS");
|
|
73
71
|
},
|
|
74
72
|
onBlur() {
|
|
@@ -116,7 +114,7 @@ function connect(state, send, normalize) {
|
|
|
116
114
|
if (event.defaultPrevented) return;
|
|
117
115
|
if (!isSelfTarget(event)) return;
|
|
118
116
|
if (itemState.disabled) return;
|
|
119
|
-
const
|
|
117
|
+
const exec = {
|
|
120
118
|
Tab(event$1) {
|
|
121
119
|
const isShiftTab = event$1.shiftKey;
|
|
122
120
|
send({
|
|
@@ -148,8 +146,7 @@ function connect(state, send, normalize) {
|
|
|
148
146
|
if (!rovingFocus) return;
|
|
149
147
|
send("TOGGLE.FOCUS_LAST");
|
|
150
148
|
}
|
|
151
|
-
};
|
|
152
|
-
const exec = keyMap[getEventKey(event)];
|
|
149
|
+
}[getEventKey(event)];
|
|
153
150
|
if (exec) {
|
|
154
151
|
exec(event);
|
|
155
152
|
if (event.key !== "Tab") event.preventDefault();
|
|
@@ -172,7 +169,6 @@ const set = { value(ctx, value) {
|
|
|
172
169
|
invoke.change(ctx);
|
|
173
170
|
} };
|
|
174
171
|
function machine(userContext) {
|
|
175
|
-
const ctx = compact(userContext);
|
|
176
172
|
return createMachine({
|
|
177
173
|
id: "toggle-group",
|
|
178
174
|
initial: "idle",
|
|
@@ -182,13 +178,13 @@ function machine(userContext) {
|
|
|
182
178
|
orientation: "horizontal",
|
|
183
179
|
rovingFocus: true,
|
|
184
180
|
loopFocus: true,
|
|
185
|
-
...
|
|
181
|
+
...compact(userContext),
|
|
186
182
|
focusedId: null,
|
|
187
183
|
isTabbingBackward: false,
|
|
188
184
|
isClickFocus: false,
|
|
189
185
|
isWithinToolbar: false
|
|
190
186
|
},
|
|
191
|
-
computed: { currentLoopFocus: (ctx
|
|
187
|
+
computed: { currentLoopFocus: (ctx) => ctx.loopFocus && !ctx.isWithinToolbar },
|
|
192
188
|
entry: ["checkIfWithinToolbar"],
|
|
193
189
|
on: {
|
|
194
190
|
"VALUE.SET": { actions: ["setValue"] },
|
|
@@ -225,59 +221,58 @@ function machine(userContext) {
|
|
|
225
221
|
}
|
|
226
222
|
}, {
|
|
227
223
|
guards: {
|
|
228
|
-
isClickFocus: (ctx
|
|
229
|
-
isTabbingBackward: (ctx
|
|
224
|
+
isClickFocus: (ctx) => ctx.isClickFocus,
|
|
225
|
+
isTabbingBackward: (ctx) => ctx.isTabbingBackward
|
|
230
226
|
},
|
|
231
227
|
actions: {
|
|
232
|
-
setIsTabbingBackward(ctx
|
|
233
|
-
ctx
|
|
228
|
+
setIsTabbingBackward(ctx) {
|
|
229
|
+
ctx.isTabbingBackward = true;
|
|
234
230
|
},
|
|
235
|
-
clearIsTabbingBackward(ctx
|
|
236
|
-
ctx
|
|
231
|
+
clearIsTabbingBackward(ctx) {
|
|
232
|
+
ctx.isTabbingBackward = false;
|
|
237
233
|
},
|
|
238
|
-
setClickFocus(ctx
|
|
239
|
-
ctx
|
|
234
|
+
setClickFocus(ctx) {
|
|
235
|
+
ctx.isClickFocus = true;
|
|
240
236
|
},
|
|
241
|
-
clearClickFocus(ctx
|
|
242
|
-
ctx
|
|
237
|
+
clearClickFocus(ctx) {
|
|
238
|
+
ctx.isClickFocus = false;
|
|
243
239
|
},
|
|
244
|
-
checkIfWithinToolbar(ctx
|
|
245
|
-
|
|
246
|
-
ctx$1.isWithinToolbar = !!closestToolbar;
|
|
240
|
+
checkIfWithinToolbar(ctx) {
|
|
241
|
+
ctx.isWithinToolbar = !!dom.getRootEl(ctx)?.closest("[role=toolbar]");
|
|
247
242
|
},
|
|
248
|
-
setFocusedId(ctx
|
|
249
|
-
ctx
|
|
243
|
+
setFocusedId(ctx, evt) {
|
|
244
|
+
ctx.focusedId = evt.id;
|
|
250
245
|
},
|
|
251
|
-
clearFocusedId(ctx
|
|
252
|
-
ctx
|
|
246
|
+
clearFocusedId(ctx) {
|
|
247
|
+
ctx.focusedId = null;
|
|
253
248
|
},
|
|
254
|
-
setValue(ctx
|
|
249
|
+
setValue(ctx, evt) {
|
|
255
250
|
if (!evt.value) return;
|
|
256
|
-
let next = Array.from(ctx
|
|
257
|
-
if (ctx
|
|
258
|
-
else next = isEqual(ctx
|
|
259
|
-
set.value(ctx
|
|
251
|
+
let next = Array.from(ctx.value);
|
|
252
|
+
if (ctx.multiple) next = next.includes(evt.value) ? remove(next, evt.value) : add(next, evt.value);
|
|
253
|
+
else next = isEqual(ctx.value, [evt.value]) ? [] : [evt.value];
|
|
254
|
+
set.value(ctx, next);
|
|
260
255
|
},
|
|
261
|
-
focusNextToggle(ctx
|
|
256
|
+
focusNextToggle(ctx) {
|
|
262
257
|
raf(() => {
|
|
263
|
-
if (!ctx
|
|
264
|
-
dom.getNextEl(ctx
|
|
258
|
+
if (!ctx.focusedId) return;
|
|
259
|
+
dom.getNextEl(ctx, ctx.focusedId)?.focus({ preventScroll: true });
|
|
265
260
|
});
|
|
266
261
|
},
|
|
267
|
-
focusPrevToggle(ctx
|
|
262
|
+
focusPrevToggle(ctx) {
|
|
268
263
|
raf(() => {
|
|
269
|
-
if (!ctx
|
|
270
|
-
dom.getPrevEl(ctx
|
|
264
|
+
if (!ctx.focusedId) return;
|
|
265
|
+
dom.getPrevEl(ctx, ctx.focusedId)?.focus({ preventScroll: true });
|
|
271
266
|
});
|
|
272
267
|
},
|
|
273
|
-
focusFirstToggle(ctx
|
|
268
|
+
focusFirstToggle(ctx) {
|
|
274
269
|
raf(() => {
|
|
275
|
-
dom.getFirstEl(ctx
|
|
270
|
+
dom.getFirstEl(ctx)?.focus({ preventScroll: true });
|
|
276
271
|
});
|
|
277
272
|
},
|
|
278
|
-
focusLastToggle(ctx
|
|
273
|
+
focusLastToggle(ctx) {
|
|
279
274
|
raf(() => {
|
|
280
|
-
dom.getLastEl(ctx
|
|
275
|
+
dom.getLastEl(ctx)?.focus({ preventScroll: true });
|
|
281
276
|
});
|
|
282
277
|
}
|
|
283
278
|
}
|
package/package.json
CHANGED
|
@@ -1,26 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@destyler/toggle",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0-beta.5",
|
|
5
5
|
"description": "A two-state button that can be either on or off.",
|
|
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/toggle"
|
|
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/
|
|
23
|
-
"@destyler/
|
|
25
|
+
"@destyler/anatomy": "0.2.0-beta.5",
|
|
26
|
+
"@destyler/types": "0.2.0-beta.5",
|
|
27
|
+
"@destyler/dom": "0.2.0-beta.5",
|
|
28
|
+
"@destyler/utils": "0.2.0-beta.5",
|
|
29
|
+
"@destyler/xstate": "0.2.0-beta.5"
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
24
33
|
},
|
|
25
34
|
"scripts": {
|
|
26
35
|
"clear": "rimraf ./dist",
|
|
File without changes
|