@zag-js/tabs 0.10.2 → 0.10.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.ts +4 -7
- package/dist/index.js +8 -491
- package/dist/index.mjs +3 -15
- package/dist/tabs.anatomy.d.ts +3 -6
- package/dist/tabs.anatomy.js +10 -33
- package/dist/tabs.anatomy.mjs +6 -8
- package/dist/tabs.connect.d.ts +3 -7
- package/dist/tabs.connect.js +30 -112
- package/dist/tabs.connect.mjs +159 -8
- package/dist/tabs.dom.d.ts +20 -25
- package/dist/tabs.dom.js +15 -37
- package/dist/tabs.dom.mjs +56 -6
- package/dist/tabs.machine.d.ts +3 -7
- package/dist/tabs.machine.js +31 -109
- package/dist/tabs.machine.mjs +247 -7
- package/dist/tabs.types.d.ts +10 -12
- package/package.json +10 -15
- package/dist/chunk-EU4R7SET.mjs +0 -58
- package/dist/chunk-GMBCGZJ4.mjs +0 -166
- package/dist/chunk-HGL32F6R.mjs +0 -252
- package/dist/chunk-S2KW2DT4.mjs +0 -9
- package/dist/tabs.types.js +0 -18
- package/dist/tabs.types.mjs +0 -0
package/dist/tabs.machine.js
CHANGED
|
@@ -1,94 +1,18 @@
|
|
|
1
|
-
|
|
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);
|
|
1
|
+
'use strict';
|
|
19
2
|
|
|
20
|
-
|
|
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
|
-
var import_dom_query2 = require("@zag-js/dom-query");
|
|
28
|
-
var import_element_rect = require("@zag-js/element-rect");
|
|
29
|
-
var import_tabbable = require("@zag-js/tabbable");
|
|
30
|
-
var import_utils2 = require("@zag-js/utils");
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
31
4
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
getContentId: (ctx, id) => ctx.ids?.content ?? `tabs:${ctx.id}:content-${id}`,
|
|
39
|
-
getContentGroupId: (ctx) => ctx.ids?.contentGroup ?? `tabs:${ctx.id}:content-group`,
|
|
40
|
-
getTriggerId: (ctx, id) => ctx.ids?.trigger ?? `tabs:${ctx.id}:trigger-${id}`,
|
|
41
|
-
getIndicatorId: (ctx) => ctx.ids?.indicator ?? `tabs:${ctx.id}:indicator`,
|
|
42
|
-
getTablistEl: (ctx) => dom.getById(ctx, dom.getTablistId(ctx)),
|
|
43
|
-
getContentEl: (ctx, id) => dom.getById(ctx, dom.getContentId(ctx, id)),
|
|
44
|
-
getTriggerEl: (ctx, id) => dom.getById(ctx, dom.getTriggerId(ctx, id)),
|
|
45
|
-
getIndicatorEl: (ctx) => dom.getById(ctx, dom.getIndicatorId(ctx)),
|
|
46
|
-
getElements: (ctx) => {
|
|
47
|
-
const ownerId = CSS.escape(dom.getTablistId(ctx));
|
|
48
|
-
const selector = `[role=tab][data-ownedby='${ownerId}']:not([disabled])`;
|
|
49
|
-
return (0, import_dom_query.queryAll)(dom.getTablistEl(ctx), selector);
|
|
50
|
-
},
|
|
51
|
-
getFirstEl: (ctx) => (0, import_utils.first)(dom.getElements(ctx)),
|
|
52
|
-
getLastEl: (ctx) => (0, import_utils.last)(dom.getElements(ctx)),
|
|
53
|
-
getNextEl: (ctx, id) => (0, import_dom_query.nextById)(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
|
|
54
|
-
getPrevEl: (ctx, id) => (0, import_dom_query.prevById)(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
|
|
55
|
-
getActiveContentEl: (ctx) => {
|
|
56
|
-
if (!ctx.value)
|
|
57
|
-
return;
|
|
58
|
-
return dom.getContentEl(ctx, ctx.value);
|
|
59
|
-
},
|
|
60
|
-
getActiveTabEl: (ctx) => {
|
|
61
|
-
if (!ctx.value)
|
|
62
|
-
return;
|
|
63
|
-
return dom.getTriggerEl(ctx, ctx.value);
|
|
64
|
-
},
|
|
65
|
-
getOffsetRect: (el) => {
|
|
66
|
-
return {
|
|
67
|
-
left: el?.offsetLeft ?? 0,
|
|
68
|
-
top: el?.offsetTop ?? 0,
|
|
69
|
-
width: el?.offsetWidth ?? 0,
|
|
70
|
-
height: el?.offsetHeight ?? 0
|
|
71
|
-
};
|
|
72
|
-
},
|
|
73
|
-
getRectById: (ctx, id) => {
|
|
74
|
-
const tab = (0, import_dom_query.itemById)(dom.getElements(ctx), dom.getTriggerId(ctx, id));
|
|
75
|
-
return dom.resolveRect(dom.getOffsetRect(tab), ctx.orientation);
|
|
76
|
-
},
|
|
77
|
-
resolveRect(rect, orientation) {
|
|
78
|
-
const sizeProp = orientation === "vertical" ? "height" : "width";
|
|
79
|
-
const placementProp = orientation === "vertical" ? "top" : "left";
|
|
80
|
-
return {
|
|
81
|
-
[placementProp]: `${rect[placementProp]}px`,
|
|
82
|
-
[sizeProp]: `${rect[sizeProp]}px`
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
});
|
|
5
|
+
const core = require('@zag-js/core');
|
|
6
|
+
const domQuery = require('@zag-js/dom-query');
|
|
7
|
+
const elementRect = require('@zag-js/element-rect');
|
|
8
|
+
const tabbable = require('@zag-js/tabbable');
|
|
9
|
+
const utils = require('@zag-js/utils');
|
|
10
|
+
const tabs_dom = require('./tabs.dom.js');
|
|
86
11
|
|
|
87
|
-
|
|
88
|
-
var { not } = import_core.guards;
|
|
12
|
+
const { not } = core.guards;
|
|
89
13
|
function machine(userContext) {
|
|
90
|
-
const ctx =
|
|
91
|
-
return
|
|
14
|
+
const ctx = utils.compact(userContext);
|
|
15
|
+
return core.createMachine(
|
|
92
16
|
{
|
|
93
17
|
initial: "idle",
|
|
94
18
|
context: {
|
|
@@ -227,25 +151,25 @@ function machine(userContext) {
|
|
|
227
151
|
ctx2.value = null;
|
|
228
152
|
},
|
|
229
153
|
focusFirstTab(ctx2) {
|
|
230
|
-
|
|
154
|
+
domQuery.raf(() => tabs_dom.dom.getFirstEl(ctx2)?.focus());
|
|
231
155
|
},
|
|
232
156
|
focusLastTab(ctx2) {
|
|
233
|
-
|
|
157
|
+
domQuery.raf(() => tabs_dom.dom.getLastEl(ctx2)?.focus());
|
|
234
158
|
},
|
|
235
159
|
focusNextTab(ctx2) {
|
|
236
160
|
if (!ctx2.focusedValue)
|
|
237
161
|
return;
|
|
238
|
-
const next = dom.getNextEl(ctx2, ctx2.focusedValue);
|
|
239
|
-
|
|
162
|
+
const next = tabs_dom.dom.getNextEl(ctx2, ctx2.focusedValue);
|
|
163
|
+
domQuery.raf(() => next?.focus());
|
|
240
164
|
},
|
|
241
165
|
focusPrevTab(ctx2) {
|
|
242
166
|
if (!ctx2.focusedValue)
|
|
243
167
|
return;
|
|
244
|
-
const prev = dom.getPrevEl(ctx2, ctx2.focusedValue);
|
|
245
|
-
|
|
168
|
+
const prev = tabs_dom.dom.getPrevEl(ctx2, ctx2.focusedValue);
|
|
169
|
+
domQuery.raf(() => prev?.focus());
|
|
246
170
|
},
|
|
247
171
|
checkRenderedElements(ctx2) {
|
|
248
|
-
ctx2.isIndicatorRendered = !!dom.getIndicatorEl(ctx2);
|
|
172
|
+
ctx2.isIndicatorRendered = !!tabs_dom.dom.getIndicatorEl(ctx2);
|
|
249
173
|
},
|
|
250
174
|
invokeOnChange(ctx2) {
|
|
251
175
|
ctx2.onChange?.({ value: ctx2.value });
|
|
@@ -260,11 +184,11 @@ function machine(userContext) {
|
|
|
260
184
|
},
|
|
261
185
|
// if tab panel contains focusable elements, remove the tabindex attribute
|
|
262
186
|
setContentTabIndex(ctx2) {
|
|
263
|
-
|
|
264
|
-
const panel = dom.getActiveContentEl(ctx2);
|
|
187
|
+
domQuery.raf(() => {
|
|
188
|
+
const panel = tabs_dom.dom.getActiveContentEl(ctx2);
|
|
265
189
|
if (!panel)
|
|
266
190
|
return;
|
|
267
|
-
const focusables =
|
|
191
|
+
const focusables = tabbable.getFocusables(panel);
|
|
268
192
|
if (focusables.length > 0) {
|
|
269
193
|
panel.removeAttribute("tabindex");
|
|
270
194
|
} else {
|
|
@@ -282,11 +206,11 @@ function machine(userContext) {
|
|
|
282
206
|
const value = evt.id ?? ctx2.value;
|
|
283
207
|
if (!ctx2.isIndicatorRendered || !value)
|
|
284
208
|
return;
|
|
285
|
-
const tabEl = dom.getTriggerEl(ctx2, value);
|
|
209
|
+
const tabEl = tabs_dom.dom.getTriggerEl(ctx2, value);
|
|
286
210
|
if (!tabEl)
|
|
287
211
|
return;
|
|
288
|
-
ctx2.indicatorRect = dom.getRectById(ctx2, value);
|
|
289
|
-
|
|
212
|
+
ctx2.indicatorRect = tabs_dom.dom.getRectById(ctx2, value);
|
|
213
|
+
domQuery.nextTick(() => {
|
|
290
214
|
ctx2.canIndicatorTransition = false;
|
|
291
215
|
});
|
|
292
216
|
},
|
|
@@ -295,16 +219,16 @@ function machine(userContext) {
|
|
|
295
219
|
const value = ctx2.value;
|
|
296
220
|
if (!ctx2.isIndicatorRendered || !value)
|
|
297
221
|
return;
|
|
298
|
-
const tabEl = dom.getActiveTabEl(ctx2);
|
|
222
|
+
const tabEl = tabs_dom.dom.getActiveTabEl(ctx2);
|
|
299
223
|
if (!tabEl)
|
|
300
224
|
return;
|
|
301
|
-
ctx2.indicatorCleanup =
|
|
225
|
+
ctx2.indicatorCleanup = elementRect.trackElementRect(tabEl, {
|
|
302
226
|
getRect(el) {
|
|
303
|
-
return dom.getOffsetRect(el);
|
|
227
|
+
return tabs_dom.dom.getOffsetRect(el);
|
|
304
228
|
},
|
|
305
229
|
onChange(rect) {
|
|
306
|
-
ctx2.indicatorRect = dom.resolveRect(rect, ctx2.orientation);
|
|
307
|
-
|
|
230
|
+
ctx2.indicatorRect = tabs_dom.dom.resolveRect(rect, ctx2.orientation);
|
|
231
|
+
domQuery.nextTick(() => {
|
|
308
232
|
ctx2.canIndicatorTransition = false;
|
|
309
233
|
});
|
|
310
234
|
}
|
|
@@ -323,7 +247,5 @@ function pushUnique(arr, value) {
|
|
|
323
247
|
newArr.push(value);
|
|
324
248
|
return newArr;
|
|
325
249
|
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
machine
|
|
329
|
-
});
|
|
250
|
+
|
|
251
|
+
exports.machine = machine;
|
package/dist/tabs.machine.mjs
CHANGED
|
@@ -1,7 +1,247 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { createMachine, guards } from '@zag-js/core';
|
|
2
|
+
import { raf, nextTick } from '@zag-js/dom-query';
|
|
3
|
+
import { trackElementRect } from '@zag-js/element-rect';
|
|
4
|
+
import { getFocusables } from '@zag-js/tabbable';
|
|
5
|
+
import { compact } from '@zag-js/utils';
|
|
6
|
+
import { dom } from './tabs.dom.mjs';
|
|
7
|
+
|
|
8
|
+
const { not } = guards;
|
|
9
|
+
function machine(userContext) {
|
|
10
|
+
const ctx = compact(userContext);
|
|
11
|
+
return createMachine(
|
|
12
|
+
{
|
|
13
|
+
initial: "idle",
|
|
14
|
+
context: {
|
|
15
|
+
dir: "ltr",
|
|
16
|
+
orientation: "horizontal",
|
|
17
|
+
activationMode: "automatic",
|
|
18
|
+
value: null,
|
|
19
|
+
focusedValue: null,
|
|
20
|
+
previousValues: [],
|
|
21
|
+
indicatorRect: {
|
|
22
|
+
left: "0px",
|
|
23
|
+
top: "0px",
|
|
24
|
+
width: "0px",
|
|
25
|
+
height: "0px"
|
|
26
|
+
},
|
|
27
|
+
canIndicatorTransition: false,
|
|
28
|
+
isIndicatorRendered: false,
|
|
29
|
+
loop: true,
|
|
30
|
+
translations: {},
|
|
31
|
+
...ctx
|
|
32
|
+
},
|
|
33
|
+
computed: {
|
|
34
|
+
isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
|
|
35
|
+
isVertical: (ctx2) => ctx2.orientation === "vertical"
|
|
36
|
+
},
|
|
37
|
+
created: ["setPrevSelectedTabs"],
|
|
38
|
+
entry: ["checkRenderedElements", "syncIndicatorRect", "setContentTabIndex"],
|
|
39
|
+
exit: ["cleanupObserver"],
|
|
40
|
+
watch: {
|
|
41
|
+
focusedValue: "invokeOnFocus",
|
|
42
|
+
value: [
|
|
43
|
+
"enableIndicatorTransition",
|
|
44
|
+
"invokeOnChange",
|
|
45
|
+
"setPrevSelectedTabs",
|
|
46
|
+
"syncIndicatorRect",
|
|
47
|
+
"setContentTabIndex"
|
|
48
|
+
],
|
|
49
|
+
dir: ["syncIndicatorRect"],
|
|
50
|
+
orientation: ["syncIndicatorRect"]
|
|
51
|
+
},
|
|
52
|
+
on: {
|
|
53
|
+
SET_VALUE: {
|
|
54
|
+
actions: "setValue"
|
|
55
|
+
},
|
|
56
|
+
CLEAR_VALUE: {
|
|
57
|
+
actions: "clearValue"
|
|
58
|
+
},
|
|
59
|
+
SET_INDICATOR_RECT: {
|
|
60
|
+
actions: "setIndicatorRect"
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
states: {
|
|
64
|
+
idle: {
|
|
65
|
+
on: {
|
|
66
|
+
TAB_FOCUS: [
|
|
67
|
+
{
|
|
68
|
+
guard: "selectOnFocus",
|
|
69
|
+
target: "focused",
|
|
70
|
+
actions: ["setFocusedValue", "setValue"]
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
target: "focused",
|
|
74
|
+
actions: "setFocusedValue"
|
|
75
|
+
}
|
|
76
|
+
],
|
|
77
|
+
TAB_CLICK: {
|
|
78
|
+
target: "focused",
|
|
79
|
+
actions: ["setFocusedValue", "setValue"]
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
focused: {
|
|
84
|
+
on: {
|
|
85
|
+
TAB_CLICK: {
|
|
86
|
+
target: "focused",
|
|
87
|
+
actions: ["setFocusedValue", "setValue"]
|
|
88
|
+
},
|
|
89
|
+
ARROW_LEFT: {
|
|
90
|
+
guard: "isHorizontal",
|
|
91
|
+
actions: "focusPrevTab"
|
|
92
|
+
},
|
|
93
|
+
ARROW_RIGHT: {
|
|
94
|
+
guard: "isHorizontal",
|
|
95
|
+
actions: "focusNextTab"
|
|
96
|
+
},
|
|
97
|
+
ARROW_UP: {
|
|
98
|
+
guard: "isVertical",
|
|
99
|
+
actions: "focusPrevTab"
|
|
100
|
+
},
|
|
101
|
+
ARROW_DOWN: {
|
|
102
|
+
guard: "isVertical",
|
|
103
|
+
actions: "focusNextTab"
|
|
104
|
+
},
|
|
105
|
+
HOME: {
|
|
106
|
+
actions: "focusFirstTab"
|
|
107
|
+
},
|
|
108
|
+
END: {
|
|
109
|
+
actions: "focusLastTab"
|
|
110
|
+
},
|
|
111
|
+
ENTER: {
|
|
112
|
+
guard: not("selectOnFocus"),
|
|
113
|
+
actions: "setValue"
|
|
114
|
+
},
|
|
115
|
+
TAB_FOCUS: [
|
|
116
|
+
{
|
|
117
|
+
guard: "selectOnFocus",
|
|
118
|
+
actions: ["setFocusedValue", "setValue"]
|
|
119
|
+
},
|
|
120
|
+
{ actions: "setFocusedValue" }
|
|
121
|
+
],
|
|
122
|
+
TAB_BLUR: {
|
|
123
|
+
target: "idle",
|
|
124
|
+
actions: "clearFocusedValue"
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
guards: {
|
|
132
|
+
isVertical: (ctx2) => ctx2.isVertical,
|
|
133
|
+
isHorizontal: (ctx2) => ctx2.isHorizontal,
|
|
134
|
+
selectOnFocus: (ctx2) => ctx2.activationMode === "automatic"
|
|
135
|
+
},
|
|
136
|
+
actions: {
|
|
137
|
+
setFocusedValue(ctx2, evt) {
|
|
138
|
+
ctx2.focusedValue = evt.value;
|
|
139
|
+
},
|
|
140
|
+
clearFocusedValue(ctx2) {
|
|
141
|
+
ctx2.focusedValue = null;
|
|
142
|
+
},
|
|
143
|
+
setValue(ctx2, evt) {
|
|
144
|
+
ctx2.value = evt.value;
|
|
145
|
+
},
|
|
146
|
+
clearValue(ctx2) {
|
|
147
|
+
ctx2.value = null;
|
|
148
|
+
},
|
|
149
|
+
focusFirstTab(ctx2) {
|
|
150
|
+
raf(() => dom.getFirstEl(ctx2)?.focus());
|
|
151
|
+
},
|
|
152
|
+
focusLastTab(ctx2) {
|
|
153
|
+
raf(() => dom.getLastEl(ctx2)?.focus());
|
|
154
|
+
},
|
|
155
|
+
focusNextTab(ctx2) {
|
|
156
|
+
if (!ctx2.focusedValue)
|
|
157
|
+
return;
|
|
158
|
+
const next = dom.getNextEl(ctx2, ctx2.focusedValue);
|
|
159
|
+
raf(() => next?.focus());
|
|
160
|
+
},
|
|
161
|
+
focusPrevTab(ctx2) {
|
|
162
|
+
if (!ctx2.focusedValue)
|
|
163
|
+
return;
|
|
164
|
+
const prev = dom.getPrevEl(ctx2, ctx2.focusedValue);
|
|
165
|
+
raf(() => prev?.focus());
|
|
166
|
+
},
|
|
167
|
+
checkRenderedElements(ctx2) {
|
|
168
|
+
ctx2.isIndicatorRendered = !!dom.getIndicatorEl(ctx2);
|
|
169
|
+
},
|
|
170
|
+
invokeOnChange(ctx2) {
|
|
171
|
+
ctx2.onChange?.({ value: ctx2.value });
|
|
172
|
+
},
|
|
173
|
+
invokeOnFocus(ctx2) {
|
|
174
|
+
ctx2.onFocus?.({ value: ctx2.focusedValue });
|
|
175
|
+
},
|
|
176
|
+
setPrevSelectedTabs(ctx2) {
|
|
177
|
+
if (ctx2.value != null) {
|
|
178
|
+
ctx2.previousValues = pushUnique(ctx2.previousValues, ctx2.value);
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
// if tab panel contains focusable elements, remove the tabindex attribute
|
|
182
|
+
setContentTabIndex(ctx2) {
|
|
183
|
+
raf(() => {
|
|
184
|
+
const panel = dom.getActiveContentEl(ctx2);
|
|
185
|
+
if (!panel)
|
|
186
|
+
return;
|
|
187
|
+
const focusables = getFocusables(panel);
|
|
188
|
+
if (focusables.length > 0) {
|
|
189
|
+
panel.removeAttribute("tabindex");
|
|
190
|
+
} else {
|
|
191
|
+
panel.setAttribute("tabindex", "0");
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
},
|
|
195
|
+
cleanupObserver(ctx2) {
|
|
196
|
+
ctx2.indicatorCleanup?.();
|
|
197
|
+
},
|
|
198
|
+
enableIndicatorTransition(ctx2) {
|
|
199
|
+
ctx2.canIndicatorTransition = true;
|
|
200
|
+
},
|
|
201
|
+
setIndicatorRect(ctx2, evt) {
|
|
202
|
+
const value = evt.id ?? ctx2.value;
|
|
203
|
+
if (!ctx2.isIndicatorRendered || !value)
|
|
204
|
+
return;
|
|
205
|
+
const tabEl = dom.getTriggerEl(ctx2, value);
|
|
206
|
+
if (!tabEl)
|
|
207
|
+
return;
|
|
208
|
+
ctx2.indicatorRect = dom.getRectById(ctx2, value);
|
|
209
|
+
nextTick(() => {
|
|
210
|
+
ctx2.canIndicatorTransition = false;
|
|
211
|
+
});
|
|
212
|
+
},
|
|
213
|
+
syncIndicatorRect(ctx2) {
|
|
214
|
+
ctx2.indicatorCleanup?.();
|
|
215
|
+
const value = ctx2.value;
|
|
216
|
+
if (!ctx2.isIndicatorRendered || !value)
|
|
217
|
+
return;
|
|
218
|
+
const tabEl = dom.getActiveTabEl(ctx2);
|
|
219
|
+
if (!tabEl)
|
|
220
|
+
return;
|
|
221
|
+
ctx2.indicatorCleanup = trackElementRect(tabEl, {
|
|
222
|
+
getRect(el) {
|
|
223
|
+
return dom.getOffsetRect(el);
|
|
224
|
+
},
|
|
225
|
+
onChange(rect) {
|
|
226
|
+
ctx2.indicatorRect = dom.resolveRect(rect, ctx2.orientation);
|
|
227
|
+
nextTick(() => {
|
|
228
|
+
ctx2.canIndicatorTransition = false;
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
function pushUnique(arr, value) {
|
|
238
|
+
const newArr = Array.from(arr).slice();
|
|
239
|
+
const index = newArr.indexOf(value);
|
|
240
|
+
if (index > -1) {
|
|
241
|
+
newArr.splice(index, 1);
|
|
242
|
+
}
|
|
243
|
+
newArr.push(value);
|
|
244
|
+
return newArr;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export { machine };
|
package/dist/tabs.types.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { StateMachine } from
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import type { StateMachine as S } from "@zag-js/core";
|
|
2
|
+
import type { CommonProperties, Context, DirectionProperty, RequiredBy } from "@zag-js/types";
|
|
4
3
|
type IntlTranslations = {
|
|
5
4
|
tablistLabel?: string;
|
|
6
5
|
};
|
|
@@ -12,11 +11,11 @@ type ElementIds = Partial<{
|
|
|
12
11
|
content: string;
|
|
13
12
|
indicator: string;
|
|
14
13
|
}>;
|
|
15
|
-
type TriggerProps = {
|
|
14
|
+
export type TriggerProps = {
|
|
16
15
|
value: string;
|
|
17
16
|
disabled?: boolean;
|
|
18
17
|
};
|
|
19
|
-
type ContentProps = {
|
|
18
|
+
export type ContentProps = {
|
|
20
19
|
value: string;
|
|
21
20
|
};
|
|
22
21
|
type PublicContext = DirectionProperty & CommonProperties & {
|
|
@@ -71,7 +70,7 @@ type PublicContext = DirectionProperty & CommonProperties & {
|
|
|
71
70
|
value: string;
|
|
72
71
|
}) => void;
|
|
73
72
|
};
|
|
74
|
-
type UserDefinedContext = RequiredBy<PublicContext, "id">;
|
|
73
|
+
export type UserDefinedContext = RequiredBy<PublicContext, "id">;
|
|
75
74
|
type ComputedContext = Readonly<{
|
|
76
75
|
/**
|
|
77
76
|
* @computed
|
|
@@ -85,11 +84,10 @@ type ComputedContext = Readonly<{
|
|
|
85
84
|
isVertical: boolean;
|
|
86
85
|
}>;
|
|
87
86
|
type PrivateContext = Context<{}>;
|
|
88
|
-
type MachineContext = PublicContext & ComputedContext & PrivateContext;
|
|
89
|
-
type MachineState = {
|
|
87
|
+
export type MachineContext = PublicContext & ComputedContext & PrivateContext;
|
|
88
|
+
export type MachineState = {
|
|
90
89
|
value: "idle" | "focused";
|
|
91
90
|
};
|
|
92
|
-
type State =
|
|
93
|
-
type Send =
|
|
94
|
-
|
|
95
|
-
export { ContentProps, MachineContext, MachineState, Send, State, TriggerProps, UserDefinedContext };
|
|
91
|
+
export type State = S.State<MachineContext, MachineState>;
|
|
92
|
+
export type Send = S.Send<S.AnyEventObject>;
|
|
93
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/tabs",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.4",
|
|
4
4
|
"description": "Core logic for the tabs widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -27,14 +27,14 @@
|
|
|
27
27
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@zag-js/anatomy": "0.10.
|
|
31
|
-
"@zag-js/dom-query": "0.10.
|
|
32
|
-
"@zag-js/dom-event": "0.10.
|
|
33
|
-
"@zag-js/element-rect": "0.10.
|
|
34
|
-
"@zag-js/tabbable": "0.10.
|
|
35
|
-
"@zag-js/utils": "0.10.
|
|
36
|
-
"@zag-js/core": "0.10.
|
|
37
|
-
"@zag-js/types": "0.10.
|
|
30
|
+
"@zag-js/anatomy": "0.10.4",
|
|
31
|
+
"@zag-js/dom-query": "0.10.4",
|
|
32
|
+
"@zag-js/dom-event": "0.10.4",
|
|
33
|
+
"@zag-js/element-rect": "0.10.4",
|
|
34
|
+
"@zag-js/tabbable": "0.10.4",
|
|
35
|
+
"@zag-js/utils": "0.10.4",
|
|
36
|
+
"@zag-js/core": "0.10.4",
|
|
37
|
+
"@zag-js/types": "0.10.4"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"clean-package": "2.2.0"
|
|
@@ -52,13 +52,8 @@
|
|
|
52
52
|
"./package.json": "./package.json"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
|
-
"build
|
|
56
|
-
"start": "pnpm build --watch",
|
|
57
|
-
"build": "tsup src --dts",
|
|
58
|
-
"test": "jest --config ../../../jest.config.js --rootDir . --passWithNoTests",
|
|
55
|
+
"build": "vite build -c ../../../vite.config.ts",
|
|
59
56
|
"lint": "eslint src --ext .ts,.tsx",
|
|
60
|
-
"test-ci": "pnpm test --ci --runInBand",
|
|
61
|
-
"test-watch": "pnpm test --watch -u",
|
|
62
57
|
"typecheck": "tsc --noEmit"
|
|
63
58
|
}
|
|
64
59
|
}
|
package/dist/chunk-EU4R7SET.mjs
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
// src/tabs.dom.ts
|
|
2
|
-
import { createScope, itemById, nextById, prevById, queryAll } from "@zag-js/dom-query";
|
|
3
|
-
import { first, last } from "@zag-js/utils";
|
|
4
|
-
var dom = createScope({
|
|
5
|
-
getRootId: (ctx) => ctx.ids?.root ?? `tabs:${ctx.id}`,
|
|
6
|
-
getTablistId: (ctx) => ctx.ids?.tablist ?? `tabs:${ctx.id}:list`,
|
|
7
|
-
getContentId: (ctx, id) => ctx.ids?.content ?? `tabs:${ctx.id}:content-${id}`,
|
|
8
|
-
getContentGroupId: (ctx) => ctx.ids?.contentGroup ?? `tabs:${ctx.id}:content-group`,
|
|
9
|
-
getTriggerId: (ctx, id) => ctx.ids?.trigger ?? `tabs:${ctx.id}:trigger-${id}`,
|
|
10
|
-
getIndicatorId: (ctx) => ctx.ids?.indicator ?? `tabs:${ctx.id}:indicator`,
|
|
11
|
-
getTablistEl: (ctx) => dom.getById(ctx, dom.getTablistId(ctx)),
|
|
12
|
-
getContentEl: (ctx, id) => dom.getById(ctx, dom.getContentId(ctx, id)),
|
|
13
|
-
getTriggerEl: (ctx, id) => dom.getById(ctx, dom.getTriggerId(ctx, id)),
|
|
14
|
-
getIndicatorEl: (ctx) => dom.getById(ctx, dom.getIndicatorId(ctx)),
|
|
15
|
-
getElements: (ctx) => {
|
|
16
|
-
const ownerId = CSS.escape(dom.getTablistId(ctx));
|
|
17
|
-
const selector = `[role=tab][data-ownedby='${ownerId}']:not([disabled])`;
|
|
18
|
-
return queryAll(dom.getTablistEl(ctx), selector);
|
|
19
|
-
},
|
|
20
|
-
getFirstEl: (ctx) => first(dom.getElements(ctx)),
|
|
21
|
-
getLastEl: (ctx) => last(dom.getElements(ctx)),
|
|
22
|
-
getNextEl: (ctx, id) => nextById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
|
|
23
|
-
getPrevEl: (ctx, id) => prevById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
|
|
24
|
-
getActiveContentEl: (ctx) => {
|
|
25
|
-
if (!ctx.value)
|
|
26
|
-
return;
|
|
27
|
-
return dom.getContentEl(ctx, ctx.value);
|
|
28
|
-
},
|
|
29
|
-
getActiveTabEl: (ctx) => {
|
|
30
|
-
if (!ctx.value)
|
|
31
|
-
return;
|
|
32
|
-
return dom.getTriggerEl(ctx, ctx.value);
|
|
33
|
-
},
|
|
34
|
-
getOffsetRect: (el) => {
|
|
35
|
-
return {
|
|
36
|
-
left: el?.offsetLeft ?? 0,
|
|
37
|
-
top: el?.offsetTop ?? 0,
|
|
38
|
-
width: el?.offsetWidth ?? 0,
|
|
39
|
-
height: el?.offsetHeight ?? 0
|
|
40
|
-
};
|
|
41
|
-
},
|
|
42
|
-
getRectById: (ctx, id) => {
|
|
43
|
-
const tab = itemById(dom.getElements(ctx), dom.getTriggerId(ctx, id));
|
|
44
|
-
return dom.resolveRect(dom.getOffsetRect(tab), ctx.orientation);
|
|
45
|
-
},
|
|
46
|
-
resolveRect(rect, orientation) {
|
|
47
|
-
const sizeProp = orientation === "vertical" ? "height" : "width";
|
|
48
|
-
const placementProp = orientation === "vertical" ? "top" : "left";
|
|
49
|
-
return {
|
|
50
|
-
[placementProp]: `${rect[placementProp]}px`,
|
|
51
|
-
[sizeProp]: `${rect[sizeProp]}px`
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
export {
|
|
57
|
-
dom
|
|
58
|
-
};
|