@destyler/toggle 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 +116 -113
- package/dist/index.js +307 -0
- package/package.json +11 -16
- package/dist/index.cjs +0 -349
- package/dist/index.d.cts +0 -136
- package/dist/index.d.mts +0 -136
- package/dist/index.mjs +0 -341
package/dist/index.d.ts
CHANGED
|
@@ -1,136 +1,139 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import { StateMachine, Machine } from '@zag-js/core';
|
|
6
|
-
|
|
7
|
-
declare const anatomy: _zag_js_anatomy.AnatomyInstance<"root" | "item">;
|
|
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, Orientation, PropTypes, RequiredBy } from "@destyler/types";
|
|
8
5
|
|
|
6
|
+
//#region src/anatomy.d.ts
|
|
7
|
+
declare const anatomy: _destyler_anatomy0.AnatomyInstance<"root" | "item">;
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/types.d.ts
|
|
9
10
|
interface ValueChangeDetails {
|
|
10
|
-
|
|
11
|
+
value: string[];
|
|
11
12
|
}
|
|
12
13
|
type ElementIds = Partial<{
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
root: string;
|
|
15
|
+
item: (value: string) => string;
|
|
15
16
|
}>;
|
|
16
17
|
interface PublicContext extends DirectionProperty, CommonProperties {
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
18
|
+
/**
|
|
19
|
+
* The ids of the elements in the toggle. Useful for composition.
|
|
20
|
+
*/
|
|
21
|
+
ids?: ElementIds | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Whether the toggle is disabled.
|
|
24
|
+
*/
|
|
25
|
+
disabled?: boolean | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* The values of the toggles in the group.
|
|
28
|
+
*/
|
|
29
|
+
value: string[];
|
|
30
|
+
/**
|
|
31
|
+
* Function to call when the toggle is clicked.
|
|
32
|
+
*/
|
|
33
|
+
onValueChange?: ((details: ValueChangeDetails) => void) | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Whether to loop focus inside the toggle group.
|
|
36
|
+
* @default true
|
|
37
|
+
*/
|
|
38
|
+
loopFocus: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Whether to use roving tab index to manage focus.
|
|
41
|
+
* @default true
|
|
42
|
+
*/
|
|
43
|
+
rovingFocus?: boolean | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* The orientation of the toggle group.
|
|
46
|
+
* @default "horizontal"
|
|
47
|
+
*/
|
|
48
|
+
orientation: Orientation;
|
|
49
|
+
/**
|
|
50
|
+
* Whether to allow multiple toggles to be selected.
|
|
51
|
+
*/
|
|
52
|
+
multiple?: boolean | undefined;
|
|
52
53
|
}
|
|
53
54
|
type UserDefinedContext = RequiredBy<PublicContext, 'id'>;
|
|
54
55
|
type ComputedContext = Readonly<{
|
|
55
|
-
|
|
56
|
+
currentLoopFocus: boolean;
|
|
56
57
|
}>;
|
|
57
58
|
interface PrivateContext {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
interface MachineContext extends PublicContext, PrivateContext, ComputedContext {
|
|
59
|
+
/**
|
|
60
|
+
* @internal
|
|
61
|
+
* Whether the user is tabbing backward.
|
|
62
|
+
*/
|
|
63
|
+
isTabbingBackward: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* @internal
|
|
66
|
+
* Whether the toggle was focused by a click.
|
|
67
|
+
*/
|
|
68
|
+
isClickFocus: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* @internal
|
|
71
|
+
* The value of the toggle that was focused.
|
|
72
|
+
*/
|
|
73
|
+
focusedId: string | null;
|
|
74
|
+
/**
|
|
75
|
+
* @internal
|
|
76
|
+
* Whether the toggle group is within a toolbar.
|
|
77
|
+
* This is used to determine whether to use roving tab index.
|
|
78
|
+
*/
|
|
79
|
+
isWithinToolbar: boolean;
|
|
81
80
|
}
|
|
81
|
+
interface MachineContext extends PublicContext, PrivateContext, ComputedContext {}
|
|
82
82
|
interface MachineState {
|
|
83
|
-
|
|
83
|
+
value: 'idle' | 'focused';
|
|
84
84
|
}
|
|
85
|
-
type State =
|
|
86
|
-
type Send =
|
|
87
|
-
type Service = Machine<MachineContext, MachineState,
|
|
85
|
+
type State = XState<MachineContext, MachineState>;
|
|
86
|
+
type Send = XSend<AnyEventObject>;
|
|
87
|
+
type Service = Machine<MachineContext, MachineState, AnyEventObject>;
|
|
88
88
|
interface ItemProps {
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
value: string;
|
|
90
|
+
disabled?: boolean | undefined;
|
|
91
91
|
}
|
|
92
92
|
interface ItemState {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
93
|
+
/**
|
|
94
|
+
* The underlying id of the item.
|
|
95
|
+
*/
|
|
96
|
+
id: string;
|
|
97
|
+
/**
|
|
98
|
+
* Whether the toggle item is disabled.
|
|
99
|
+
*/
|
|
100
|
+
disabled: boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Whether the toggle item is pressed.
|
|
103
|
+
*/
|
|
104
|
+
pressed: boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Whether the toggle item is focused.
|
|
107
|
+
*/
|
|
108
|
+
focused: boolean;
|
|
109
109
|
}
|
|
110
110
|
interface MachineApi<T extends PropTypes = PropTypes> {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
111
|
+
/**
|
|
112
|
+
* The value of the toggle group.
|
|
113
|
+
*/
|
|
114
|
+
value: string[];
|
|
115
|
+
/**
|
|
116
|
+
* Function to set the value of the toggle group.
|
|
117
|
+
*/
|
|
118
|
+
setValue: (values: string[]) => void;
|
|
119
|
+
/**
|
|
120
|
+
* Returns the state of the toggle item.
|
|
121
|
+
*/
|
|
122
|
+
getItemState: (props: ItemProps) => ItemState;
|
|
123
|
+
getRootProps: () => T['element'];
|
|
124
|
+
getItemProps: (props: ItemProps) => T['button'];
|
|
125
125
|
}
|
|
126
|
-
|
|
126
|
+
//#endregion
|
|
127
|
+
//#region src/connect.d.ts
|
|
127
128
|
declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
129
|
+
//#endregion
|
|
130
|
+
//#region src/machine.d.ts
|
|
131
|
+
declare function machine(userContext: UserDefinedContext): _destyler_xstate0.Machine<MachineContext, MachineState, _destyler_xstate0.AnyEventObject>;
|
|
132
|
+
//#endregion
|
|
133
|
+
//#region src/props.d.ts
|
|
134
|
+
declare const props: ("value" | "ids" | "disabled" | "onValueChange" | "loopFocus" | "rovingFocus" | "orientation" | "multiple" | "dir" | "id" | "getRootNode")[];
|
|
135
|
+
declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "value" | "ids" | "disabled" | "onValueChange" | "loopFocus" | "rovingFocus" | "orientation" | "multiple" | "dir" | "id" | "getRootNode">];
|
|
133
136
|
declare const itemProps: (keyof ItemProps)[];
|
|
134
137
|
declare const splitItemProps: <Props extends ItemProps>(props: Props) => [ItemProps, Omit<Props, keyof ItemProps>];
|
|
135
|
-
|
|
136
|
-
export { type MachineApi as Api, type UserDefinedContext as Context, type ElementIds, type ItemProps, type ItemState, type Service, type ValueChangeDetails, anatomy, connect, itemProps, machine, props, splitItemProps, splitProps };
|
|
138
|
+
//#endregion
|
|
139
|
+
export { type MachineApi as Api, type UserDefinedContext as Context, type ElementIds, type ItemProps, type ItemState, type Orientation, type Service, type ValueChangeDetails, anatomy, connect, itemProps, machine, props, splitItemProps, splitProps };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import { createAnatomy } from "@destyler/anatomy";
|
|
2
|
+
import { createScope, dataAttr, getEventKey, isSafari, isSelfTarget, nextById, prevById, queryAll, raf } from "@destyler/dom";
|
|
3
|
+
import { add, compact, createSplitProps, first, isEqual, last, remove } from "@destyler/utils";
|
|
4
|
+
import { createMachine, guards } from "@destyler/xstate";
|
|
5
|
+
import { createProps } from "@destyler/types";
|
|
6
|
+
|
|
7
|
+
//#region src/anatomy.ts
|
|
8
|
+
const anatomy = createAnatomy("toggle-group").parts("root", "item");
|
|
9
|
+
const parts = anatomy.build();
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/dom.ts
|
|
13
|
+
const dom = createScope({
|
|
14
|
+
getRootId: (ctx) => ctx.ids?.root ?? `toggle:${ctx.id}`,
|
|
15
|
+
getItemId: (ctx, value) => ctx.ids?.item?.(value) ?? `toggle:${ctx.id}:${value}`,
|
|
16
|
+
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
17
|
+
getElements: (ctx) => {
|
|
18
|
+
const ownerId = CSS.escape(dom.getRootId(ctx));
|
|
19
|
+
const selector = `[data-ownedby='${ownerId}']:not([data-disabled])`;
|
|
20
|
+
return queryAll(dom.getRootEl(ctx), selector);
|
|
21
|
+
},
|
|
22
|
+
getFirstEl: (ctx) => first(dom.getElements(ctx)),
|
|
23
|
+
getLastEl: (ctx) => last(dom.getElements(ctx)),
|
|
24
|
+
getNextEl: (ctx, id) => nextById(dom.getElements(ctx), id, ctx.currentLoopFocus),
|
|
25
|
+
getPrevEl: (ctx, id) => prevById(dom.getElements(ctx), id, ctx.currentLoopFocus)
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/connect.ts
|
|
30
|
+
function connect(state, send, normalize) {
|
|
31
|
+
const value = state.context.value;
|
|
32
|
+
const disabled = state.context.disabled;
|
|
33
|
+
const isSingle = !state.context.multiple;
|
|
34
|
+
const rovingFocus = state.context.rovingFocus;
|
|
35
|
+
const isHorizontal = state.context.orientation === "horizontal";
|
|
36
|
+
function getItemState(props$1) {
|
|
37
|
+
const id = dom.getItemId(state.context, props$1.value);
|
|
38
|
+
return {
|
|
39
|
+
id,
|
|
40
|
+
disabled: Boolean(props$1.disabled || disabled),
|
|
41
|
+
pressed: !!value.includes(props$1.value),
|
|
42
|
+
focused: state.context.focusedId === id
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
value,
|
|
47
|
+
setValue(value$1) {
|
|
48
|
+
send({
|
|
49
|
+
type: "VALUE.SET",
|
|
50
|
+
value: value$1
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
getRootProps() {
|
|
54
|
+
return normalize.element({
|
|
55
|
+
...parts.root.attrs,
|
|
56
|
+
"id": dom.getRootId(state.context),
|
|
57
|
+
"dir": state.context.dir,
|
|
58
|
+
"role": isSingle ? "radiogroup" : "group",
|
|
59
|
+
"tabIndex": state.context.isTabbingBackward ? -1 : 0,
|
|
60
|
+
"data-disabled": dataAttr(disabled),
|
|
61
|
+
"data-orientation": state.context.orientation,
|
|
62
|
+
"data-focus": dataAttr(state.context.focusedId != null),
|
|
63
|
+
"style": { outline: "none" },
|
|
64
|
+
onMouseDown() {
|
|
65
|
+
if (disabled) return;
|
|
66
|
+
send("ROOT.MOUSE_DOWN");
|
|
67
|
+
},
|
|
68
|
+
onFocus(event) {
|
|
69
|
+
if (disabled) return;
|
|
70
|
+
const evt = event.nativeEvent || event;
|
|
71
|
+
if (!isSelfTarget(evt) || !!state.context.isClickFocus || state.context.isTabbingBackward) return;
|
|
72
|
+
send("ROOT.FOCUS");
|
|
73
|
+
},
|
|
74
|
+
onBlur() {
|
|
75
|
+
if (disabled) return;
|
|
76
|
+
send("ROOT.BLUR");
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
getItemState,
|
|
81
|
+
getItemProps(props$1) {
|
|
82
|
+
const itemState = getItemState(props$1);
|
|
83
|
+
const rovingTabIndex = itemState.focused ? 0 : -1;
|
|
84
|
+
return normalize.button({
|
|
85
|
+
...parts.item.attrs,
|
|
86
|
+
"id": itemState.id,
|
|
87
|
+
"type": "button",
|
|
88
|
+
"data-ownedby": dom.getRootId(state.context),
|
|
89
|
+
"data-focus": dataAttr(itemState.focused),
|
|
90
|
+
"disabled": itemState.disabled,
|
|
91
|
+
"tabIndex": rovingFocus ? rovingTabIndex : void 0,
|
|
92
|
+
"role": isSingle ? "radio" : void 0,
|
|
93
|
+
"aria-checked": isSingle ? itemState.pressed : void 0,
|
|
94
|
+
"aria-pressed": isSingle ? void 0 : itemState.pressed,
|
|
95
|
+
"data-disabled": dataAttr(itemState.disabled),
|
|
96
|
+
"data-orientation": state.context.orientation,
|
|
97
|
+
"dir": state.context.dir,
|
|
98
|
+
"data-state": itemState.pressed ? "on" : "off",
|
|
99
|
+
onFocus() {
|
|
100
|
+
if (itemState.disabled) return;
|
|
101
|
+
send({
|
|
102
|
+
type: "TOGGLE.FOCUS",
|
|
103
|
+
id: itemState.id
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
onClick(event) {
|
|
107
|
+
if (itemState.disabled) return;
|
|
108
|
+
send({
|
|
109
|
+
type: "TOGGLE.CLICK",
|
|
110
|
+
id: itemState.id,
|
|
111
|
+
value: props$1.value
|
|
112
|
+
});
|
|
113
|
+
if (isSafari()) event.currentTarget.focus({ preventScroll: true });
|
|
114
|
+
},
|
|
115
|
+
onKeyDown(event) {
|
|
116
|
+
if (event.defaultPrevented) return;
|
|
117
|
+
if (!isSelfTarget(event)) return;
|
|
118
|
+
if (itemState.disabled) return;
|
|
119
|
+
const keyMap = {
|
|
120
|
+
Tab(event$1) {
|
|
121
|
+
const isShiftTab = event$1.shiftKey;
|
|
122
|
+
send({
|
|
123
|
+
type: "TOGGLE.SHIFT_TAB",
|
|
124
|
+
isShiftTab
|
|
125
|
+
});
|
|
126
|
+
},
|
|
127
|
+
ArrowLeft() {
|
|
128
|
+
if (!rovingFocus || !isHorizontal) return;
|
|
129
|
+
send("TOGGLE.FOCUS_PREV");
|
|
130
|
+
},
|
|
131
|
+
ArrowRight() {
|
|
132
|
+
if (!rovingFocus || !isHorizontal) return;
|
|
133
|
+
send("TOGGLE.FOCUS_NEXT");
|
|
134
|
+
},
|
|
135
|
+
ArrowUp() {
|
|
136
|
+
if (!rovingFocus || isHorizontal) return;
|
|
137
|
+
send("TOGGLE.FOCUS_PREV");
|
|
138
|
+
},
|
|
139
|
+
ArrowDown() {
|
|
140
|
+
if (!rovingFocus || isHorizontal) return;
|
|
141
|
+
send("TOGGLE.FOCUS_NEXT");
|
|
142
|
+
},
|
|
143
|
+
Home() {
|
|
144
|
+
if (!rovingFocus) return;
|
|
145
|
+
send("TOGGLE.FOCUS_FIRST");
|
|
146
|
+
},
|
|
147
|
+
End() {
|
|
148
|
+
if (!rovingFocus) return;
|
|
149
|
+
send("TOGGLE.FOCUS_LAST");
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
const exec = keyMap[getEventKey(event)];
|
|
153
|
+
if (exec) {
|
|
154
|
+
exec(event);
|
|
155
|
+
if (event.key !== "Tab") event.preventDefault();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
//#endregion
|
|
164
|
+
//#region src/machine.ts
|
|
165
|
+
const { not, and } = guards;
|
|
166
|
+
const invoke = { change(ctx) {
|
|
167
|
+
ctx.onValueChange?.({ value: Array.from(ctx.value) });
|
|
168
|
+
} };
|
|
169
|
+
const set = { value(ctx, value) {
|
|
170
|
+
if (isEqual(ctx.value, value)) return;
|
|
171
|
+
ctx.value = value;
|
|
172
|
+
invoke.change(ctx);
|
|
173
|
+
} };
|
|
174
|
+
function machine(userContext) {
|
|
175
|
+
const ctx = compact(userContext);
|
|
176
|
+
return createMachine({
|
|
177
|
+
id: "toggle-group",
|
|
178
|
+
initial: "idle",
|
|
179
|
+
context: {
|
|
180
|
+
value: [],
|
|
181
|
+
disabled: false,
|
|
182
|
+
orientation: "horizontal",
|
|
183
|
+
rovingFocus: true,
|
|
184
|
+
loopFocus: true,
|
|
185
|
+
...ctx,
|
|
186
|
+
focusedId: null,
|
|
187
|
+
isTabbingBackward: false,
|
|
188
|
+
isClickFocus: false,
|
|
189
|
+
isWithinToolbar: false
|
|
190
|
+
},
|
|
191
|
+
computed: { currentLoopFocus: (ctx$1) => ctx$1.loopFocus && !ctx$1.isWithinToolbar },
|
|
192
|
+
entry: ["checkIfWithinToolbar"],
|
|
193
|
+
on: {
|
|
194
|
+
"VALUE.SET": { actions: ["setValue"] },
|
|
195
|
+
"TOGGLE.CLICK": { actions: ["setValue"] },
|
|
196
|
+
"ROOT.MOUSE_DOWN": { actions: ["setClickFocus"] }
|
|
197
|
+
},
|
|
198
|
+
states: {
|
|
199
|
+
idle: { on: {
|
|
200
|
+
"ROOT.FOCUS": {
|
|
201
|
+
target: "focused",
|
|
202
|
+
guard: not(and("isClickFocus", "isTabbingBackward")),
|
|
203
|
+
actions: ["focusFirstToggle", "clearClickFocus"]
|
|
204
|
+
},
|
|
205
|
+
"TOGGLE.FOCUS": {
|
|
206
|
+
target: "focused",
|
|
207
|
+
actions: ["setFocusedId"]
|
|
208
|
+
}
|
|
209
|
+
} },
|
|
210
|
+
focused: { on: {
|
|
211
|
+
"ROOT.BLUR": {
|
|
212
|
+
target: "idle",
|
|
213
|
+
actions: ["clearIsTabbingBackward"]
|
|
214
|
+
},
|
|
215
|
+
"TOGGLE.FOCUS": { actions: ["setFocusedId"] },
|
|
216
|
+
"TOGGLE.FOCUS_NEXT": { actions: ["focusNextToggle"] },
|
|
217
|
+
"TOGGLE.FOCUS_PREV": { actions: ["focusPrevToggle"] },
|
|
218
|
+
"TOGGLE.FOCUS_FIRST": { actions: ["focusFirstToggle"] },
|
|
219
|
+
"TOGGLE.FOCUS_LAST": { actions: ["focusLastToggle"] },
|
|
220
|
+
"TOGGLE.SHIFT_TAB": {
|
|
221
|
+
target: "idle",
|
|
222
|
+
actions: ["setIsTabbingBackward"]
|
|
223
|
+
}
|
|
224
|
+
} }
|
|
225
|
+
}
|
|
226
|
+
}, {
|
|
227
|
+
guards: {
|
|
228
|
+
isClickFocus: (ctx$1) => ctx$1.isClickFocus,
|
|
229
|
+
isTabbingBackward: (ctx$1) => ctx$1.isTabbingBackward
|
|
230
|
+
},
|
|
231
|
+
actions: {
|
|
232
|
+
setIsTabbingBackward(ctx$1) {
|
|
233
|
+
ctx$1.isTabbingBackward = true;
|
|
234
|
+
},
|
|
235
|
+
clearIsTabbingBackward(ctx$1) {
|
|
236
|
+
ctx$1.isTabbingBackward = false;
|
|
237
|
+
},
|
|
238
|
+
setClickFocus(ctx$1) {
|
|
239
|
+
ctx$1.isClickFocus = true;
|
|
240
|
+
},
|
|
241
|
+
clearClickFocus(ctx$1) {
|
|
242
|
+
ctx$1.isClickFocus = false;
|
|
243
|
+
},
|
|
244
|
+
checkIfWithinToolbar(ctx$1) {
|
|
245
|
+
const closestToolbar = dom.getRootEl(ctx$1)?.closest("[role=toolbar]");
|
|
246
|
+
ctx$1.isWithinToolbar = !!closestToolbar;
|
|
247
|
+
},
|
|
248
|
+
setFocusedId(ctx$1, evt) {
|
|
249
|
+
ctx$1.focusedId = evt.id;
|
|
250
|
+
},
|
|
251
|
+
clearFocusedId(ctx$1) {
|
|
252
|
+
ctx$1.focusedId = null;
|
|
253
|
+
},
|
|
254
|
+
setValue(ctx$1, evt) {
|
|
255
|
+
if (!evt.value) return;
|
|
256
|
+
let next = Array.from(ctx$1.value);
|
|
257
|
+
if (ctx$1.multiple) next = next.includes(evt.value) ? remove(next, evt.value) : add(next, evt.value);
|
|
258
|
+
else next = isEqual(ctx$1.value, [evt.value]) ? [] : [evt.value];
|
|
259
|
+
set.value(ctx$1, next);
|
|
260
|
+
},
|
|
261
|
+
focusNextToggle(ctx$1) {
|
|
262
|
+
raf(() => {
|
|
263
|
+
if (!ctx$1.focusedId) return;
|
|
264
|
+
dom.getNextEl(ctx$1, ctx$1.focusedId)?.focus({ preventScroll: true });
|
|
265
|
+
});
|
|
266
|
+
},
|
|
267
|
+
focusPrevToggle(ctx$1) {
|
|
268
|
+
raf(() => {
|
|
269
|
+
if (!ctx$1.focusedId) return;
|
|
270
|
+
dom.getPrevEl(ctx$1, ctx$1.focusedId)?.focus({ preventScroll: true });
|
|
271
|
+
});
|
|
272
|
+
},
|
|
273
|
+
focusFirstToggle(ctx$1) {
|
|
274
|
+
raf(() => {
|
|
275
|
+
dom.getFirstEl(ctx$1)?.focus({ preventScroll: true });
|
|
276
|
+
});
|
|
277
|
+
},
|
|
278
|
+
focusLastToggle(ctx$1) {
|
|
279
|
+
raf(() => {
|
|
280
|
+
dom.getLastEl(ctx$1)?.focus({ preventScroll: true });
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
//#endregion
|
|
288
|
+
//#region src/props.ts
|
|
289
|
+
const props = createProps()([
|
|
290
|
+
"dir",
|
|
291
|
+
"disabled",
|
|
292
|
+
"getRootNode",
|
|
293
|
+
"id",
|
|
294
|
+
"ids",
|
|
295
|
+
"loopFocus",
|
|
296
|
+
"multiple",
|
|
297
|
+
"onValueChange",
|
|
298
|
+
"orientation",
|
|
299
|
+
"rovingFocus",
|
|
300
|
+
"value"
|
|
301
|
+
]);
|
|
302
|
+
const splitProps = createSplitProps(props);
|
|
303
|
+
const itemProps = createProps()(["value", "disabled"]);
|
|
304
|
+
const splitItemProps = createSplitProps(itemProps);
|
|
305
|
+
|
|
306
|
+
//#endregion
|
|
307
|
+
export { anatomy, connect, itemProps, machine, props, splitItemProps, splitProps };
|
package/package.json
CHANGED
|
@@ -1,36 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@destyler/toggle",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.7-beta.
|
|
4
|
+
"version": "0.0.7-beta.9",
|
|
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
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
|
-
"@zag-js/utils": "^0.82.1"
|
|
19
|
+
"@destyler/anatomy": "0.0.7-beta.9",
|
|
20
|
+
"@destyler/types": "0.0.7-beta.9",
|
|
21
|
+
"@destyler/dom": "0.0.7-beta.9",
|
|
22
|
+
"@destyler/xstate": "0.0.7-beta.9",
|
|
23
|
+
"@destyler/utils": "0.0.7-beta.9"
|
|
29
24
|
},
|
|
30
25
|
"scripts": {
|
|
31
26
|
"clear": "rimraf ./dist",
|
|
32
27
|
"clear:node_modules": "rimraf ./node_modules",
|
|
33
|
-
"build": "pnpm run clear &&
|
|
34
|
-
"
|
|
28
|
+
"build": "pnpm run clear && tsdown",
|
|
29
|
+
"watch": "tsdown --watch"
|
|
35
30
|
}
|
|
36
31
|
}
|