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