@zag-js/tabs 0.1.9 → 0.1.12
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/LICENSE +21 -0
- package/dist/index.d.ts +115 -3
- package/dist/index.js +236 -233
- package/dist/index.mjs +232 -237
- package/package.json +14 -11
- package/dist/tabs.connect.d.ts +0 -17
- package/dist/tabs.dom.d.ts +0 -32
- package/dist/tabs.machine.d.ts +0 -2
- package/dist/tabs.types.d.ts +0 -120
package/dist/index.mjs
CHANGED
|
@@ -1,37 +1,48 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
-
var __spreadValues = (a, b) => {
|
|
7
|
-
for (var prop in b || (b = {}))
|
|
8
|
-
if (__hasOwnProp.call(b, prop))
|
|
9
|
-
__defNormalProp(a, prop, b[prop]);
|
|
10
|
-
if (__getOwnPropSymbols)
|
|
11
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
-
if (__propIsEnum.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
}
|
|
15
|
-
return a;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
1
|
// ../../utilities/dom/dist/index.mjs
|
|
19
2
|
var dataAttr = (guard) => {
|
|
20
3
|
return guard ? "" : void 0;
|
|
21
4
|
};
|
|
22
5
|
var isDom = () => typeof window !== "undefined";
|
|
23
6
|
function getPlatform() {
|
|
24
|
-
var _a;
|
|
25
7
|
const agent = navigator.userAgentData;
|
|
26
|
-
return (
|
|
8
|
+
return (agent == null ? void 0 : agent.platform) ?? navigator.platform;
|
|
27
9
|
}
|
|
28
10
|
var pt = (v) => isDom() && v.test(getPlatform());
|
|
29
11
|
var vn = (v) => isDom() && v.test(navigator.vendor);
|
|
30
12
|
var isSafari = () => isApple() && vn(/apple/i);
|
|
31
13
|
var isApple = () => pt(/mac|iphone|ipad|ipod/i);
|
|
14
|
+
function isDocument(el) {
|
|
15
|
+
return el.nodeType === Node.DOCUMENT_NODE;
|
|
16
|
+
}
|
|
17
|
+
function isWindow(value) {
|
|
18
|
+
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
19
|
+
}
|
|
32
20
|
function isFrame(element) {
|
|
33
21
|
return element.localName === "iframe";
|
|
34
22
|
}
|
|
23
|
+
function getDocument(el) {
|
|
24
|
+
if (isWindow(el))
|
|
25
|
+
return el.document;
|
|
26
|
+
if (isDocument(el))
|
|
27
|
+
return el;
|
|
28
|
+
return (el == null ? void 0 : el.ownerDocument) ?? document;
|
|
29
|
+
}
|
|
30
|
+
function defineDomHelpers(helpers) {
|
|
31
|
+
const dom2 = {
|
|
32
|
+
getRootNode: (ctx) => {
|
|
33
|
+
var _a;
|
|
34
|
+
return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) ?? document;
|
|
35
|
+
},
|
|
36
|
+
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
37
|
+
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
38
|
+
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
39
|
+
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
40
|
+
};
|
|
41
|
+
return {
|
|
42
|
+
...dom2,
|
|
43
|
+
...helpers
|
|
44
|
+
};
|
|
45
|
+
}
|
|
35
46
|
function isHTMLElement(v) {
|
|
36
47
|
return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
|
|
37
48
|
}
|
|
@@ -79,10 +90,9 @@ var sameKeyMap = {
|
|
|
79
90
|
Right: "ArrowRight"
|
|
80
91
|
};
|
|
81
92
|
function getEventKey(event, options = {}) {
|
|
82
|
-
var _a;
|
|
83
93
|
const { dir = "ltr", orientation = "horizontal" } = options;
|
|
84
94
|
let { key } = event;
|
|
85
|
-
key =
|
|
95
|
+
key = sameKeyMap[key] ?? key;
|
|
86
96
|
const isRtl = dir === "rtl" && orientation === "horizontal";
|
|
87
97
|
if (isRtl && key in rtlKeyMap) {
|
|
88
98
|
key = rtlKeyMap[key];
|
|
@@ -109,8 +119,7 @@ function raf(fn) {
|
|
|
109
119
|
};
|
|
110
120
|
}
|
|
111
121
|
function queryAll(root, selector) {
|
|
112
|
-
|
|
113
|
-
return Array.from((_a = root == null ? void 0 : root.querySelectorAll(selector)) != null ? _a : []);
|
|
122
|
+
return Array.from((root == null ? void 0 : root.querySelectorAll(selector)) ?? []);
|
|
114
123
|
}
|
|
115
124
|
function itemById(v, id) {
|
|
116
125
|
return v.find((node) => node.id === id);
|
|
@@ -137,40 +146,32 @@ var first = (v) => v[0];
|
|
|
137
146
|
var last = (v) => v[v.length - 1];
|
|
138
147
|
|
|
139
148
|
// src/tabs.dom.ts
|
|
140
|
-
var dom = {
|
|
141
|
-
getDoc: (ctx) => {
|
|
142
|
-
var _a;
|
|
143
|
-
return (_a = ctx.doc) != null ? _a : document;
|
|
144
|
-
},
|
|
145
|
-
getRootNode: (ctx) => {
|
|
146
|
-
var _a;
|
|
147
|
-
return (_a = ctx.rootNode) != null ? _a : dom.getDoc(ctx);
|
|
148
|
-
},
|
|
149
|
+
var dom = defineDomHelpers({
|
|
149
150
|
getRootId: (ctx) => {
|
|
150
|
-
var _a
|
|
151
|
-
return (
|
|
151
|
+
var _a;
|
|
152
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.root) ?? `tabs:${ctx.id}`;
|
|
152
153
|
},
|
|
153
154
|
getTriggerGroupId: (ctx) => {
|
|
154
|
-
var _a
|
|
155
|
-
return (
|
|
155
|
+
var _a;
|
|
156
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.triggerGroup) ?? `tabs:${ctx.id}:trigger-group`;
|
|
156
157
|
},
|
|
157
158
|
getContentId: (ctx, id) => {
|
|
158
|
-
var _a
|
|
159
|
-
return (
|
|
159
|
+
var _a;
|
|
160
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.content) ?? `tabs:${ctx.id}:content-${id}`;
|
|
160
161
|
},
|
|
161
162
|
getContentGroupId: (ctx) => {
|
|
162
|
-
var _a
|
|
163
|
-
return (
|
|
163
|
+
var _a;
|
|
164
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.contentGroup) ?? `tabs:${ctx.id}:content-group`;
|
|
164
165
|
},
|
|
165
166
|
getTriggerId: (ctx, id) => {
|
|
166
|
-
var _a
|
|
167
|
-
return (
|
|
167
|
+
var _a;
|
|
168
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.trigger) ?? `tabs:${ctx.id}:trigger-${id}`;
|
|
168
169
|
},
|
|
169
|
-
getIndicatorId: (ctx) => `tabs:${ctx.
|
|
170
|
-
getTriggerGroupEl: (ctx) => dom.
|
|
171
|
-
getContentEl: (ctx, id) => dom.
|
|
172
|
-
getTriggerEl: (ctx, id) => dom.
|
|
173
|
-
getIndicatorEl: (ctx) => dom.
|
|
170
|
+
getIndicatorId: (ctx) => `tabs:${ctx.id}:indicator`,
|
|
171
|
+
getTriggerGroupEl: (ctx) => dom.getById(ctx, dom.getTriggerGroupId(ctx)),
|
|
172
|
+
getContentEl: (ctx, id) => dom.getById(ctx, dom.getContentId(ctx, id)),
|
|
173
|
+
getTriggerEl: (ctx, id) => dom.getById(ctx, dom.getTriggerId(ctx, id)),
|
|
174
|
+
getIndicatorEl: (ctx) => dom.getById(ctx, dom.getIndicatorId(ctx)),
|
|
174
175
|
getElements: (ctx) => {
|
|
175
176
|
const ownerId = CSS.escape(dom.getTriggerGroupId(ctx));
|
|
176
177
|
const selector = `[role=tab][data-ownedby='${ownerId}']:not([disabled])`;
|
|
@@ -184,17 +185,16 @@ var dom = {
|
|
|
184
185
|
if (!ctx.value)
|
|
185
186
|
return;
|
|
186
187
|
const id = dom.getContentId(ctx, ctx.value);
|
|
187
|
-
return dom.
|
|
188
|
+
return dom.getById(ctx, id);
|
|
188
189
|
},
|
|
189
190
|
getRectById: (ctx, id) => {
|
|
190
|
-
var _a;
|
|
191
191
|
const empty = {
|
|
192
192
|
offsetLeft: 0,
|
|
193
193
|
offsetTop: 0,
|
|
194
194
|
offsetWidth: 0,
|
|
195
195
|
offsetHeight: 0
|
|
196
196
|
};
|
|
197
|
-
const tab =
|
|
197
|
+
const tab = itemById(dom.getElements(ctx), dom.getTriggerId(ctx, id)) ?? empty;
|
|
198
198
|
if (ctx.isVertical) {
|
|
199
199
|
return {
|
|
200
200
|
top: `${tab.offsetTop}px`,
|
|
@@ -206,7 +206,7 @@ var dom = {
|
|
|
206
206
|
width: `${tab.offsetWidth}px`
|
|
207
207
|
};
|
|
208
208
|
}
|
|
209
|
-
};
|
|
209
|
+
});
|
|
210
210
|
|
|
211
211
|
// src/tabs.connect.ts
|
|
212
212
|
function connect(state, send, normalize) {
|
|
@@ -337,225 +337,220 @@ function connect(state, send, normalize) {
|
|
|
337
337
|
id: dom.getIndicatorId(state.context),
|
|
338
338
|
"data-part": "indicator",
|
|
339
339
|
"data-orientation": state.context.orientation,
|
|
340
|
-
style:
|
|
340
|
+
style: {
|
|
341
341
|
"--transition-duration": "200ms",
|
|
342
342
|
"--transition-property": "left, right, top, bottom, width, height",
|
|
343
343
|
position: "absolute",
|
|
344
344
|
willChange: "var(--transition-property)",
|
|
345
345
|
transitionProperty: "var(--transition-property)",
|
|
346
346
|
transitionDuration: state.context.hasMeasuredRect ? "var(--transition-duration)" : "0ms",
|
|
347
|
-
transitionTimingFunction: "var(--transition-timing-function)"
|
|
348
|
-
|
|
347
|
+
transitionTimingFunction: "var(--transition-timing-function)",
|
|
348
|
+
...state.context.indicatorRect
|
|
349
|
+
}
|
|
349
350
|
})
|
|
350
351
|
};
|
|
351
352
|
}
|
|
352
353
|
|
|
353
354
|
// src/tabs.machine.ts
|
|
354
|
-
import { createMachine, guards
|
|
355
|
+
import { createMachine, guards } from "@zag-js/core";
|
|
355
356
|
var { not } = guards;
|
|
356
|
-
function machine(ctx
|
|
357
|
-
return createMachine(
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
computed: {
|
|
374
|
-
isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
|
|
375
|
-
isVertical: (ctx2) => ctx2.orientation === "vertical"
|
|
376
|
-
},
|
|
377
|
-
created: ["setPrevSelectedTabs"],
|
|
378
|
-
watch: {
|
|
379
|
-
focusedValue: "invokeOnFocus",
|
|
380
|
-
value: ["invokeOnChange", "setPrevSelectedTabs", "setIndicatorRect", "setContentTabIndex"],
|
|
381
|
-
dir: ["clearMeasured", "setIndicatorRect"]
|
|
382
|
-
},
|
|
383
|
-
on: {
|
|
384
|
-
SET_VALUE: {
|
|
385
|
-
actions: "setValue"
|
|
357
|
+
function machine(ctx) {
|
|
358
|
+
return createMachine(
|
|
359
|
+
{
|
|
360
|
+
initial: "unknown",
|
|
361
|
+
context: {
|
|
362
|
+
dir: "ltr",
|
|
363
|
+
orientation: "horizontal",
|
|
364
|
+
activationMode: "automatic",
|
|
365
|
+
value: null,
|
|
366
|
+
focusedValue: null,
|
|
367
|
+
previousValues: [],
|
|
368
|
+
indicatorRect: { left: "0px", top: "0px", width: "0px", height: "0px" },
|
|
369
|
+
hasMeasuredRect: false,
|
|
370
|
+
isIndicatorRendered: false,
|
|
371
|
+
loop: true,
|
|
372
|
+
messages: {},
|
|
373
|
+
...ctx
|
|
386
374
|
},
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
},
|
|
391
|
-
states: {
|
|
392
|
-
unknown: {
|
|
393
|
-
on: {
|
|
394
|
-
SETUP: {
|
|
395
|
-
target: "idle",
|
|
396
|
-
actions: ["setupDocument", "checkRenderedElements", "setIndicatorRect", "setContentTabIndex"]
|
|
397
|
-
}
|
|
398
|
-
}
|
|
375
|
+
computed: {
|
|
376
|
+
isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
|
|
377
|
+
isVertical: (ctx2) => ctx2.orientation === "vertical"
|
|
399
378
|
},
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
379
|
+
created: ["setPrevSelectedTabs"],
|
|
380
|
+
watch: {
|
|
381
|
+
focusedValue: "invokeOnFocus",
|
|
382
|
+
value: ["invokeOnChange", "setPrevSelectedTabs", "setIndicatorRect", "setContentTabIndex"],
|
|
383
|
+
dir: ["clearMeasured", "setIndicatorRect"]
|
|
384
|
+
},
|
|
385
|
+
on: {
|
|
386
|
+
SET_VALUE: {
|
|
387
|
+
actions: "setValue"
|
|
388
|
+
},
|
|
389
|
+
DELETE: {
|
|
390
|
+
actions: "deleteValue"
|
|
411
391
|
}
|
|
412
392
|
},
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
actions: "focusNextTab"
|
|
426
|
-
},
|
|
427
|
-
ARROW_UP: {
|
|
428
|
-
guard: "isVertical",
|
|
429
|
-
actions: "focusPrevTab"
|
|
430
|
-
},
|
|
431
|
-
ARROW_DOWN: {
|
|
432
|
-
guard: "isVertical",
|
|
433
|
-
actions: "focusNextTab"
|
|
434
|
-
},
|
|
435
|
-
HOME: {
|
|
436
|
-
actions: "focusFirstTab"
|
|
437
|
-
},
|
|
438
|
-
END: {
|
|
439
|
-
actions: "focusLastTab"
|
|
440
|
-
},
|
|
441
|
-
ENTER: {
|
|
442
|
-
guard: not("selectOnFocus"),
|
|
443
|
-
actions: "setValue"
|
|
444
|
-
},
|
|
445
|
-
TAB_FOCUS: [
|
|
446
|
-
{
|
|
393
|
+
states: {
|
|
394
|
+
unknown: {
|
|
395
|
+
on: {
|
|
396
|
+
SETUP: {
|
|
397
|
+
target: "idle",
|
|
398
|
+
actions: ["checkRenderedElements", "setIndicatorRect", "setContentTabIndex"]
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
},
|
|
402
|
+
idle: {
|
|
403
|
+
on: {
|
|
404
|
+
TAB_FOCUS: {
|
|
447
405
|
guard: "selectOnFocus",
|
|
406
|
+
target: "focused",
|
|
448
407
|
actions: ["setFocusedValue", "setValue"]
|
|
449
408
|
},
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
409
|
+
TAB_CLICK: {
|
|
410
|
+
target: "focused",
|
|
411
|
+
actions: ["setFocusedValue", "setValue"]
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
},
|
|
415
|
+
focused: {
|
|
416
|
+
on: {
|
|
417
|
+
TAB_CLICK: {
|
|
418
|
+
target: "focused",
|
|
419
|
+
actions: ["setFocusedValue", "setValue"]
|
|
420
|
+
},
|
|
421
|
+
ARROW_LEFT: {
|
|
422
|
+
guard: "isHorizontal",
|
|
423
|
+
actions: "focusPrevTab"
|
|
424
|
+
},
|
|
425
|
+
ARROW_RIGHT: {
|
|
426
|
+
guard: "isHorizontal",
|
|
427
|
+
actions: "focusNextTab"
|
|
428
|
+
},
|
|
429
|
+
ARROW_UP: {
|
|
430
|
+
guard: "isVertical",
|
|
431
|
+
actions: "focusPrevTab"
|
|
432
|
+
},
|
|
433
|
+
ARROW_DOWN: {
|
|
434
|
+
guard: "isVertical",
|
|
435
|
+
actions: "focusNextTab"
|
|
436
|
+
},
|
|
437
|
+
HOME: {
|
|
438
|
+
actions: "focusFirstTab"
|
|
439
|
+
},
|
|
440
|
+
END: {
|
|
441
|
+
actions: "focusLastTab"
|
|
442
|
+
},
|
|
443
|
+
ENTER: {
|
|
444
|
+
guard: not("selectOnFocus"),
|
|
445
|
+
actions: "setValue"
|
|
446
|
+
},
|
|
447
|
+
TAB_FOCUS: [
|
|
448
|
+
{
|
|
449
|
+
guard: "selectOnFocus",
|
|
450
|
+
actions: ["setFocusedValue", "setValue"]
|
|
451
|
+
},
|
|
452
|
+
{ actions: "setFocusedValue" }
|
|
453
|
+
],
|
|
454
|
+
TAB_BLUR: {
|
|
455
|
+
target: "idle",
|
|
456
|
+
actions: "clearFocusedValue"
|
|
457
|
+
}
|
|
455
458
|
}
|
|
456
459
|
}
|
|
457
460
|
}
|
|
458
|
-
}
|
|
459
|
-
}, {
|
|
460
|
-
guards: {
|
|
461
|
-
isVertical: (ctx2) => ctx2.isVertical,
|
|
462
|
-
isHorizontal: (ctx2) => ctx2.isHorizontal,
|
|
463
|
-
selectOnFocus: (ctx2) => ctx2.activationMode === "automatic"
|
|
464
461
|
},
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
ctx2
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
if (evt.root)
|
|
471
|
-
ctx2.rootNode = ref(evt.root);
|
|
472
|
-
},
|
|
473
|
-
setFocusedValue(ctx2, evt) {
|
|
474
|
-
ctx2.focusedValue = evt.value;
|
|
475
|
-
},
|
|
476
|
-
clearFocusedValue(ctx2) {
|
|
477
|
-
ctx2.focusedValue = null;
|
|
478
|
-
},
|
|
479
|
-
setValue(ctx2, evt) {
|
|
480
|
-
ctx2.value = evt.value;
|
|
462
|
+
{
|
|
463
|
+
guards: {
|
|
464
|
+
isVertical: (ctx2) => ctx2.isVertical,
|
|
465
|
+
isHorizontal: (ctx2) => ctx2.isHorizontal,
|
|
466
|
+
selectOnFocus: (ctx2) => ctx2.activationMode === "automatic"
|
|
481
467
|
},
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
raf(() => {
|
|
468
|
+
actions: {
|
|
469
|
+
setFocusedValue(ctx2, evt) {
|
|
470
|
+
ctx2.focusedValue = evt.value;
|
|
471
|
+
},
|
|
472
|
+
clearFocusedValue(ctx2) {
|
|
473
|
+
ctx2.focusedValue = null;
|
|
474
|
+
},
|
|
475
|
+
setValue(ctx2, evt) {
|
|
476
|
+
ctx2.value = evt.value;
|
|
477
|
+
},
|
|
478
|
+
invokeOnDelete(ctx2, evt) {
|
|
494
479
|
var _a;
|
|
495
|
-
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
nextTick(() => {
|
|
512
|
-
if (!ctx2.isIndicatorRendered || !ctx2.value)
|
|
480
|
+
(_a = ctx2.onDelete) == null ? void 0 : _a.call(ctx2, { value: evt.value });
|
|
481
|
+
},
|
|
482
|
+
focusFirstTab(ctx2) {
|
|
483
|
+
raf(() => {
|
|
484
|
+
var _a;
|
|
485
|
+
return (_a = dom.getFirstEl(ctx2)) == null ? void 0 : _a.focus();
|
|
486
|
+
});
|
|
487
|
+
},
|
|
488
|
+
focusLastTab(ctx2) {
|
|
489
|
+
raf(() => {
|
|
490
|
+
var _a;
|
|
491
|
+
return (_a = dom.getLastEl(ctx2)) == null ? void 0 : _a.focus();
|
|
492
|
+
});
|
|
493
|
+
},
|
|
494
|
+
focusNextTab(ctx2) {
|
|
495
|
+
if (!ctx2.focusedValue)
|
|
513
496
|
return;
|
|
514
|
-
|
|
515
|
-
|
|
497
|
+
const next = dom.getNextEl(ctx2, ctx2.focusedValue);
|
|
498
|
+
raf(() => next == null ? void 0 : next.focus());
|
|
499
|
+
},
|
|
500
|
+
focusPrevTab(ctx2) {
|
|
501
|
+
if (!ctx2.focusedValue)
|
|
516
502
|
return;
|
|
503
|
+
const prev = dom.getPrevEl(ctx2, ctx2.focusedValue);
|
|
504
|
+
raf(() => prev == null ? void 0 : prev.focus());
|
|
505
|
+
},
|
|
506
|
+
setIndicatorRect(ctx2) {
|
|
517
507
|
nextTick(() => {
|
|
518
|
-
ctx2.
|
|
508
|
+
if (!ctx2.isIndicatorRendered || !ctx2.value)
|
|
509
|
+
return;
|
|
510
|
+
ctx2.indicatorRect = dom.getRectById(ctx2, ctx2.value);
|
|
511
|
+
if (ctx2.hasMeasuredRect)
|
|
512
|
+
return;
|
|
513
|
+
nextTick(() => {
|
|
514
|
+
ctx2.hasMeasuredRect = true;
|
|
515
|
+
});
|
|
519
516
|
});
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
checkRenderedElements(ctx2) {
|
|
523
|
-
nextTick(() => {
|
|
517
|
+
},
|
|
518
|
+
checkRenderedElements(ctx2) {
|
|
524
519
|
ctx2.isIndicatorRendered = !!dom.getIndicatorEl(ctx2);
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
ctx2.previousValues = Array.from(new Set(newSelected));
|
|
542
|
-
}
|
|
543
|
-
},
|
|
544
|
-
setContentTabIndex(ctx2) {
|
|
545
|
-
raf(() => {
|
|
546
|
-
const panel = dom.getActiveContentEl(ctx2);
|
|
547
|
-
if (!panel)
|
|
548
|
-
return;
|
|
549
|
-
const focusables = getFocusables(panel);
|
|
550
|
-
if (focusables.length > 0) {
|
|
551
|
-
panel.removeAttribute("tabindex");
|
|
552
|
-
} else {
|
|
553
|
-
panel.setAttribute("tabindex", "0");
|
|
520
|
+
},
|
|
521
|
+
clearMeasured(ctx2) {
|
|
522
|
+
ctx2.hasMeasuredRect = false;
|
|
523
|
+
},
|
|
524
|
+
invokeOnChange(ctx2) {
|
|
525
|
+
var _a;
|
|
526
|
+
(_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
|
|
527
|
+
},
|
|
528
|
+
invokeOnFocus(ctx2) {
|
|
529
|
+
var _a;
|
|
530
|
+
(_a = ctx2.onFocus) == null ? void 0 : _a.call(ctx2, { value: ctx2.focusedValue });
|
|
531
|
+
},
|
|
532
|
+
setPrevSelectedTabs(ctx2) {
|
|
533
|
+
if (ctx2.value != null) {
|
|
534
|
+
const newSelected = Array.from(ctx2.previousValues).concat(ctx2.value);
|
|
535
|
+
ctx2.previousValues = Array.from(new Set(newSelected));
|
|
554
536
|
}
|
|
555
|
-
}
|
|
537
|
+
},
|
|
538
|
+
setContentTabIndex(ctx2) {
|
|
539
|
+
raf(() => {
|
|
540
|
+
const panel = dom.getActiveContentEl(ctx2);
|
|
541
|
+
if (!panel)
|
|
542
|
+
return;
|
|
543
|
+
const focusables = getFocusables(panel);
|
|
544
|
+
if (focusables.length > 0) {
|
|
545
|
+
panel.removeAttribute("tabindex");
|
|
546
|
+
} else {
|
|
547
|
+
panel.setAttribute("tabindex", "0");
|
|
548
|
+
}
|
|
549
|
+
});
|
|
550
|
+
}
|
|
556
551
|
}
|
|
557
552
|
}
|
|
558
|
-
|
|
553
|
+
);
|
|
559
554
|
}
|
|
560
555
|
export {
|
|
561
556
|
connect,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/tabs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
4
4
|
"description": "Core logic for the tabs widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -29,18 +29,21 @@
|
|
|
29
29
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@zag-js/core": "0.1.
|
|
33
|
-
"@zag-js/
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
"@zag-js/core": "0.1.9",
|
|
33
|
+
"@zag-js/types": "0.2.4"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@zag-js/dom-utils": "0.1.10",
|
|
37
|
+
"@zag-js/utils": "0.1.3"
|
|
36
38
|
},
|
|
37
39
|
"scripts": {
|
|
38
|
-
"build
|
|
39
|
-
"start": "
|
|
40
|
-
"build": "
|
|
40
|
+
"build-fast": "tsup src/index.ts --format=esm,cjs",
|
|
41
|
+
"start": "pnpm build --watch",
|
|
42
|
+
"build": "tsup src/index.ts --format=esm,cjs --dts",
|
|
41
43
|
"test": "jest --config ../../../jest.config.js --rootDir . --passWithNoTests",
|
|
42
44
|
"lint": "eslint src --ext .ts,.tsx",
|
|
43
|
-
"test
|
|
44
|
-
"test
|
|
45
|
+
"test-ci": "pnpm test --ci --runInBand",
|
|
46
|
+
"test-watch": "pnpm test --watch -u",
|
|
47
|
+
"typecheck": "tsc --noEmit"
|
|
45
48
|
}
|
|
46
|
-
}
|
|
49
|
+
}
|
package/dist/tabs.connect.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { NormalizeProps, PropTypes } from "@zag-js/types";
|
|
2
|
-
import type { Send, State, TabProps } from "./tabs.types";
|
|
3
|
-
export declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
|
|
4
|
-
value: string;
|
|
5
|
-
focusedValue: string;
|
|
6
|
-
previousValues: string[];
|
|
7
|
-
setValue(value: string): void;
|
|
8
|
-
rootProps: T["element"];
|
|
9
|
-
triggerGroupProps: T["element"];
|
|
10
|
-
getTriggerProps(props: TabProps): T["button"];
|
|
11
|
-
contentGroupProps: T["element"];
|
|
12
|
-
getContentProps({ value }: {
|
|
13
|
-
value: string;
|
|
14
|
-
}): T["element"];
|
|
15
|
-
getDeleteButtonProps({ value, disabled }: TabProps): T["button"];
|
|
16
|
-
indicatorProps: T["element"];
|
|
17
|
-
};
|
package/dist/tabs.dom.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { MachineContext as Ctx } from "./tabs.types";
|
|
2
|
-
export declare const dom: {
|
|
3
|
-
getDoc: (ctx: Ctx) => Document;
|
|
4
|
-
getRootNode: (ctx: Ctx) => Document | ShadowRoot;
|
|
5
|
-
getRootId: (ctx: Ctx) => string;
|
|
6
|
-
getTriggerGroupId: (ctx: Ctx) => string;
|
|
7
|
-
getContentId: (ctx: Ctx, id: string) => string;
|
|
8
|
-
getContentGroupId: (ctx: Ctx) => string;
|
|
9
|
-
getTriggerId: (ctx: Ctx, id: string) => string;
|
|
10
|
-
getIndicatorId: (ctx: Ctx) => string;
|
|
11
|
-
getTriggerGroupEl: (ctx: Ctx) => HTMLElement;
|
|
12
|
-
getContentEl: (ctx: Ctx, id: string) => HTMLElement;
|
|
13
|
-
getTriggerEl: (ctx: Ctx, id: string) => HTMLElement;
|
|
14
|
-
getIndicatorEl: (ctx: Ctx) => HTMLElement;
|
|
15
|
-
getElements: (ctx: Ctx) => HTMLElement[];
|
|
16
|
-
getFirstEl: (ctx: Ctx) => HTMLElement;
|
|
17
|
-
getLastEl: (ctx: Ctx) => HTMLElement;
|
|
18
|
-
getNextEl: (ctx: Ctx, id: string) => HTMLElement;
|
|
19
|
-
getPrevEl: (ctx: Ctx, id: string) => HTMLElement;
|
|
20
|
-
getActiveContentEl: (ctx: Ctx) => HTMLElement;
|
|
21
|
-
getRectById: (ctx: Ctx, id: string) => {
|
|
22
|
-
top: string;
|
|
23
|
-
height: string;
|
|
24
|
-
left?: undefined;
|
|
25
|
-
width?: undefined;
|
|
26
|
-
} | {
|
|
27
|
-
left: string;
|
|
28
|
-
width: string;
|
|
29
|
-
top?: undefined;
|
|
30
|
-
height?: undefined;
|
|
31
|
-
};
|
|
32
|
-
};
|
package/dist/tabs.machine.d.ts
DELETED