@zag-js/tabs 0.2.5 → 0.2.7
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-B2NPUA5Z.mjs +186 -0
- package/dist/chunk-OIIQ7RFL.mjs +145 -0
- package/dist/chunk-S2KW2DT4.mjs +9 -0
- package/dist/chunk-T4EOWSTO.mjs +285 -0
- package/dist/index.d.ts +7 -963
- package/dist/index.js +31 -33
- 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 +338 -0
- package/dist/tabs.connect.mjs +8 -0
- package/dist/tabs.dom.d.ts +51 -0
- package/dist/tabs.dom.js +157 -0
- package/dist/tabs.dom.mjs +6 -0
- package/dist/tabs.machine.d.ts +7 -0
- package/dist/tabs.machine.js +441 -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,338 @@
|
|
|
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.connect.ts
|
|
21
|
+
var tabs_connect_exports = {};
|
|
22
|
+
__export(tabs_connect_exports, {
|
|
23
|
+
connect: () => connect
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(tabs_connect_exports);
|
|
26
|
+
|
|
27
|
+
// ../../utilities/dom/src/attrs.ts
|
|
28
|
+
var dataAttr = (guard) => {
|
|
29
|
+
return guard ? "" : void 0;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// ../../utilities/core/src/array.ts
|
|
33
|
+
var first = (v) => v[0];
|
|
34
|
+
var last = (v) => v[v.length - 1];
|
|
35
|
+
|
|
36
|
+
// ../../utilities/dom/src/platform.ts
|
|
37
|
+
var isDom = () => typeof window !== "undefined";
|
|
38
|
+
function getPlatform() {
|
|
39
|
+
var _a;
|
|
40
|
+
const agent = navigator.userAgentData;
|
|
41
|
+
return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
|
|
42
|
+
}
|
|
43
|
+
var pt = (v) => isDom() && v.test(getPlatform());
|
|
44
|
+
var vn = (v) => isDom() && v.test(navigator.vendor);
|
|
45
|
+
var isSafari = () => isApple() && vn(/apple/i);
|
|
46
|
+
var isApple = () => pt(/mac|iphone|ipad|ipod/i);
|
|
47
|
+
|
|
48
|
+
// ../../utilities/dom/src/query.ts
|
|
49
|
+
function isDocument(el) {
|
|
50
|
+
return el.nodeType === Node.DOCUMENT_NODE;
|
|
51
|
+
}
|
|
52
|
+
function isWindow(value) {
|
|
53
|
+
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
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
|
+
};
|
|
77
|
+
return {
|
|
78
|
+
...dom2,
|
|
79
|
+
...helpers
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// ../../utilities/dom/src/keyboard-event.ts
|
|
84
|
+
var rtlKeyMap = {
|
|
85
|
+
ArrowLeft: "ArrowRight",
|
|
86
|
+
ArrowRight: "ArrowLeft"
|
|
87
|
+
};
|
|
88
|
+
var sameKeyMap = {
|
|
89
|
+
Up: "ArrowUp",
|
|
90
|
+
Down: "ArrowDown",
|
|
91
|
+
Esc: "Escape",
|
|
92
|
+
" ": "Space",
|
|
93
|
+
",": "Comma",
|
|
94
|
+
Left: "ArrowLeft",
|
|
95
|
+
Right: "ArrowRight"
|
|
96
|
+
};
|
|
97
|
+
function getEventKey(event, options = {}) {
|
|
98
|
+
var _a;
|
|
99
|
+
const { dir = "ltr", orientation = "horizontal" } = options;
|
|
100
|
+
let { key } = event;
|
|
101
|
+
key = (_a = sameKeyMap[key]) != null ? _a : key;
|
|
102
|
+
const isRtl = dir === "rtl" && orientation === "horizontal";
|
|
103
|
+
if (isRtl && key in rtlKeyMap) {
|
|
104
|
+
key = rtlKeyMap[key];
|
|
105
|
+
}
|
|
106
|
+
return key;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// ../../utilities/dom/src/nodelist.ts
|
|
110
|
+
function queryAll(root, selector) {
|
|
111
|
+
var _a;
|
|
112
|
+
return Array.from((_a = root == null ? void 0 : root.querySelectorAll(selector)) != null ? _a : []);
|
|
113
|
+
}
|
|
114
|
+
function itemById(v, id) {
|
|
115
|
+
return v.find((node) => node.id === id);
|
|
116
|
+
}
|
|
117
|
+
function indexOfId(v, id) {
|
|
118
|
+
const item = itemById(v, id);
|
|
119
|
+
return item ? v.indexOf(item) : -1;
|
|
120
|
+
}
|
|
121
|
+
function nextById(v, id, loop = true) {
|
|
122
|
+
let idx = indexOfId(v, id);
|
|
123
|
+
idx = loop ? (idx + 1) % v.length : Math.min(idx + 1, v.length - 1);
|
|
124
|
+
return v[idx];
|
|
125
|
+
}
|
|
126
|
+
function prevById(v, id, loop = true) {
|
|
127
|
+
let idx = indexOfId(v, id);
|
|
128
|
+
if (idx === -1)
|
|
129
|
+
return loop ? v[v.length - 1] : null;
|
|
130
|
+
idx = loop ? (idx - 1 + v.length) % v.length : Math.max(0, idx - 1);
|
|
131
|
+
return v[idx];
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// src/tabs.anatomy.ts
|
|
135
|
+
var import_anatomy = require("@zag-js/anatomy");
|
|
136
|
+
var anatomy = (0, import_anatomy.createAnatomy)("tabs").parts("root", "tablist", "trigger", "contentGroup", "content", "indicator");
|
|
137
|
+
var parts = anatomy.build();
|
|
138
|
+
|
|
139
|
+
// src/tabs.dom.ts
|
|
140
|
+
var dom = defineDomHelpers({
|
|
141
|
+
getRootId: (ctx) => {
|
|
142
|
+
var _a, _b;
|
|
143
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `tabs:${ctx.id}`;
|
|
144
|
+
},
|
|
145
|
+
getTablistId: (ctx) => {
|
|
146
|
+
var _a, _b;
|
|
147
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.tablist) != null ? _b : `tabs:${ctx.id}:list`;
|
|
148
|
+
},
|
|
149
|
+
getContentId: (ctx, id) => {
|
|
150
|
+
var _a, _b;
|
|
151
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.content) != null ? _b : `tabs:${ctx.id}:content-${id}`;
|
|
152
|
+
},
|
|
153
|
+
getContentGroupId: (ctx) => {
|
|
154
|
+
var _a, _b;
|
|
155
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.contentGroup) != null ? _b : `tabs:${ctx.id}:content-group`;
|
|
156
|
+
},
|
|
157
|
+
getTriggerId: (ctx, id) => {
|
|
158
|
+
var _a, _b;
|
|
159
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.trigger) != null ? _b : `tabs:${ctx.id}:trigger-${id}`;
|
|
160
|
+
},
|
|
161
|
+
getIndicatorId: (ctx) => `tabs:${ctx.id}:indicator`,
|
|
162
|
+
getTablistEl: (ctx) => dom.getById(ctx, dom.getTablistId(ctx)),
|
|
163
|
+
getContentEl: (ctx, id) => dom.getById(ctx, dom.getContentId(ctx, id)),
|
|
164
|
+
getTriggerEl: (ctx, id) => dom.getById(ctx, dom.getTriggerId(ctx, id)),
|
|
165
|
+
getIndicatorEl: (ctx) => dom.getById(ctx, dom.getIndicatorId(ctx)),
|
|
166
|
+
getElements: (ctx) => {
|
|
167
|
+
const ownerId = CSS.escape(dom.getTablistId(ctx));
|
|
168
|
+
const selector = `[role=tab][data-ownedby='${ownerId}']:not([disabled])`;
|
|
169
|
+
return queryAll(dom.getTablistEl(ctx), selector);
|
|
170
|
+
},
|
|
171
|
+
getFirstEl: (ctx) => first(dom.getElements(ctx)),
|
|
172
|
+
getLastEl: (ctx) => last(dom.getElements(ctx)),
|
|
173
|
+
getNextEl: (ctx, id) => nextById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
|
|
174
|
+
getPrevEl: (ctx, id) => prevById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
|
|
175
|
+
getActiveContentEl: (ctx) => {
|
|
176
|
+
if (!ctx.value)
|
|
177
|
+
return;
|
|
178
|
+
const id = dom.getContentId(ctx, ctx.value);
|
|
179
|
+
return dom.getById(ctx, id);
|
|
180
|
+
},
|
|
181
|
+
getRectById: (ctx, id) => {
|
|
182
|
+
var _a;
|
|
183
|
+
const empty = {
|
|
184
|
+
offsetLeft: 0,
|
|
185
|
+
offsetTop: 0,
|
|
186
|
+
offsetWidth: 0,
|
|
187
|
+
offsetHeight: 0
|
|
188
|
+
};
|
|
189
|
+
const tab = (_a = itemById(dom.getElements(ctx), dom.getTriggerId(ctx, id))) != null ? _a : empty;
|
|
190
|
+
if (ctx.isVertical) {
|
|
191
|
+
return {
|
|
192
|
+
top: `${tab.offsetTop}px`,
|
|
193
|
+
height: `${tab.offsetHeight}px`
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
return {
|
|
197
|
+
left: `${tab.offsetLeft}px`,
|
|
198
|
+
width: `${tab.offsetWidth}px`
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
// src/tabs.connect.ts
|
|
204
|
+
function connect(state, send, normalize) {
|
|
205
|
+
const translations = state.context.translations;
|
|
206
|
+
const isFocused = state.matches("focused");
|
|
207
|
+
return {
|
|
208
|
+
value: state.context.value,
|
|
209
|
+
focusedValue: state.context.focusedValue,
|
|
210
|
+
previousValues: Array.from(state.context.previousValues),
|
|
211
|
+
setValue(value) {
|
|
212
|
+
send({ type: "SET_VALUE", value });
|
|
213
|
+
},
|
|
214
|
+
clearValue() {
|
|
215
|
+
send({ type: "CLEAR_VALUE" });
|
|
216
|
+
},
|
|
217
|
+
rootProps: normalize.element({
|
|
218
|
+
...parts.root.attrs,
|
|
219
|
+
id: dom.getRootId(state.context),
|
|
220
|
+
"data-orientation": state.context.orientation,
|
|
221
|
+
"data-focus": dataAttr(isFocused),
|
|
222
|
+
dir: state.context.dir
|
|
223
|
+
}),
|
|
224
|
+
tablistProps: normalize.element({
|
|
225
|
+
...parts.tablist.attrs,
|
|
226
|
+
id: dom.getTablistId(state.context),
|
|
227
|
+
role: "tablist",
|
|
228
|
+
"data-focus": dataAttr(isFocused),
|
|
229
|
+
"aria-orientation": state.context.orientation,
|
|
230
|
+
"data-orientation": state.context.orientation,
|
|
231
|
+
"aria-label": translations.tablistLabel,
|
|
232
|
+
onKeyDown(event) {
|
|
233
|
+
const keyMap = {
|
|
234
|
+
ArrowDown() {
|
|
235
|
+
send("ARROW_DOWN");
|
|
236
|
+
},
|
|
237
|
+
ArrowUp() {
|
|
238
|
+
send("ARROW_UP");
|
|
239
|
+
},
|
|
240
|
+
ArrowLeft() {
|
|
241
|
+
send("ARROW_LEFT");
|
|
242
|
+
},
|
|
243
|
+
ArrowRight() {
|
|
244
|
+
send("ARROW_RIGHT");
|
|
245
|
+
},
|
|
246
|
+
Home() {
|
|
247
|
+
send("HOME");
|
|
248
|
+
},
|
|
249
|
+
End() {
|
|
250
|
+
send("END");
|
|
251
|
+
},
|
|
252
|
+
Enter() {
|
|
253
|
+
send({ type: "ENTER", value: state.context.focusedValue });
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
let key = getEventKey(event, state.context);
|
|
257
|
+
const exec = keyMap[key];
|
|
258
|
+
if (exec) {
|
|
259
|
+
event.preventDefault();
|
|
260
|
+
exec(event);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}),
|
|
264
|
+
getTriggerProps(props) {
|
|
265
|
+
const { value, disabled } = props;
|
|
266
|
+
const selected = state.context.value === value;
|
|
267
|
+
return normalize.button({
|
|
268
|
+
...parts.trigger.attrs,
|
|
269
|
+
role: "tab",
|
|
270
|
+
type: "button",
|
|
271
|
+
disabled,
|
|
272
|
+
"data-orientation": state.context.orientation,
|
|
273
|
+
"data-disabled": dataAttr(disabled),
|
|
274
|
+
"aria-disabled": disabled,
|
|
275
|
+
"data-value": value,
|
|
276
|
+
"aria-selected": selected,
|
|
277
|
+
"data-selected": dataAttr(selected),
|
|
278
|
+
"aria-controls": dom.getContentId(state.context, value),
|
|
279
|
+
"data-ownedby": dom.getTablistId(state.context),
|
|
280
|
+
id: dom.getTriggerId(state.context, value),
|
|
281
|
+
tabIndex: selected ? 0 : -1,
|
|
282
|
+
onFocus() {
|
|
283
|
+
send({ type: "TAB_FOCUS", value });
|
|
284
|
+
},
|
|
285
|
+
onBlur(event) {
|
|
286
|
+
const target = event.relatedTarget;
|
|
287
|
+
if ((target == null ? void 0 : target.getAttribute("role")) !== "tab") {
|
|
288
|
+
send({ type: "TAB_BLUR" });
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
onClick(event) {
|
|
292
|
+
if (disabled)
|
|
293
|
+
return;
|
|
294
|
+
if (isSafari()) {
|
|
295
|
+
event.currentTarget.focus();
|
|
296
|
+
}
|
|
297
|
+
send({ type: "TAB_CLICK", value });
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
},
|
|
301
|
+
contentGroupProps: normalize.element({
|
|
302
|
+
...parts.contentGroup.attrs,
|
|
303
|
+
id: dom.getContentGroupId(state.context),
|
|
304
|
+
"data-orientation": state.context.orientation
|
|
305
|
+
}),
|
|
306
|
+
getContentProps({ value }) {
|
|
307
|
+
const selected = state.context.value === value;
|
|
308
|
+
return normalize.element({
|
|
309
|
+
...parts.content.attrs,
|
|
310
|
+
id: dom.getContentId(state.context, value),
|
|
311
|
+
tabIndex: 0,
|
|
312
|
+
"aria-labelledby": dom.getTriggerId(state.context, value),
|
|
313
|
+
role: "tabpanel",
|
|
314
|
+
"data-ownedby": dom.getTablistId(state.context),
|
|
315
|
+
hidden: !selected
|
|
316
|
+
});
|
|
317
|
+
},
|
|
318
|
+
indicatorProps: normalize.element({
|
|
319
|
+
id: dom.getIndicatorId(state.context),
|
|
320
|
+
...parts.indicator.attrs,
|
|
321
|
+
"data-orientation": state.context.orientation,
|
|
322
|
+
style: {
|
|
323
|
+
"--transition-duration": "200ms",
|
|
324
|
+
"--transition-property": "left, right, top, bottom, width, height",
|
|
325
|
+
position: "absolute",
|
|
326
|
+
willChange: "var(--transition-property)",
|
|
327
|
+
transitionProperty: "var(--transition-property)",
|
|
328
|
+
transitionDuration: state.context.hasMeasuredRect ? "var(--transition-duration)" : "0ms",
|
|
329
|
+
transitionTimingFunction: "var(--transition-timing-function)",
|
|
330
|
+
...state.context.indicatorRect
|
|
331
|
+
}
|
|
332
|
+
})
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
336
|
+
0 && (module.exports = {
|
|
337
|
+
connect
|
|
338
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { MachineContext } from './tabs.types.js';
|
|
2
|
+
import '@zag-js/core';
|
|
3
|
+
import '@zag-js/types';
|
|
4
|
+
|
|
5
|
+
declare const dom: {
|
|
6
|
+
getRootNode: (ctx: {
|
|
7
|
+
getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
|
|
8
|
+
}) => Document | ShadowRoot;
|
|
9
|
+
getDoc: (ctx: {
|
|
10
|
+
getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
|
|
11
|
+
}) => Document;
|
|
12
|
+
getWin: (ctx: {
|
|
13
|
+
getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
|
|
14
|
+
}) => Window & typeof globalThis;
|
|
15
|
+
getActiveElement: (ctx: {
|
|
16
|
+
getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
|
|
17
|
+
}) => HTMLElement | null;
|
|
18
|
+
getById: <T = HTMLElement>(ctx: {
|
|
19
|
+
getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
|
|
20
|
+
}, id: string) => T | null;
|
|
21
|
+
} & {
|
|
22
|
+
getRootId: (ctx: MachineContext) => string;
|
|
23
|
+
getTablistId: (ctx: MachineContext) => string;
|
|
24
|
+
getContentId: (ctx: MachineContext, id: string) => string;
|
|
25
|
+
getContentGroupId: (ctx: MachineContext) => string;
|
|
26
|
+
getTriggerId: (ctx: MachineContext, id: string) => string;
|
|
27
|
+
getIndicatorId: (ctx: MachineContext) => string;
|
|
28
|
+
getTablistEl: (ctx: MachineContext) => HTMLElement | null;
|
|
29
|
+
getContentEl: (ctx: MachineContext, id: string) => HTMLElement | null;
|
|
30
|
+
getTriggerEl: (ctx: MachineContext, id: string) => HTMLElement | null;
|
|
31
|
+
getIndicatorEl: (ctx: MachineContext) => HTMLElement | null;
|
|
32
|
+
getElements: (ctx: MachineContext) => HTMLElement[];
|
|
33
|
+
getFirstEl: (ctx: MachineContext) => HTMLElement | undefined;
|
|
34
|
+
getLastEl: (ctx: MachineContext) => HTMLElement | undefined;
|
|
35
|
+
getNextEl: (ctx: MachineContext, id: string) => HTMLElement;
|
|
36
|
+
getPrevEl: (ctx: MachineContext, id: string) => HTMLElement | null;
|
|
37
|
+
getActiveContentEl: (ctx: MachineContext) => HTMLElement | null | undefined;
|
|
38
|
+
getRectById: (ctx: MachineContext, id: string) => {
|
|
39
|
+
top: string;
|
|
40
|
+
height: string;
|
|
41
|
+
left?: undefined;
|
|
42
|
+
width?: undefined;
|
|
43
|
+
} | {
|
|
44
|
+
left: string;
|
|
45
|
+
width: string;
|
|
46
|
+
top?: undefined;
|
|
47
|
+
height?: undefined;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export { dom };
|
package/dist/tabs.dom.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
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.dom.ts
|
|
21
|
+
var tabs_dom_exports = {};
|
|
22
|
+
__export(tabs_dom_exports, {
|
|
23
|
+
dom: () => dom
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(tabs_dom_exports);
|
|
26
|
+
|
|
27
|
+
// ../../utilities/core/src/array.ts
|
|
28
|
+
var first = (v) => v[0];
|
|
29
|
+
var last = (v) => v[v.length - 1];
|
|
30
|
+
|
|
31
|
+
// ../../utilities/dom/src/query.ts
|
|
32
|
+
function isDocument(el) {
|
|
33
|
+
return el.nodeType === Node.DOCUMENT_NODE;
|
|
34
|
+
}
|
|
35
|
+
function isWindow(value) {
|
|
36
|
+
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
37
|
+
}
|
|
38
|
+
function getDocument(el) {
|
|
39
|
+
var _a;
|
|
40
|
+
if (isWindow(el))
|
|
41
|
+
return el.document;
|
|
42
|
+
if (isDocument(el))
|
|
43
|
+
return el;
|
|
44
|
+
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
45
|
+
}
|
|
46
|
+
function defineDomHelpers(helpers) {
|
|
47
|
+
const dom2 = {
|
|
48
|
+
getRootNode: (ctx) => {
|
|
49
|
+
var _a, _b;
|
|
50
|
+
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
51
|
+
},
|
|
52
|
+
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
53
|
+
getWin: (ctx) => {
|
|
54
|
+
var _a;
|
|
55
|
+
return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
|
|
56
|
+
},
|
|
57
|
+
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
58
|
+
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
59
|
+
};
|
|
60
|
+
return {
|
|
61
|
+
...dom2,
|
|
62
|
+
...helpers
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// ../../utilities/dom/src/nodelist.ts
|
|
67
|
+
function queryAll(root, selector) {
|
|
68
|
+
var _a;
|
|
69
|
+
return Array.from((_a = root == null ? void 0 : root.querySelectorAll(selector)) != null ? _a : []);
|
|
70
|
+
}
|
|
71
|
+
function itemById(v, id) {
|
|
72
|
+
return v.find((node) => node.id === id);
|
|
73
|
+
}
|
|
74
|
+
function indexOfId(v, id) {
|
|
75
|
+
const item = itemById(v, id);
|
|
76
|
+
return item ? v.indexOf(item) : -1;
|
|
77
|
+
}
|
|
78
|
+
function nextById(v, id, loop = true) {
|
|
79
|
+
let idx = indexOfId(v, id);
|
|
80
|
+
idx = loop ? (idx + 1) % v.length : Math.min(idx + 1, v.length - 1);
|
|
81
|
+
return v[idx];
|
|
82
|
+
}
|
|
83
|
+
function prevById(v, id, loop = true) {
|
|
84
|
+
let idx = indexOfId(v, id);
|
|
85
|
+
if (idx === -1)
|
|
86
|
+
return loop ? v[v.length - 1] : null;
|
|
87
|
+
idx = loop ? (idx - 1 + v.length) % v.length : Math.max(0, idx - 1);
|
|
88
|
+
return v[idx];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// src/tabs.dom.ts
|
|
92
|
+
var dom = defineDomHelpers({
|
|
93
|
+
getRootId: (ctx) => {
|
|
94
|
+
var _a, _b;
|
|
95
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `tabs:${ctx.id}`;
|
|
96
|
+
},
|
|
97
|
+
getTablistId: (ctx) => {
|
|
98
|
+
var _a, _b;
|
|
99
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.tablist) != null ? _b : `tabs:${ctx.id}:list`;
|
|
100
|
+
},
|
|
101
|
+
getContentId: (ctx, id) => {
|
|
102
|
+
var _a, _b;
|
|
103
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.content) != null ? _b : `tabs:${ctx.id}:content-${id}`;
|
|
104
|
+
},
|
|
105
|
+
getContentGroupId: (ctx) => {
|
|
106
|
+
var _a, _b;
|
|
107
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.contentGroup) != null ? _b : `tabs:${ctx.id}:content-group`;
|
|
108
|
+
},
|
|
109
|
+
getTriggerId: (ctx, id) => {
|
|
110
|
+
var _a, _b;
|
|
111
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.trigger) != null ? _b : `tabs:${ctx.id}:trigger-${id}`;
|
|
112
|
+
},
|
|
113
|
+
getIndicatorId: (ctx) => `tabs:${ctx.id}:indicator`,
|
|
114
|
+
getTablistEl: (ctx) => dom.getById(ctx, dom.getTablistId(ctx)),
|
|
115
|
+
getContentEl: (ctx, id) => dom.getById(ctx, dom.getContentId(ctx, id)),
|
|
116
|
+
getTriggerEl: (ctx, id) => dom.getById(ctx, dom.getTriggerId(ctx, id)),
|
|
117
|
+
getIndicatorEl: (ctx) => dom.getById(ctx, dom.getIndicatorId(ctx)),
|
|
118
|
+
getElements: (ctx) => {
|
|
119
|
+
const ownerId = CSS.escape(dom.getTablistId(ctx));
|
|
120
|
+
const selector = `[role=tab][data-ownedby='${ownerId}']:not([disabled])`;
|
|
121
|
+
return queryAll(dom.getTablistEl(ctx), selector);
|
|
122
|
+
},
|
|
123
|
+
getFirstEl: (ctx) => first(dom.getElements(ctx)),
|
|
124
|
+
getLastEl: (ctx) => last(dom.getElements(ctx)),
|
|
125
|
+
getNextEl: (ctx, id) => nextById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
|
|
126
|
+
getPrevEl: (ctx, id) => prevById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
|
|
127
|
+
getActiveContentEl: (ctx) => {
|
|
128
|
+
if (!ctx.value)
|
|
129
|
+
return;
|
|
130
|
+
const id = dom.getContentId(ctx, ctx.value);
|
|
131
|
+
return dom.getById(ctx, id);
|
|
132
|
+
},
|
|
133
|
+
getRectById: (ctx, id) => {
|
|
134
|
+
var _a;
|
|
135
|
+
const empty = {
|
|
136
|
+
offsetLeft: 0,
|
|
137
|
+
offsetTop: 0,
|
|
138
|
+
offsetWidth: 0,
|
|
139
|
+
offsetHeight: 0
|
|
140
|
+
};
|
|
141
|
+
const tab = (_a = itemById(dom.getElements(ctx), dom.getTriggerId(ctx, id))) != null ? _a : empty;
|
|
142
|
+
if (ctx.isVertical) {
|
|
143
|
+
return {
|
|
144
|
+
top: `${tab.offsetTop}px`,
|
|
145
|
+
height: `${tab.offsetHeight}px`
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
left: `${tab.offsetLeft}px`,
|
|
150
|
+
width: `${tab.offsetWidth}px`
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
155
|
+
0 && (module.exports = {
|
|
156
|
+
dom
|
|
157
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as _zag_js_core from '@zag-js/core';
|
|
2
|
+
import { UserDefinedContext, MachineContext, MachineState } from './tabs.types.js';
|
|
3
|
+
import '@zag-js/types';
|
|
4
|
+
|
|
5
|
+
declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
|
|
6
|
+
|
|
7
|
+
export { machine };
|