@zag-js/tabs 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 +7 -8
- package/dist/index.d.ts +7 -8
- package/dist/index.js +16 -38
- package/dist/index.mjs +2 -7
- package/dist/tabs.anatomy.d.mts +2 -6
- package/dist/tabs.anatomy.d.ts +2 -6
- package/dist/tabs.anatomy.js +8 -33
- package/dist/tabs.anatomy.mjs +4 -7
- package/dist/tabs.connect.d.mts +4 -7
- package/dist/tabs.connect.d.ts +4 -7
- package/dist/tabs.connect.js +253 -231
- package/dist/tabs.connect.mjs +249 -204
- package/dist/tabs.dom.d.mts +27 -33
- package/dist/tabs.dom.d.ts +27 -33
- package/dist/tabs.dom.js +77 -84
- package/dist/tabs.dom.mjs +57 -44
- package/dist/tabs.machine.d.mts +2 -7
- package/dist/tabs.machine.d.ts +2 -7
- package/dist/tabs.machine.js +301 -329
- package/dist/tabs.machine.mjs +298 -294
- package/dist/tabs.props.d.mts +7 -12
- package/dist/tabs.props.d.ts +7 -12
- package/dist/tabs.props.js +33 -61
- package/dist/tabs.props.mjs +24 -31
- package/dist/tabs.types.d.mts +252 -194
- package/dist/tabs.types.d.ts +252 -194
- package/dist/tabs.types.js +4 -18
- package/dist/tabs.types.mjs +1 -0
- package/package.json +7 -7
package/dist/tabs.machine.js
CHANGED
|
@@ -1,331 +1,303 @@
|
|
|
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/tabs.machine.ts
|
|
31
|
-
var tabs_machine_exports = {};
|
|
32
|
-
__export(tabs_machine_exports, {
|
|
33
|
-
machine: () => machine
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(tabs_machine_exports);
|
|
36
|
-
var import_core = require("@zag-js/core");
|
|
37
|
-
var import_dom_query = require("@zag-js/dom-query");
|
|
38
|
-
var import_utils = require("@zag-js/utils");
|
|
39
|
-
var dom = __toESM(require("./tabs.dom.js"));
|
|
40
|
-
var { createMachine } = (0, import_core.setup)();
|
|
41
|
-
var machine = createMachine({
|
|
42
|
-
props({ props }) {
|
|
43
|
-
return {
|
|
44
|
-
dir: "ltr",
|
|
45
|
-
orientation: "horizontal",
|
|
46
|
-
activationMode: "automatic",
|
|
47
|
-
loopFocus: true,
|
|
48
|
-
navigate(details) {
|
|
49
|
-
(0, import_dom_query.clickIfLink)(details.node);
|
|
50
|
-
},
|
|
51
|
-
defaultValue: null,
|
|
52
|
-
...props
|
|
53
|
-
};
|
|
54
|
-
},
|
|
55
|
-
initialState() {
|
|
56
|
-
return "idle";
|
|
57
|
-
},
|
|
58
|
-
context({ prop, bindable }) {
|
|
59
|
-
return {
|
|
60
|
-
value: bindable(() => ({
|
|
61
|
-
defaultValue: prop("defaultValue"),
|
|
62
|
-
value: prop("value"),
|
|
63
|
-
onChange(value) {
|
|
64
|
-
prop("onValueChange")?.({ value });
|
|
65
|
-
}
|
|
66
|
-
})),
|
|
67
|
-
focusedValue: bindable(() => ({
|
|
68
|
-
defaultValue: prop("value") || prop("defaultValue"),
|
|
69
|
-
sync: true,
|
|
70
|
-
onChange(value) {
|
|
71
|
-
prop("onFocusChange")?.({ focusedValue: value });
|
|
72
|
-
}
|
|
73
|
-
})),
|
|
74
|
-
ssr: bindable(() => ({ defaultValue: true })),
|
|
75
|
-
indicatorRect: bindable(() => ({
|
|
76
|
-
defaultValue: null
|
|
77
|
-
})),
|
|
78
|
-
animateIndicator: bindable(() => ({
|
|
79
|
-
defaultValue: false
|
|
80
|
-
}))
|
|
81
|
-
};
|
|
82
|
-
},
|
|
83
|
-
refs() {
|
|
84
|
-
return {
|
|
85
|
-
indicatorCleanup: null,
|
|
86
|
-
prevValue: null
|
|
87
|
-
};
|
|
88
|
-
},
|
|
89
|
-
watch({ context, prop, track, action }) {
|
|
90
|
-
track([() => context.get("value")], () => {
|
|
91
|
-
action(["syncIndicatorAnimation", "syncIndicatorRect", "syncTabIndex", "navigateIfNeeded"]);
|
|
92
|
-
});
|
|
93
|
-
track([() => prop("dir"), () => prop("orientation")], () => {
|
|
94
|
-
action(["syncIndicatorRect"]);
|
|
95
|
-
});
|
|
96
|
-
},
|
|
97
|
-
on: {
|
|
98
|
-
SET_VALUE: {
|
|
99
|
-
actions: ["setValue"]
|
|
100
|
-
},
|
|
101
|
-
CLEAR_VALUE: {
|
|
102
|
-
actions: ["clearValue"]
|
|
103
|
-
},
|
|
104
|
-
SET_INDICATOR_RECT: {
|
|
105
|
-
actions: ["setIndicatorRect"]
|
|
106
|
-
},
|
|
107
|
-
SYNC_TAB_INDEX: {
|
|
108
|
-
actions: ["syncTabIndex"]
|
|
109
|
-
},
|
|
110
|
-
INDICATOR_TRANSITION_END: {
|
|
111
|
-
actions: ["clearIndicatorAnimation"]
|
|
112
|
-
}
|
|
113
|
-
},
|
|
114
|
-
entry: ["syncPrevValue", "syncIndicatorRect", "syncTabIndex", "syncSsr"],
|
|
115
|
-
exit: ["cleanupObserver"],
|
|
116
|
-
states: {
|
|
117
|
-
idle: {
|
|
118
|
-
on: {
|
|
119
|
-
TAB_FOCUS: {
|
|
120
|
-
target: "focused",
|
|
121
|
-
actions: ["setFocusedValue"]
|
|
122
|
-
},
|
|
123
|
-
TAB_CLICK: {
|
|
124
|
-
target: "focused",
|
|
125
|
-
actions: ["setFocusedValue", "setValue"]
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
},
|
|
129
|
-
focused: {
|
|
130
|
-
on: {
|
|
131
|
-
TAB_CLICK: {
|
|
132
|
-
actions: ["setFocusedValue", "setValue"]
|
|
133
|
-
},
|
|
134
|
-
ARROW_PREV: [
|
|
135
|
-
{
|
|
136
|
-
guard: "selectOnFocus",
|
|
137
|
-
actions: ["focusPrevTab", "selectFocusedTab"]
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
actions: ["focusPrevTab"]
|
|
141
|
-
}
|
|
142
|
-
],
|
|
143
|
-
ARROW_NEXT: [
|
|
144
|
-
{
|
|
145
|
-
guard: "selectOnFocus",
|
|
146
|
-
actions: ["focusNextTab", "selectFocusedTab"]
|
|
147
|
-
},
|
|
148
|
-
{
|
|
149
|
-
actions: ["focusNextTab"]
|
|
150
|
-
}
|
|
151
|
-
],
|
|
152
|
-
HOME: [
|
|
153
|
-
{
|
|
154
|
-
guard: "selectOnFocus",
|
|
155
|
-
actions: ["focusFirstTab", "selectFocusedTab"]
|
|
156
|
-
},
|
|
157
|
-
{
|
|
158
|
-
actions: ["focusFirstTab"]
|
|
159
|
-
}
|
|
160
|
-
],
|
|
161
|
-
END: [
|
|
162
|
-
{
|
|
163
|
-
guard: "selectOnFocus",
|
|
164
|
-
actions: ["focusLastTab", "selectFocusedTab"]
|
|
165
|
-
},
|
|
166
|
-
{
|
|
167
|
-
actions: ["focusLastTab"]
|
|
168
|
-
}
|
|
169
|
-
],
|
|
170
|
-
TAB_FOCUS: {
|
|
171
|
-
actions: ["setFocusedValue"]
|
|
172
|
-
},
|
|
173
|
-
TAB_BLUR: {
|
|
174
|
-
target: "idle",
|
|
175
|
-
actions: ["clearFocusedValue"]
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
},
|
|
180
|
-
implementations: {
|
|
181
|
-
guards: {
|
|
182
|
-
selectOnFocus: ({ prop }) => prop("activationMode") === "automatic"
|
|
183
|
-
},
|
|
184
|
-
actions: {
|
|
185
|
-
selectFocusedTab({ context, prop }) {
|
|
186
|
-
(0, import_dom_query.raf)(() => {
|
|
187
|
-
const focusedValue = context.get("focusedValue");
|
|
188
|
-
if (!focusedValue) return;
|
|
189
|
-
const nullable = prop("deselectable") && context.get("value") === focusedValue;
|
|
190
|
-
const value = nullable ? null : focusedValue;
|
|
191
|
-
context.set("value", value);
|
|
192
|
-
});
|
|
193
|
-
},
|
|
194
|
-
setFocusedValue({ context, event, flush }) {
|
|
195
|
-
if (event.value == null) return;
|
|
196
|
-
flush(() => {
|
|
197
|
-
context.set("focusedValue", event.value);
|
|
198
|
-
});
|
|
199
|
-
},
|
|
200
|
-
clearFocusedValue({ context }) {
|
|
201
|
-
context.set("focusedValue", null);
|
|
202
|
-
},
|
|
203
|
-
setValue({ context, event, prop }) {
|
|
204
|
-
const nullable = prop("deselectable") && context.get("value") === context.get("focusedValue");
|
|
205
|
-
context.set("value", nullable ? null : event.value);
|
|
206
|
-
},
|
|
207
|
-
clearValue({ context }) {
|
|
208
|
-
context.set("value", null);
|
|
209
|
-
},
|
|
210
|
-
focusFirstTab({ scope }) {
|
|
211
|
-
(0, import_dom_query.raf)(() => {
|
|
212
|
-
dom.getFirstTriggerEl(scope)?.focus();
|
|
213
|
-
});
|
|
214
|
-
},
|
|
215
|
-
focusLastTab({ scope }) {
|
|
216
|
-
(0, import_dom_query.raf)(() => {
|
|
217
|
-
dom.getLastTriggerEl(scope)?.focus();
|
|
218
|
-
});
|
|
219
|
-
},
|
|
220
|
-
focusNextTab({ context, prop, scope, event }) {
|
|
221
|
-
const focusedValue = event.value ?? context.get("focusedValue");
|
|
222
|
-
if (!focusedValue) return;
|
|
223
|
-
const triggerEl = dom.getNextTriggerEl(scope, {
|
|
224
|
-
value: focusedValue,
|
|
225
|
-
loopFocus: prop("loopFocus")
|
|
226
|
-
});
|
|
227
|
-
(0, import_dom_query.raf)(() => {
|
|
228
|
-
if (prop("virtualFocus")) {
|
|
229
|
-
if (triggerEl?.dataset.value != null) {
|
|
230
|
-
context.set("focusedValue", triggerEl.dataset.value);
|
|
231
|
-
}
|
|
232
|
-
} else {
|
|
233
|
-
triggerEl?.focus();
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
},
|
|
237
|
-
focusPrevTab({ context, prop, scope, event }) {
|
|
238
|
-
const focusedValue = event.value ?? context.get("focusedValue");
|
|
239
|
-
if (!focusedValue) return;
|
|
240
|
-
const triggerEl = dom.getPrevTriggerEl(scope, {
|
|
241
|
-
value: focusedValue,
|
|
242
|
-
loopFocus: prop("loopFocus")
|
|
243
|
-
});
|
|
244
|
-
(0, import_dom_query.raf)(() => {
|
|
245
|
-
if (prop("virtualFocus")) {
|
|
246
|
-
if (triggerEl?.dataset.value != null) {
|
|
247
|
-
context.set("focusedValue", triggerEl.dataset.value);
|
|
248
|
-
}
|
|
249
|
-
} else {
|
|
250
|
-
triggerEl?.focus();
|
|
251
|
-
}
|
|
252
|
-
});
|
|
253
|
-
},
|
|
254
|
-
syncTabIndex({ context, scope }) {
|
|
255
|
-
(0, import_dom_query.raf)(() => {
|
|
256
|
-
const value = context.get("value");
|
|
257
|
-
if (!value) return;
|
|
258
|
-
const contentEl = dom.getContentEl(scope, value);
|
|
259
|
-
if (!contentEl) return;
|
|
260
|
-
const focusables = (0, import_dom_query.getFocusables)(contentEl);
|
|
261
|
-
if (focusables.length > 0) {
|
|
262
|
-
contentEl.removeAttribute("tabindex");
|
|
263
|
-
} else {
|
|
264
|
-
contentEl.setAttribute("tabindex", "0");
|
|
265
|
-
}
|
|
266
|
-
});
|
|
267
|
-
},
|
|
268
|
-
cleanupObserver({ refs }) {
|
|
269
|
-
const cleanup = refs.get("indicatorCleanup");
|
|
270
|
-
if (cleanup) cleanup();
|
|
271
|
-
},
|
|
272
|
-
setIndicatorRect({ context, event, scope }) {
|
|
273
|
-
const value = event.id ?? context.get("value");
|
|
274
|
-
const indicatorEl = dom.getIndicatorEl(scope);
|
|
275
|
-
if (!indicatorEl) return;
|
|
276
|
-
if (!value) return;
|
|
277
|
-
const triggerEl = dom.getTriggerEl(scope, value);
|
|
278
|
-
if (!triggerEl) return;
|
|
279
|
-
context.set("indicatorRect", dom.getRectByValue(scope, value));
|
|
280
|
-
},
|
|
281
|
-
syncSsr({ context }) {
|
|
282
|
-
context.set("ssr", false);
|
|
283
|
-
},
|
|
284
|
-
syncPrevValue({ context, refs }) {
|
|
285
|
-
refs.set("prevValue", context.get("value"));
|
|
286
|
-
},
|
|
287
|
-
syncIndicatorAnimation({ context, refs }) {
|
|
288
|
-
const prevValue = refs.get("prevValue");
|
|
289
|
-
const nextValue = context.get("value");
|
|
290
|
-
const animate = prevValue != null && nextValue != null && prevValue !== nextValue;
|
|
291
|
-
context.set("animateIndicator", animate);
|
|
292
|
-
refs.set("prevValue", nextValue);
|
|
293
|
-
},
|
|
294
|
-
clearIndicatorAnimation({ context }) {
|
|
295
|
-
context.set("animateIndicator", false);
|
|
296
|
-
},
|
|
297
|
-
syncIndicatorRect({ context, refs, scope }) {
|
|
298
|
-
const cleanup = refs.get("indicatorCleanup");
|
|
299
|
-
if (cleanup) cleanup();
|
|
300
|
-
const indicatorEl = dom.getIndicatorEl(scope);
|
|
301
|
-
if (!indicatorEl) return;
|
|
302
|
-
const exec = () => {
|
|
303
|
-
const triggerEl = dom.getTriggerEl(scope, context.get("value"));
|
|
304
|
-
if (!triggerEl) return;
|
|
305
|
-
const rect = dom.getOffsetRect(triggerEl);
|
|
306
|
-
context.set("indicatorRect", (prev) => (0, import_utils.isEqual)(prev, rect) ? prev : rect);
|
|
307
|
-
};
|
|
308
|
-
exec();
|
|
309
|
-
const triggerEls = dom.getElements(scope);
|
|
310
|
-
const listEl = dom.getListEl(scope);
|
|
311
|
-
const indicatorCleanup = (0, import_utils.callAll)(
|
|
312
|
-
...triggerEls.map((el) => import_dom_query.resizeObserverBorderBox.observe(el, exec)),
|
|
313
|
-
...listEl ? [import_dom_query.resizeObserverBorderBox.observe(listEl, exec)] : []
|
|
314
|
-
);
|
|
315
|
-
refs.set("indicatorCleanup", indicatorCleanup);
|
|
316
|
-
},
|
|
317
|
-
navigateIfNeeded({ context, prop, scope }) {
|
|
318
|
-
const value = context.get("value");
|
|
319
|
-
if (!value) return;
|
|
320
|
-
const triggerEl = dom.getTriggerEl(scope, value);
|
|
321
|
-
if ((0, import_dom_query.isAnchorElement)(triggerEl)) {
|
|
322
|
-
prop("navigate")?.({ value, node: triggerEl, href: triggerEl.href });
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
}
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
327
4
|
});
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
5
|
+
const require_tabs_dom = require("./tabs.dom.js");
|
|
6
|
+
let _zag_js_dom_query = require("@zag-js/dom-query");
|
|
7
|
+
let _zag_js_utils = require("@zag-js/utils");
|
|
8
|
+
// src/tabs.machine.ts
|
|
9
|
+
const { createMachine } = (0, require("@zag-js/core").setup)();
|
|
10
|
+
const machine = createMachine({
|
|
11
|
+
props({ props }) {
|
|
12
|
+
return {
|
|
13
|
+
dir: "ltr",
|
|
14
|
+
orientation: "horizontal",
|
|
15
|
+
activationMode: "automatic",
|
|
16
|
+
loopFocus: true,
|
|
17
|
+
defaultValue: null,
|
|
18
|
+
...props
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
initialState() {
|
|
22
|
+
return "idle";
|
|
23
|
+
},
|
|
24
|
+
context({ prop, bindable, scope, getEvent }) {
|
|
25
|
+
return {
|
|
26
|
+
value: bindable(() => ({
|
|
27
|
+
defaultValue: prop("defaultValue"),
|
|
28
|
+
value: prop("value"),
|
|
29
|
+
onChange(value, prevValue) {
|
|
30
|
+
const activationDirection = require_tabs_dom.getActivationDirection(scope, prevValue ?? null, value, prop("orientation"));
|
|
31
|
+
const reason = getEvent().src;
|
|
32
|
+
prop("onValueChange")?.({
|
|
33
|
+
value,
|
|
34
|
+
activationDirection,
|
|
35
|
+
reason
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
})),
|
|
39
|
+
focusedValue: bindable(() => ({
|
|
40
|
+
defaultValue: prop("value") || prop("defaultValue"),
|
|
41
|
+
sync: true,
|
|
42
|
+
onChange(value) {
|
|
43
|
+
prop("onFocusChange")?.({ focusedValue: value });
|
|
44
|
+
}
|
|
45
|
+
})),
|
|
46
|
+
ssr: bindable(() => ({ defaultValue: true })),
|
|
47
|
+
indicatorRect: bindable(() => ({ defaultValue: null })),
|
|
48
|
+
indicatorInstant: bindable(() => ({ defaultValue: false })),
|
|
49
|
+
tabStopValue: bindable(() => ({ defaultValue: null })),
|
|
50
|
+
hasFocusableContent: bindable(() => ({ defaultValue: false })),
|
|
51
|
+
activationDirection: bindable(() => ({ defaultValue: "none" }))
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
refs({ prop }) {
|
|
55
|
+
return {
|
|
56
|
+
previousValue: prop("value") ?? prop("defaultValue") ?? null,
|
|
57
|
+
indicatorCleanup: null,
|
|
58
|
+
indicatorFrame: _zag_js_dom_query.AnimationFrame.create(),
|
|
59
|
+
focusFrame: _zag_js_dom_query.AnimationFrame.create(),
|
|
60
|
+
selectFrame: _zag_js_dom_query.AnimationFrame.create(),
|
|
61
|
+
tabIndexFrame: _zag_js_dom_query.AnimationFrame.create(),
|
|
62
|
+
directionFrame: _zag_js_dom_query.AnimationFrame.create()
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
computed: { activationDirection({ context, refs, scope, prop }) {
|
|
66
|
+
const value = context.get("value");
|
|
67
|
+
const previousValue = refs.get("previousValue");
|
|
68
|
+
if (value === previousValue) return context.get("activationDirection");
|
|
69
|
+
return require_tabs_dom.getActivationDirection(scope, previousValue, value, prop("orientation"));
|
|
70
|
+
} },
|
|
71
|
+
watch({ context, prop, track, action }) {
|
|
72
|
+
track([() => context.get("value")], () => {
|
|
73
|
+
action([
|
|
74
|
+
"setActivationDirection",
|
|
75
|
+
"syncIndicatorRect",
|
|
76
|
+
"syncTabIndex",
|
|
77
|
+
"syncTabStopValue"
|
|
78
|
+
]);
|
|
79
|
+
});
|
|
80
|
+
track([() => prop("dir"), () => prop("orientation")], () => {
|
|
81
|
+
action(["snapIndicator", "syncIndicatorRect"]);
|
|
82
|
+
});
|
|
83
|
+
},
|
|
84
|
+
on: {
|
|
85
|
+
"TRIGGER.FOCUS": {
|
|
86
|
+
target: "focused",
|
|
87
|
+
actions: ["setFocusedValue"]
|
|
88
|
+
},
|
|
89
|
+
"TRIGGER.CLICK": {
|
|
90
|
+
target: "focused",
|
|
91
|
+
actions: [
|
|
92
|
+
"setFocusedValue",
|
|
93
|
+
"toggleValue",
|
|
94
|
+
"requestNavigation"
|
|
95
|
+
]
|
|
96
|
+
},
|
|
97
|
+
"TRIGGERS.CHANGE": { actions: ["syncTabStopValue", "syncIndicatorRect"] },
|
|
98
|
+
"VALUE.SET": { actions: ["setValue"] },
|
|
99
|
+
"VALUE.STEP": [{
|
|
100
|
+
guard: "isVirtualFocus",
|
|
101
|
+
target: "focused",
|
|
102
|
+
actions: ["stepValue"]
|
|
103
|
+
}, { actions: ["stepValue"] }],
|
|
104
|
+
"INDICATOR.SET": { actions: ["setIndicatorRect"] },
|
|
105
|
+
"INDICATOR.RESIZE": [{
|
|
106
|
+
guard: "isIndicatorTransitioning",
|
|
107
|
+
actions: ["setResizedIndicatorRect"]
|
|
108
|
+
}, { actions: ["snapIndicator", "setResizedIndicatorRect"] }],
|
|
109
|
+
"CONTENT.SYNC": { actions: ["syncTabIndex"] }
|
|
110
|
+
},
|
|
111
|
+
effects: ["trackTriggers"],
|
|
112
|
+
entry: [
|
|
113
|
+
"syncIndicatorRect",
|
|
114
|
+
"syncTabIndex",
|
|
115
|
+
"syncTabStopValue",
|
|
116
|
+
"syncSsr"
|
|
117
|
+
],
|
|
118
|
+
exit: ["cleanupObserver", "cancelFrames"],
|
|
119
|
+
states: {
|
|
120
|
+
idle: {},
|
|
121
|
+
focused: {
|
|
122
|
+
exit: ["cancelFocusFrame"],
|
|
123
|
+
on: {
|
|
124
|
+
"FOCUS.MOVE": [{
|
|
125
|
+
guard: "selectOnFocus",
|
|
126
|
+
actions: ["moveFocus", "selectFocusedTab"]
|
|
127
|
+
}, { actions: ["moveFocus"] }],
|
|
128
|
+
"TRIGGER.BLUR": {
|
|
129
|
+
target: "idle",
|
|
130
|
+
actions: ["clearFocusedValue"]
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
implementations: {
|
|
136
|
+
guards: {
|
|
137
|
+
selectOnFocus: ({ prop }) => prop("activationMode") === "automatic",
|
|
138
|
+
isIndicatorTransitioning: ({ event }) => !!event.transitioning,
|
|
139
|
+
isVirtualFocus: ({ prop }) => !!prop("virtualFocus")
|
|
140
|
+
},
|
|
141
|
+
actions: {
|
|
142
|
+
selectFocusedTab({ context, prop, event, scope, refs, send }) {
|
|
143
|
+
refs.get("selectFrame").request(() => {
|
|
144
|
+
const value = context.get("focusedValue");
|
|
145
|
+
if (!value || context.get("value") === value) return;
|
|
146
|
+
if (event.src === "keyboard") {
|
|
147
|
+
const triggerEl = require_tabs_dom.getTriggerEl(scope, value);
|
|
148
|
+
if ((0, _zag_js_dom_query.isAnchorElement)(triggerEl) && prop("navigate") !== null) {
|
|
149
|
+
triggerEl.click();
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
send({
|
|
154
|
+
type: "VALUE.SET",
|
|
155
|
+
value,
|
|
156
|
+
src: "keyboard"
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
},
|
|
160
|
+
setFocusedValue({ context, event, flush }) {
|
|
161
|
+
if (event.value == null) return;
|
|
162
|
+
flush(() => {
|
|
163
|
+
context.set("focusedValue", event.value);
|
|
164
|
+
});
|
|
165
|
+
},
|
|
166
|
+
clearFocusedValue({ context }) {
|
|
167
|
+
context.set("focusedValue", null);
|
|
168
|
+
},
|
|
169
|
+
setValue({ context, event }) {
|
|
170
|
+
context.set("value", event.value);
|
|
171
|
+
},
|
|
172
|
+
toggleValue({ context, event, prop }) {
|
|
173
|
+
const deselect = prop("deselectable") && context.get("value") === event.value;
|
|
174
|
+
context.set("value", deselect ? null : event.value);
|
|
175
|
+
},
|
|
176
|
+
syncTabStopValue({ context, scope }) {
|
|
177
|
+
const selectedEl = require_tabs_dom.getTriggerEl(scope, context.get("value"));
|
|
178
|
+
const reachable = selectedEl != null && !selectedEl.hasAttribute("disabled");
|
|
179
|
+
context.set("tabStopValue", reachable ? null : require_tabs_dom.getFirstTriggerEl(scope)?.dataset.value ?? null);
|
|
180
|
+
},
|
|
181
|
+
moveFocus(params) {
|
|
182
|
+
const { context, prop, scope, event } = params;
|
|
183
|
+
const focusedValue = context.get("focusedValue");
|
|
184
|
+
focusTrigger(params, () => {
|
|
185
|
+
if (event.to === "first") return require_tabs_dom.getFirstTriggerEl(scope);
|
|
186
|
+
if (event.to === "last") return require_tabs_dom.getLastTriggerEl(scope);
|
|
187
|
+
if (!focusedValue) return null;
|
|
188
|
+
return require_tabs_dom.getSiblingTriggerEl(scope, focusedValue, event.to === "next" ? 1 : -1, prop("loopFocus"));
|
|
189
|
+
});
|
|
190
|
+
},
|
|
191
|
+
stepValue({ context, prop, scope, event }) {
|
|
192
|
+
const value = require_tabs_dom.getSiblingTriggerEl(scope, event.from ?? context.get("value"), event.step, prop("loopFocus"))?.dataset.value;
|
|
193
|
+
if (value == null) return;
|
|
194
|
+
context.set("value", value);
|
|
195
|
+
if (prop("virtualFocus")) context.set("focusedValue", value);
|
|
196
|
+
},
|
|
197
|
+
setActivationDirection({ refs, computed, context, scope, prop }) {
|
|
198
|
+
const previousValue = refs.get("previousValue");
|
|
199
|
+
const value = context.get("value");
|
|
200
|
+
context.set("activationDirection", computed("activationDirection"));
|
|
201
|
+
refs.set("previousValue", value);
|
|
202
|
+
if (value == null || require_tabs_dom.getTriggerEl(scope, value)) return;
|
|
203
|
+
refs.get("directionFrame").request(() => {
|
|
204
|
+
context.set("activationDirection", require_tabs_dom.getActivationDirection(scope, previousValue, value, prop("orientation")));
|
|
205
|
+
});
|
|
206
|
+
},
|
|
207
|
+
syncTabIndex({ context, scope, refs }) {
|
|
208
|
+
refs.get("tabIndexFrame").request(() => {
|
|
209
|
+
const contentEl = require_tabs_dom.getContentEl(scope, context.get("value") ?? "");
|
|
210
|
+
context.set("hasFocusableContent", contentEl != null && (0, _zag_js_dom_query.getFocusables)(contentEl).length > 0);
|
|
211
|
+
});
|
|
212
|
+
},
|
|
213
|
+
cancelFocusFrame({ refs }) {
|
|
214
|
+
refs.get("focusFrame").cancel();
|
|
215
|
+
},
|
|
216
|
+
cancelFrames({ refs }) {
|
|
217
|
+
refs.get("focusFrame").cancel();
|
|
218
|
+
refs.get("indicatorFrame").cancel();
|
|
219
|
+
refs.get("selectFrame").cancel();
|
|
220
|
+
refs.get("tabIndexFrame").cancel();
|
|
221
|
+
refs.get("directionFrame").cancel();
|
|
222
|
+
},
|
|
223
|
+
cleanupObserver({ refs }) {
|
|
224
|
+
const cleanup = refs.get("indicatorCleanup");
|
|
225
|
+
if (cleanup) cleanup();
|
|
226
|
+
},
|
|
227
|
+
setIndicatorRect({ context, event, scope }) {
|
|
228
|
+
if (!require_tabs_dom.getIndicatorEl(scope)) return;
|
|
229
|
+
const triggerEl = require_tabs_dom.getTriggerEl(scope, event.value ?? context.get("value"));
|
|
230
|
+
if (!triggerEl) return;
|
|
231
|
+
context.set("indicatorRect", require_tabs_dom.getTriggerRect(scope, triggerEl));
|
|
232
|
+
},
|
|
233
|
+
syncSsr({ context }) {
|
|
234
|
+
context.set("ssr", false);
|
|
235
|
+
},
|
|
236
|
+
snapIndicator({ context, refs }) {
|
|
237
|
+
const frame = refs.get("indicatorFrame");
|
|
238
|
+
context.set("indicatorInstant", true);
|
|
239
|
+
frame.request(() => frame.request(() => context.set("indicatorInstant", false)));
|
|
240
|
+
},
|
|
241
|
+
setResizedIndicatorRect({ context, event }) {
|
|
242
|
+
context.set("indicatorRect", event.rect);
|
|
243
|
+
},
|
|
244
|
+
syncIndicatorRect({ context, refs, scope, send }) {
|
|
245
|
+
const cleanup = refs.get("indicatorCleanup");
|
|
246
|
+
if (cleanup) cleanup();
|
|
247
|
+
const indicatorEl = require_tabs_dom.getIndicatorEl(scope);
|
|
248
|
+
if (!indicatorEl) return;
|
|
249
|
+
const getRect = () => {
|
|
250
|
+
const triggerEl = require_tabs_dom.getTriggerEl(scope, context.get("value"));
|
|
251
|
+
return triggerEl ? require_tabs_dom.getTriggerRect(scope, triggerEl) : null;
|
|
252
|
+
};
|
|
253
|
+
const rect = getRect();
|
|
254
|
+
if (rect) context.set("indicatorRect", (prev) => (0, _zag_js_utils.isEqual)(prev, rect) ? prev : rect);
|
|
255
|
+
const onResize = () => {
|
|
256
|
+
const rect = getRect();
|
|
257
|
+
if (!rect || (0, _zag_js_utils.isEqual)(context.get("indicatorRect"), rect)) return;
|
|
258
|
+
send({
|
|
259
|
+
type: "INDICATOR.RESIZE",
|
|
260
|
+
rect,
|
|
261
|
+
transitioning: indicatorEl.getAnimations?.().length > 0
|
|
262
|
+
});
|
|
263
|
+
};
|
|
264
|
+
const triggerEls = require_tabs_dom.getElements(scope);
|
|
265
|
+
const listEl = require_tabs_dom.getListEl(scope);
|
|
266
|
+
const indicatorCleanup = (0, _zag_js_utils.callAll)(...triggerEls.map((el) => _zag_js_dom_query.resizeObserverBorderBox.observe(el, onResize)), ...listEl ? [_zag_js_dom_query.resizeObserverBorderBox.observe(listEl, onResize), (0, _zag_js_dom_query.addDomEvent)(listEl, "scroll", onResize, { passive: true })] : []);
|
|
267
|
+
refs.set("indicatorCleanup", indicatorCleanup);
|
|
268
|
+
},
|
|
269
|
+
requestNavigation({ event, prop, scope }) {
|
|
270
|
+
const navigate = prop("navigate");
|
|
271
|
+
if (!navigate || event.value == null) return;
|
|
272
|
+
const node = require_tabs_dom.getTriggerEl(scope, event.value);
|
|
273
|
+
if (!(0, _zag_js_dom_query.isAnchorElement)(node)) return;
|
|
274
|
+
navigate({
|
|
275
|
+
value: event.value,
|
|
276
|
+
node,
|
|
277
|
+
href: node.href
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
effects: { trackTriggers({ scope, send }) {
|
|
282
|
+
return (0, _zag_js_dom_query.observeChildren)(() => require_tabs_dom.getListEl(scope), {
|
|
283
|
+
attributes: true,
|
|
284
|
+
attributeFilter: ["disabled"],
|
|
285
|
+
callback() {
|
|
286
|
+
send({ type: "TRIGGERS.CHANGE" });
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
} }
|
|
290
|
+
}
|
|
331
291
|
});
|
|
292
|
+
function focusTrigger(params, getTriggerEl) {
|
|
293
|
+
const { context, prop, refs } = params;
|
|
294
|
+
refs.get("focusFrame").request(() => {
|
|
295
|
+
const triggerEl = getTriggerEl();
|
|
296
|
+
if (!prop("virtualFocus")) {
|
|
297
|
+
triggerEl?.focus();
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
if (triggerEl?.dataset.value != null) context.set("focusedValue", triggerEl.dataset.value);
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
exports.machine = machine;
|