@zag-js/tabs 0.2.5 → 0.2.6
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/chunk-7NYLYFDJ.mjs +285 -0
- package/dist/chunk-7VZIDZFW.mjs +163 -0
- package/dist/chunk-ISJ7TQVV.mjs +186 -0
- package/dist/chunk-S2KW2DT4.mjs +9 -0
- package/dist/index.d.ts +7 -963
- package/dist/index.js +30 -14
- package/dist/index.mjs +10 -594
- package/dist/tabs.anatomy.d.ts +6 -0
- package/dist/tabs.anatomy.js +34 -0
- package/dist/tabs.anatomy.mjs +8 -0
- package/dist/tabs.connect.d.ts +21 -0
- package/dist/tabs.connect.js +356 -0
- package/dist/tabs.connect.mjs +8 -0
- package/dist/tabs.dom.d.ts +55 -0
- package/dist/tabs.dom.js +175 -0
- package/dist/tabs.dom.mjs +6 -0
- package/dist/tabs.machine.d.ts +7 -0
- package/dist/tabs.machine.js +459 -0
- package/dist/tabs.machine.mjs +7 -0
- package/dist/tabs.types.d.ts +95 -0
- package/dist/tabs.types.js +18 -0
- package/dist/tabs.types.mjs +0 -0
- package/package.json +21 -11
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/tabs.machine.ts
|
|
21
|
+
var tabs_machine_exports = {};
|
|
22
|
+
__export(tabs_machine_exports, {
|
|
23
|
+
machine: () => machine
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(tabs_machine_exports);
|
|
26
|
+
var import_core = require("@zag-js/core");
|
|
27
|
+
|
|
28
|
+
// ../../utilities/core/src/array.ts
|
|
29
|
+
var first = (v) => v[0];
|
|
30
|
+
var last = (v) => v[v.length - 1];
|
|
31
|
+
|
|
32
|
+
// ../../utilities/core/src/guard.ts
|
|
33
|
+
var isArray = (v) => Array.isArray(v);
|
|
34
|
+
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
35
|
+
|
|
36
|
+
// ../../utilities/core/src/object.ts
|
|
37
|
+
function compact(obj) {
|
|
38
|
+
if (obj === void 0)
|
|
39
|
+
return obj;
|
|
40
|
+
return Object.fromEntries(
|
|
41
|
+
Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// ../../utilities/dom/src/query.ts
|
|
46
|
+
function isDocument(el) {
|
|
47
|
+
return el.nodeType === Node.DOCUMENT_NODE;
|
|
48
|
+
}
|
|
49
|
+
function isWindow(value) {
|
|
50
|
+
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
51
|
+
}
|
|
52
|
+
function isFrame(element) {
|
|
53
|
+
return element.localName === "iframe";
|
|
54
|
+
}
|
|
55
|
+
function getDocument(el) {
|
|
56
|
+
var _a;
|
|
57
|
+
if (isWindow(el))
|
|
58
|
+
return el.document;
|
|
59
|
+
if (isDocument(el))
|
|
60
|
+
return el;
|
|
61
|
+
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
62
|
+
}
|
|
63
|
+
function defineDomHelpers(helpers) {
|
|
64
|
+
const dom2 = {
|
|
65
|
+
getRootNode: (ctx) => {
|
|
66
|
+
var _a, _b;
|
|
67
|
+
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
68
|
+
},
|
|
69
|
+
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
70
|
+
getWin: (ctx) => {
|
|
71
|
+
var _a;
|
|
72
|
+
return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
|
|
73
|
+
},
|
|
74
|
+
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
75
|
+
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
|
|
76
|
+
createEmitter: (ctx, target) => {
|
|
77
|
+
const win = dom2.getWin(ctx);
|
|
78
|
+
return function emit(evt, detail, options) {
|
|
79
|
+
const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
|
|
80
|
+
const eventName = `zag:${evt}`;
|
|
81
|
+
const init = { bubbles, cancelable, composed, detail };
|
|
82
|
+
const event = new win.CustomEvent(eventName, init);
|
|
83
|
+
target.dispatchEvent(event);
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
createListener: (target) => {
|
|
87
|
+
return function listen(evt, handler) {
|
|
88
|
+
const eventName = `zag:${evt}`;
|
|
89
|
+
const listener = (e) => handler(e);
|
|
90
|
+
target.addEventListener(eventName, listener);
|
|
91
|
+
return () => target.removeEventListener(eventName, listener);
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
return {
|
|
96
|
+
...dom2,
|
|
97
|
+
...helpers
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function isHTMLElement(v) {
|
|
101
|
+
return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
|
|
102
|
+
}
|
|
103
|
+
function isVisible(el) {
|
|
104
|
+
if (!isHTMLElement(el))
|
|
105
|
+
return false;
|
|
106
|
+
return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// ../../utilities/dom/src/focusable.ts
|
|
110
|
+
var focusableSelector = "input:not([type='hidden']):not([disabled]), select:not([disabled]), textarea:not([disabled]), a[href], button:not([disabled]), [tabindex], iframe, object, embed, area[href], audio[controls], video[controls], [contenteditable]:not([contenteditable='false']), details > summary:first-of-type";
|
|
111
|
+
var getFocusables = (container, includeContainer = false) => {
|
|
112
|
+
if (!container)
|
|
113
|
+
return [];
|
|
114
|
+
const elements = Array.from(container.querySelectorAll(focusableSelector));
|
|
115
|
+
const include = includeContainer == true || includeContainer == "if-empty" && elements.length === 0;
|
|
116
|
+
if (include && isHTMLElement(container) && isFocusable(container)) {
|
|
117
|
+
elements.unshift(container);
|
|
118
|
+
}
|
|
119
|
+
const focusableElements = elements.filter(isFocusable);
|
|
120
|
+
focusableElements.forEach((element, i) => {
|
|
121
|
+
if (isFrame(element) && element.contentDocument) {
|
|
122
|
+
const frameBody = element.contentDocument.body;
|
|
123
|
+
focusableElements.splice(i, 1, ...getFocusables(frameBody));
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
return focusableElements;
|
|
127
|
+
};
|
|
128
|
+
function isFocusable(element) {
|
|
129
|
+
if (!element)
|
|
130
|
+
return false;
|
|
131
|
+
return element.matches(focusableSelector) && isVisible(element);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// ../../utilities/dom/src/next-tick.ts
|
|
135
|
+
function nextTick(fn) {
|
|
136
|
+
const set = /* @__PURE__ */ new Set();
|
|
137
|
+
function raf2(fn2) {
|
|
138
|
+
const id = globalThis.requestAnimationFrame(fn2);
|
|
139
|
+
set.add(() => globalThis.cancelAnimationFrame(id));
|
|
140
|
+
}
|
|
141
|
+
raf2(() => raf2(fn));
|
|
142
|
+
return function cleanup() {
|
|
143
|
+
set.forEach(function(fn2) {
|
|
144
|
+
fn2();
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function raf(fn) {
|
|
149
|
+
const id = globalThis.requestAnimationFrame(fn);
|
|
150
|
+
return function cleanup() {
|
|
151
|
+
globalThis.cancelAnimationFrame(id);
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// ../../utilities/dom/src/nodelist.ts
|
|
156
|
+
function queryAll(root, selector) {
|
|
157
|
+
var _a;
|
|
158
|
+
return Array.from((_a = root == null ? void 0 : root.querySelectorAll(selector)) != null ? _a : []);
|
|
159
|
+
}
|
|
160
|
+
function itemById(v, id) {
|
|
161
|
+
return v.find((node) => node.id === id);
|
|
162
|
+
}
|
|
163
|
+
function indexOfId(v, id) {
|
|
164
|
+
const item = itemById(v, id);
|
|
165
|
+
return item ? v.indexOf(item) : -1;
|
|
166
|
+
}
|
|
167
|
+
function nextById(v, id, loop = true) {
|
|
168
|
+
let idx = indexOfId(v, id);
|
|
169
|
+
idx = loop ? (idx + 1) % v.length : Math.min(idx + 1, v.length - 1);
|
|
170
|
+
return v[idx];
|
|
171
|
+
}
|
|
172
|
+
function prevById(v, id, loop = true) {
|
|
173
|
+
let idx = indexOfId(v, id);
|
|
174
|
+
if (idx === -1)
|
|
175
|
+
return loop ? v[v.length - 1] : null;
|
|
176
|
+
idx = loop ? (idx - 1 + v.length) % v.length : Math.max(0, idx - 1);
|
|
177
|
+
return v[idx];
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// src/tabs.dom.ts
|
|
181
|
+
var dom = defineDomHelpers({
|
|
182
|
+
getRootId: (ctx) => {
|
|
183
|
+
var _a, _b;
|
|
184
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `tabs:${ctx.id}`;
|
|
185
|
+
},
|
|
186
|
+
getTablistId: (ctx) => {
|
|
187
|
+
var _a, _b;
|
|
188
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.tablist) != null ? _b : `tabs:${ctx.id}:list`;
|
|
189
|
+
},
|
|
190
|
+
getContentId: (ctx, id) => {
|
|
191
|
+
var _a, _b;
|
|
192
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.content) != null ? _b : `tabs:${ctx.id}:content-${id}`;
|
|
193
|
+
},
|
|
194
|
+
getContentGroupId: (ctx) => {
|
|
195
|
+
var _a, _b;
|
|
196
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.contentGroup) != null ? _b : `tabs:${ctx.id}:content-group`;
|
|
197
|
+
},
|
|
198
|
+
getTriggerId: (ctx, id) => {
|
|
199
|
+
var _a, _b;
|
|
200
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.trigger) != null ? _b : `tabs:${ctx.id}:trigger-${id}`;
|
|
201
|
+
},
|
|
202
|
+
getIndicatorId: (ctx) => `tabs:${ctx.id}:indicator`,
|
|
203
|
+
getTablistEl: (ctx) => dom.getById(ctx, dom.getTablistId(ctx)),
|
|
204
|
+
getContentEl: (ctx, id) => dom.getById(ctx, dom.getContentId(ctx, id)),
|
|
205
|
+
getTriggerEl: (ctx, id) => dom.getById(ctx, dom.getTriggerId(ctx, id)),
|
|
206
|
+
getIndicatorEl: (ctx) => dom.getById(ctx, dom.getIndicatorId(ctx)),
|
|
207
|
+
getElements: (ctx) => {
|
|
208
|
+
const ownerId = CSS.escape(dom.getTablistId(ctx));
|
|
209
|
+
const selector = `[role=tab][data-ownedby='${ownerId}']:not([disabled])`;
|
|
210
|
+
return queryAll(dom.getTablistEl(ctx), selector);
|
|
211
|
+
},
|
|
212
|
+
getFirstEl: (ctx) => first(dom.getElements(ctx)),
|
|
213
|
+
getLastEl: (ctx) => last(dom.getElements(ctx)),
|
|
214
|
+
getNextEl: (ctx, id) => nextById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
|
|
215
|
+
getPrevEl: (ctx, id) => prevById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
|
|
216
|
+
getActiveContentEl: (ctx) => {
|
|
217
|
+
if (!ctx.value)
|
|
218
|
+
return;
|
|
219
|
+
const id = dom.getContentId(ctx, ctx.value);
|
|
220
|
+
return dom.getById(ctx, id);
|
|
221
|
+
},
|
|
222
|
+
getRectById: (ctx, id) => {
|
|
223
|
+
var _a;
|
|
224
|
+
const empty = {
|
|
225
|
+
offsetLeft: 0,
|
|
226
|
+
offsetTop: 0,
|
|
227
|
+
offsetWidth: 0,
|
|
228
|
+
offsetHeight: 0
|
|
229
|
+
};
|
|
230
|
+
const tab = (_a = itemById(dom.getElements(ctx), dom.getTriggerId(ctx, id))) != null ? _a : empty;
|
|
231
|
+
if (ctx.isVertical) {
|
|
232
|
+
return {
|
|
233
|
+
top: `${tab.offsetTop}px`,
|
|
234
|
+
height: `${tab.offsetHeight}px`
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
return {
|
|
238
|
+
left: `${tab.offsetLeft}px`,
|
|
239
|
+
width: `${tab.offsetWidth}px`
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
// src/tabs.machine.ts
|
|
245
|
+
var { not } = import_core.guards;
|
|
246
|
+
function machine(userContext) {
|
|
247
|
+
const ctx = compact(userContext);
|
|
248
|
+
return (0, import_core.createMachine)(
|
|
249
|
+
{
|
|
250
|
+
initial: "unknown",
|
|
251
|
+
context: {
|
|
252
|
+
dir: "ltr",
|
|
253
|
+
orientation: "horizontal",
|
|
254
|
+
activationMode: "automatic",
|
|
255
|
+
value: null,
|
|
256
|
+
focusedValue: null,
|
|
257
|
+
previousValues: [],
|
|
258
|
+
indicatorRect: { left: "0px", top: "0px", width: "0px", height: "0px" },
|
|
259
|
+
hasMeasuredRect: false,
|
|
260
|
+
isIndicatorRendered: false,
|
|
261
|
+
loop: true,
|
|
262
|
+
translations: {},
|
|
263
|
+
...ctx
|
|
264
|
+
},
|
|
265
|
+
computed: {
|
|
266
|
+
isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
|
|
267
|
+
isVertical: (ctx2) => ctx2.orientation === "vertical"
|
|
268
|
+
},
|
|
269
|
+
created: ["setPrevSelectedTabs"],
|
|
270
|
+
watch: {
|
|
271
|
+
focusedValue: "invokeOnFocus",
|
|
272
|
+
value: ["invokeOnChange", "setPrevSelectedTabs", "setIndicatorRect", "setContentTabIndex"],
|
|
273
|
+
dir: ["clearMeasured", "setIndicatorRect"]
|
|
274
|
+
},
|
|
275
|
+
on: {
|
|
276
|
+
SET_VALUE: {
|
|
277
|
+
actions: "setValue"
|
|
278
|
+
},
|
|
279
|
+
CLEAR_VALUE: {
|
|
280
|
+
actions: "clearValue"
|
|
281
|
+
}
|
|
282
|
+
},
|
|
283
|
+
states: {
|
|
284
|
+
unknown: {
|
|
285
|
+
on: {
|
|
286
|
+
SETUP: {
|
|
287
|
+
target: "idle",
|
|
288
|
+
actions: ["checkRenderedElements", "setIndicatorRect", "setContentTabIndex"]
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
},
|
|
292
|
+
idle: {
|
|
293
|
+
on: {
|
|
294
|
+
TAB_FOCUS: {
|
|
295
|
+
guard: "selectOnFocus",
|
|
296
|
+
target: "focused",
|
|
297
|
+
actions: ["setFocusedValue", "setValue"]
|
|
298
|
+
},
|
|
299
|
+
TAB_CLICK: {
|
|
300
|
+
target: "focused",
|
|
301
|
+
actions: ["setFocusedValue", "setValue"]
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
},
|
|
305
|
+
focused: {
|
|
306
|
+
on: {
|
|
307
|
+
TAB_CLICK: {
|
|
308
|
+
target: "focused",
|
|
309
|
+
actions: ["setFocusedValue", "setValue"]
|
|
310
|
+
},
|
|
311
|
+
ARROW_LEFT: {
|
|
312
|
+
guard: "isHorizontal",
|
|
313
|
+
actions: "focusPrevTab"
|
|
314
|
+
},
|
|
315
|
+
ARROW_RIGHT: {
|
|
316
|
+
guard: "isHorizontal",
|
|
317
|
+
actions: "focusNextTab"
|
|
318
|
+
},
|
|
319
|
+
ARROW_UP: {
|
|
320
|
+
guard: "isVertical",
|
|
321
|
+
actions: "focusPrevTab"
|
|
322
|
+
},
|
|
323
|
+
ARROW_DOWN: {
|
|
324
|
+
guard: "isVertical",
|
|
325
|
+
actions: "focusNextTab"
|
|
326
|
+
},
|
|
327
|
+
HOME: {
|
|
328
|
+
actions: "focusFirstTab"
|
|
329
|
+
},
|
|
330
|
+
END: {
|
|
331
|
+
actions: "focusLastTab"
|
|
332
|
+
},
|
|
333
|
+
ENTER: {
|
|
334
|
+
guard: not("selectOnFocus"),
|
|
335
|
+
actions: "setValue"
|
|
336
|
+
},
|
|
337
|
+
TAB_FOCUS: [
|
|
338
|
+
{
|
|
339
|
+
guard: "selectOnFocus",
|
|
340
|
+
actions: ["setFocusedValue", "setValue"]
|
|
341
|
+
},
|
|
342
|
+
{ actions: "setFocusedValue" }
|
|
343
|
+
],
|
|
344
|
+
TAB_BLUR: {
|
|
345
|
+
target: "idle",
|
|
346
|
+
actions: "clearFocusedValue"
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
guards: {
|
|
354
|
+
isVertical: (ctx2) => ctx2.isVertical,
|
|
355
|
+
isHorizontal: (ctx2) => ctx2.isHorizontal,
|
|
356
|
+
selectOnFocus: (ctx2) => ctx2.activationMode === "automatic"
|
|
357
|
+
},
|
|
358
|
+
actions: {
|
|
359
|
+
setFocusedValue(ctx2, evt) {
|
|
360
|
+
ctx2.focusedValue = evt.value;
|
|
361
|
+
},
|
|
362
|
+
clearFocusedValue(ctx2) {
|
|
363
|
+
ctx2.focusedValue = null;
|
|
364
|
+
},
|
|
365
|
+
setValue(ctx2, evt) {
|
|
366
|
+
ctx2.value = evt.value;
|
|
367
|
+
},
|
|
368
|
+
clearValue(ctx2) {
|
|
369
|
+
ctx2.value = null;
|
|
370
|
+
},
|
|
371
|
+
invokeOnDelete(ctx2, evt) {
|
|
372
|
+
var _a;
|
|
373
|
+
(_a = ctx2.onDelete) == null ? void 0 : _a.call(ctx2, { value: evt.value });
|
|
374
|
+
},
|
|
375
|
+
focusFirstTab(ctx2) {
|
|
376
|
+
raf(() => {
|
|
377
|
+
var _a;
|
|
378
|
+
return (_a = dom.getFirstEl(ctx2)) == null ? void 0 : _a.focus();
|
|
379
|
+
});
|
|
380
|
+
},
|
|
381
|
+
focusLastTab(ctx2) {
|
|
382
|
+
raf(() => {
|
|
383
|
+
var _a;
|
|
384
|
+
return (_a = dom.getLastEl(ctx2)) == null ? void 0 : _a.focus();
|
|
385
|
+
});
|
|
386
|
+
},
|
|
387
|
+
focusNextTab(ctx2) {
|
|
388
|
+
if (!ctx2.focusedValue)
|
|
389
|
+
return;
|
|
390
|
+
const next = dom.getNextEl(ctx2, ctx2.focusedValue);
|
|
391
|
+
raf(() => next == null ? void 0 : next.focus());
|
|
392
|
+
},
|
|
393
|
+
focusPrevTab(ctx2) {
|
|
394
|
+
if (!ctx2.focusedValue)
|
|
395
|
+
return;
|
|
396
|
+
const prev = dom.getPrevEl(ctx2, ctx2.focusedValue);
|
|
397
|
+
raf(() => prev == null ? void 0 : prev.focus());
|
|
398
|
+
},
|
|
399
|
+
setIndicatorRect(ctx2) {
|
|
400
|
+
nextTick(() => {
|
|
401
|
+
if (!ctx2.isIndicatorRendered || !ctx2.value)
|
|
402
|
+
return;
|
|
403
|
+
ctx2.indicatorRect = dom.getRectById(ctx2, ctx2.value);
|
|
404
|
+
if (ctx2.hasMeasuredRect)
|
|
405
|
+
return;
|
|
406
|
+
nextTick(() => {
|
|
407
|
+
ctx2.hasMeasuredRect = true;
|
|
408
|
+
});
|
|
409
|
+
});
|
|
410
|
+
},
|
|
411
|
+
checkRenderedElements(ctx2) {
|
|
412
|
+
ctx2.isIndicatorRendered = !!dom.getIndicatorEl(ctx2);
|
|
413
|
+
},
|
|
414
|
+
clearMeasured(ctx2) {
|
|
415
|
+
ctx2.hasMeasuredRect = false;
|
|
416
|
+
},
|
|
417
|
+
invokeOnChange(ctx2) {
|
|
418
|
+
var _a;
|
|
419
|
+
(_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
|
|
420
|
+
},
|
|
421
|
+
invokeOnFocus(ctx2) {
|
|
422
|
+
var _a;
|
|
423
|
+
(_a = ctx2.onFocus) == null ? void 0 : _a.call(ctx2, { value: ctx2.focusedValue });
|
|
424
|
+
},
|
|
425
|
+
setPrevSelectedTabs(ctx2) {
|
|
426
|
+
if (ctx2.value != null) {
|
|
427
|
+
ctx2.previousValues = pushUnique(Array.from(ctx2.previousValues), ctx2.value);
|
|
428
|
+
}
|
|
429
|
+
},
|
|
430
|
+
setContentTabIndex(ctx2) {
|
|
431
|
+
raf(() => {
|
|
432
|
+
const panel = dom.getActiveContentEl(ctx2);
|
|
433
|
+
if (!panel)
|
|
434
|
+
return;
|
|
435
|
+
const focusables = getFocusables(panel);
|
|
436
|
+
if (focusables.length > 0) {
|
|
437
|
+
panel.removeAttribute("tabindex");
|
|
438
|
+
} else {
|
|
439
|
+
panel.setAttribute("tabindex", "0");
|
|
440
|
+
}
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
);
|
|
446
|
+
}
|
|
447
|
+
function pushUnique(arr, value) {
|
|
448
|
+
const newArr = arr.slice();
|
|
449
|
+
const index = newArr.indexOf(value);
|
|
450
|
+
if (index > -1) {
|
|
451
|
+
newArr.splice(index, 1);
|
|
452
|
+
}
|
|
453
|
+
newArr.push(value);
|
|
454
|
+
return newArr;
|
|
455
|
+
}
|
|
456
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
457
|
+
0 && (module.exports = {
|
|
458
|
+
machine
|
|
459
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { StateMachine } from '@zag-js/core';
|
|
2
|
+
import { RequiredBy, DirectionProperty, CommonProperties, Context } from '@zag-js/types';
|
|
3
|
+
|
|
4
|
+
type IntlTranslations = {
|
|
5
|
+
tablistLabel?: string;
|
|
6
|
+
};
|
|
7
|
+
type ElementIds = Partial<{
|
|
8
|
+
root: string;
|
|
9
|
+
trigger: string;
|
|
10
|
+
tablist: string;
|
|
11
|
+
contentGroup: string;
|
|
12
|
+
content: string;
|
|
13
|
+
}>;
|
|
14
|
+
type PublicContext = DirectionProperty & CommonProperties & {
|
|
15
|
+
/**
|
|
16
|
+
* The ids of the elements in the tabs. Useful for composition.
|
|
17
|
+
*/
|
|
18
|
+
ids?: ElementIds;
|
|
19
|
+
/**
|
|
20
|
+
* Specifies the localized strings that identifies the accessibility elements and their states
|
|
21
|
+
*/
|
|
22
|
+
translations: IntlTranslations;
|
|
23
|
+
/**
|
|
24
|
+
* Whether the keyboard navigation will loop from last tab to first, and vice versa.
|
|
25
|
+
* @default true
|
|
26
|
+
*/
|
|
27
|
+
loop: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Whether the indicator is rendered.
|
|
30
|
+
*/
|
|
31
|
+
isIndicatorRendered: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* The selected tab id
|
|
34
|
+
*/
|
|
35
|
+
value: string | null;
|
|
36
|
+
/**
|
|
37
|
+
* The orientation of the tabs. Can be `horizontal` or `vertical`
|
|
38
|
+
* - `horizontal`: only left and right arrow key navigation will work.
|
|
39
|
+
* - `vertical`: only up and down arrow key navigation will work.
|
|
40
|
+
*
|
|
41
|
+
* @default "horizontal"
|
|
42
|
+
*/
|
|
43
|
+
orientation?: "horizontal" | "vertical";
|
|
44
|
+
/**
|
|
45
|
+
* The activation mode of the tabs. Can be `manual` or `automatic`
|
|
46
|
+
* - `manual`: Tabs are activated when clicked or press `enter` key.
|
|
47
|
+
* - `automatic`: Tabs are activated when receiving focus
|
|
48
|
+
* @default "automatic"
|
|
49
|
+
*/
|
|
50
|
+
activationMode?: "manual" | "automatic";
|
|
51
|
+
/**
|
|
52
|
+
* Callback to be called when the selected/active tab changes
|
|
53
|
+
*/
|
|
54
|
+
onChange?: (details: {
|
|
55
|
+
value: string | null;
|
|
56
|
+
}) => void;
|
|
57
|
+
/**
|
|
58
|
+
* Callback to be called when the focused tab changes
|
|
59
|
+
*/
|
|
60
|
+
onFocus?: (details: {
|
|
61
|
+
value: string | null;
|
|
62
|
+
}) => void;
|
|
63
|
+
/**
|
|
64
|
+
* Callback to be called when a tab's close button is clicked
|
|
65
|
+
*/
|
|
66
|
+
onDelete?: (details: {
|
|
67
|
+
value: string;
|
|
68
|
+
}) => void;
|
|
69
|
+
};
|
|
70
|
+
type UserDefinedContext = RequiredBy<PublicContext, "id">;
|
|
71
|
+
type ComputedContext = Readonly<{
|
|
72
|
+
/**
|
|
73
|
+
* @computed
|
|
74
|
+
* Whether the tab is in the horizontal orientation
|
|
75
|
+
*/
|
|
76
|
+
isHorizontal: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* @computed
|
|
79
|
+
* Whether the tab is in the vertical orientation
|
|
80
|
+
*/
|
|
81
|
+
isVertical: boolean;
|
|
82
|
+
}>;
|
|
83
|
+
type PrivateContext = Context<{}>;
|
|
84
|
+
type MachineContext = PublicContext & ComputedContext & PrivateContext;
|
|
85
|
+
type MachineState = {
|
|
86
|
+
value: "unknown" | "idle" | "focused";
|
|
87
|
+
};
|
|
88
|
+
type State = StateMachine.State<MachineContext, MachineState>;
|
|
89
|
+
type Send = StateMachine.Send<StateMachine.AnyEventObject>;
|
|
90
|
+
type TabProps = {
|
|
91
|
+
value: string;
|
|
92
|
+
disabled?: boolean;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export { MachineContext, MachineState, Send, State, TabProps, UserDefinedContext };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/tabs.types.ts
|
|
17
|
+
var tabs_types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(tabs_types_exports);
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/tabs",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"description": "Core logic for the tabs widget implemented as a state machine",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"module": "dist/index.mjs",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
8
5
|
"keywords": [
|
|
9
6
|
"js",
|
|
10
7
|
"machine",
|
|
@@ -29,18 +26,31 @@
|
|
|
29
26
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
30
27
|
},
|
|
31
28
|
"dependencies": {
|
|
32
|
-
"@zag-js/anatomy": "0.1.
|
|
33
|
-
"@zag-js/core": "0.2.
|
|
34
|
-
"@zag-js/types": "0.3.
|
|
29
|
+
"@zag-js/anatomy": "0.1.3",
|
|
30
|
+
"@zag-js/core": "0.2.4",
|
|
31
|
+
"@zag-js/types": "0.3.2"
|
|
35
32
|
},
|
|
36
33
|
"devDependencies": {
|
|
37
|
-
"
|
|
38
|
-
"@zag-js/utils": "0.
|
|
34
|
+
"clean-package": "2.2.0",
|
|
35
|
+
"@zag-js/dom-utils": "0.2.2",
|
|
36
|
+
"@zag-js/utils": "0.3.2"
|
|
37
|
+
},
|
|
38
|
+
"clean-package": "../../../clean-package.config.json",
|
|
39
|
+
"main": "dist/index.js",
|
|
40
|
+
"module": "dist/index.mjs",
|
|
41
|
+
"types": "dist/index.d.ts",
|
|
42
|
+
"exports": {
|
|
43
|
+
".": {
|
|
44
|
+
"types": "./dist/index.d.ts",
|
|
45
|
+
"import": "./dist/index.mjs",
|
|
46
|
+
"require": "./dist/index.js"
|
|
47
|
+
},
|
|
48
|
+
"./package.json": "./package.json"
|
|
39
49
|
},
|
|
40
50
|
"scripts": {
|
|
41
|
-
"build-fast": "tsup src
|
|
51
|
+
"build-fast": "tsup src",
|
|
42
52
|
"start": "pnpm build --watch",
|
|
43
|
-
"build": "tsup src
|
|
53
|
+
"build": "tsup src --dts",
|
|
44
54
|
"test": "jest --config ../../../jest.config.js --rootDir . --passWithNoTests",
|
|
45
55
|
"lint": "eslint src --ext .ts,.tsx",
|
|
46
56
|
"test-ci": "pnpm test --ci --runInBand",
|