@zag-js/tabs 0.0.0-dev-20230221113221 → 0.0.0-dev-20230222181847
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-M5VIW7LC.mjs → chunk-5JW3YJ3I.mjs} +18 -42
- package/dist/chunk-5ZMNIWHF.mjs +53 -0
- package/dist/{chunk-ZMHFFJLR.mjs → chunk-JG2VX4ST.mjs} +5 -66
- package/dist/index.js +45 -194
- package/dist/index.mjs +3 -3
- package/dist/tabs.connect.d.ts +15 -0
- package/dist/tabs.connect.js +32 -116
- package/dist/tabs.connect.mjs +2 -2
- package/dist/tabs.dom.d.ts +8 -8
- package/dist/tabs.dom.js +9 -71
- package/dist/tabs.dom.mjs +1 -1
- package/dist/tabs.machine.js +21 -148
- package/dist/tabs.machine.mjs +2 -2
- package/dist/tabs.types.d.ts +0 -4
- package/package.json +7 -5
- package/dist/chunk-SDY32WSI.mjs +0 -127
|
@@ -3,60 +3,36 @@ import {
|
|
|
3
3
|
} from "./chunk-S2KW2DT4.mjs";
|
|
4
4
|
import {
|
|
5
5
|
dom
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
|
|
8
|
-
// ../../utilities/dom/src/attrs.ts
|
|
9
|
-
var dataAttr = (guard) => {
|
|
10
|
-
return guard ? "" : void 0;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
// ../../utilities/dom/src/platform.ts
|
|
14
|
-
var isDom = () => typeof window !== "undefined";
|
|
15
|
-
function getPlatform() {
|
|
16
|
-
const agent = navigator.userAgentData;
|
|
17
|
-
return agent?.platform ?? navigator.platform;
|
|
18
|
-
}
|
|
19
|
-
var pt = (v) => isDom() && v.test(getPlatform());
|
|
20
|
-
var vn = (v) => isDom() && v.test(navigator.vendor);
|
|
21
|
-
var isSafari = () => isApple() && vn(/apple/i);
|
|
22
|
-
var isApple = () => pt(/mac|iphone|ipad|ipod/i);
|
|
23
|
-
|
|
24
|
-
// ../../utilities/dom/src/keyboard-event.ts
|
|
25
|
-
var rtlKeyMap = {
|
|
26
|
-
ArrowLeft: "ArrowRight",
|
|
27
|
-
ArrowRight: "ArrowLeft"
|
|
28
|
-
};
|
|
29
|
-
var sameKeyMap = {
|
|
30
|
-
Up: "ArrowUp",
|
|
31
|
-
Down: "ArrowDown",
|
|
32
|
-
Esc: "Escape",
|
|
33
|
-
" ": "Space",
|
|
34
|
-
",": "Comma",
|
|
35
|
-
Left: "ArrowLeft",
|
|
36
|
-
Right: "ArrowRight"
|
|
37
|
-
};
|
|
38
|
-
function getEventKey(event, options = {}) {
|
|
39
|
-
const { dir = "ltr", orientation = "horizontal" } = options;
|
|
40
|
-
let { key } = event;
|
|
41
|
-
key = sameKeyMap[key] ?? key;
|
|
42
|
-
const isRtl = dir === "rtl" && orientation === "horizontal";
|
|
43
|
-
if (isRtl && key in rtlKeyMap) {
|
|
44
|
-
key = rtlKeyMap[key];
|
|
45
|
-
}
|
|
46
|
-
return key;
|
|
47
|
-
}
|
|
6
|
+
} from "./chunk-5ZMNIWHF.mjs";
|
|
48
7
|
|
|
49
8
|
// src/tabs.connect.ts
|
|
9
|
+
import { getEventKey } from "@zag-js/dom-event";
|
|
10
|
+
import { dataAttr, isSafari } from "@zag-js/dom-query";
|
|
50
11
|
function connect(state, send, normalize) {
|
|
51
12
|
const translations = state.context.translations;
|
|
52
13
|
const isFocused = state.matches("focused");
|
|
53
14
|
return {
|
|
15
|
+
/**
|
|
16
|
+
* The current value of the tabs.
|
|
17
|
+
*/
|
|
54
18
|
value: state.context.value,
|
|
19
|
+
/**
|
|
20
|
+
* The value of the tab that is currently focused.
|
|
21
|
+
*/
|
|
55
22
|
focusedValue: state.context.focusedValue,
|
|
23
|
+
/**
|
|
24
|
+
* The previous values of the tabs in sequence of selection.
|
|
25
|
+
*/
|
|
56
26
|
previousValues: Array.from(state.context.previousValues),
|
|
27
|
+
/**
|
|
28
|
+
* Sets the value of the tabs.
|
|
29
|
+
*/
|
|
57
30
|
setValue(value) {
|
|
58
31
|
send({ type: "SET_VALUE", value });
|
|
59
32
|
},
|
|
33
|
+
/**
|
|
34
|
+
* Clears the value of the tabs.
|
|
35
|
+
*/
|
|
60
36
|
clearValue() {
|
|
61
37
|
send({ type: "CLEAR_VALUE" });
|
|
62
38
|
},
|
|
@@ -0,0 +1,53 @@
|
|
|
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) => `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
|
+
const id = dom.getContentId(ctx, ctx.value);
|
|
28
|
+
return dom.getById(ctx, id);
|
|
29
|
+
},
|
|
30
|
+
getRectById: (ctx, id) => {
|
|
31
|
+
const empty = {
|
|
32
|
+
offsetLeft: 0,
|
|
33
|
+
offsetTop: 0,
|
|
34
|
+
offsetWidth: 0,
|
|
35
|
+
offsetHeight: 0
|
|
36
|
+
};
|
|
37
|
+
const tab = itemById(dom.getElements(ctx), dom.getTriggerId(ctx, id)) ?? empty;
|
|
38
|
+
if (ctx.isVertical) {
|
|
39
|
+
return {
|
|
40
|
+
top: `${tab.offsetTop}px`,
|
|
41
|
+
height: `${tab.offsetHeight}px`
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
left: `${tab.offsetLeft}px`,
|
|
46
|
+
width: `${tab.offsetWidth}px`
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
export {
|
|
52
|
+
dom
|
|
53
|
+
};
|
|
@@ -1,73 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
-
dom
|
|
3
|
-
|
|
4
|
-
isHTMLElement,
|
|
5
|
-
isVisible
|
|
6
|
-
} from "./chunk-SDY32WSI.mjs";
|
|
2
|
+
dom
|
|
3
|
+
} from "./chunk-5ZMNIWHF.mjs";
|
|
7
4
|
|
|
8
5
|
// src/tabs.machine.ts
|
|
9
6
|
import { createMachine, guards } from "@zag-js/core";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
14
|
-
|
|
15
|
-
// ../../utilities/core/src/object.ts
|
|
16
|
-
function compact(obj) {
|
|
17
|
-
if (obj === void 0)
|
|
18
|
-
return obj;
|
|
19
|
-
return Object.fromEntries(
|
|
20
|
-
Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// ../../utilities/dom/src/focusable.ts
|
|
25
|
-
var focusableSelector = "input:not([type='hidden']):not([disabled]), select:not([disabled]), textarea:not([disabled]), a[href], button:not([disabled]), [tabindex], iframe, object, embed, area[href], audio[controls], video[controls], [contenteditable]:not([contenteditable='false']), details > summary:first-of-type";
|
|
26
|
-
var getFocusables = (container, includeContainer = false) => {
|
|
27
|
-
if (!container)
|
|
28
|
-
return [];
|
|
29
|
-
const elements = Array.from(container.querySelectorAll(focusableSelector));
|
|
30
|
-
const include = includeContainer == true || includeContainer == "if-empty" && elements.length === 0;
|
|
31
|
-
if (include && isHTMLElement(container) && isFocusable(container)) {
|
|
32
|
-
elements.unshift(container);
|
|
33
|
-
}
|
|
34
|
-
const focusableElements = elements.filter(isFocusable);
|
|
35
|
-
focusableElements.forEach((element, i) => {
|
|
36
|
-
if (isFrame(element) && element.contentDocument) {
|
|
37
|
-
const frameBody = element.contentDocument.body;
|
|
38
|
-
focusableElements.splice(i, 1, ...getFocusables(frameBody));
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
return focusableElements;
|
|
42
|
-
};
|
|
43
|
-
function isFocusable(element) {
|
|
44
|
-
if (!element)
|
|
45
|
-
return false;
|
|
46
|
-
return element.matches(focusableSelector) && isVisible(element);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// ../../utilities/dom/src/next-tick.ts
|
|
50
|
-
function nextTick(fn) {
|
|
51
|
-
const set = /* @__PURE__ */ new Set();
|
|
52
|
-
function raf2(fn2) {
|
|
53
|
-
const id = globalThis.requestAnimationFrame(fn2);
|
|
54
|
-
set.add(() => globalThis.cancelAnimationFrame(id));
|
|
55
|
-
}
|
|
56
|
-
raf2(() => raf2(fn));
|
|
57
|
-
return function cleanup() {
|
|
58
|
-
set.forEach(function(fn2) {
|
|
59
|
-
fn2();
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
function raf(fn) {
|
|
64
|
-
const id = globalThis.requestAnimationFrame(fn);
|
|
65
|
-
return function cleanup() {
|
|
66
|
-
globalThis.cancelAnimationFrame(id);
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// src/tabs.machine.ts
|
|
7
|
+
import { nextTick, raf } from "@zag-js/dom-query";
|
|
8
|
+
import { getFocusables } from "@zag-js/tabbable";
|
|
9
|
+
import { compact } from "@zag-js/utils";
|
|
71
10
|
var { not } = guards;
|
|
72
11
|
function machine(userContext) {
|
|
73
12
|
const ctx = compact(userContext);
|
package/dist/index.js
CHANGED
|
@@ -31,181 +31,14 @@ var import_anatomy = require("@zag-js/anatomy");
|
|
|
31
31
|
var anatomy = (0, import_anatomy.createAnatomy)("tabs").parts("root", "tablist", "trigger", "contentGroup", "content", "indicator");
|
|
32
32
|
var parts = anatomy.build();
|
|
33
33
|
|
|
34
|
-
//
|
|
35
|
-
var
|
|
36
|
-
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
// ../../utilities/core/src/array.ts
|
|
40
|
-
var first = (v) => v[0];
|
|
41
|
-
var last = (v) => v[v.length - 1];
|
|
42
|
-
|
|
43
|
-
// ../../utilities/core/src/guard.ts
|
|
44
|
-
var isArray = (v) => Array.isArray(v);
|
|
45
|
-
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
46
|
-
|
|
47
|
-
// ../../utilities/core/src/object.ts
|
|
48
|
-
function compact(obj) {
|
|
49
|
-
if (obj === void 0)
|
|
50
|
-
return obj;
|
|
51
|
-
return Object.fromEntries(
|
|
52
|
-
Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// ../../utilities/dom/src/platform.ts
|
|
57
|
-
var isDom = () => typeof window !== "undefined";
|
|
58
|
-
function getPlatform() {
|
|
59
|
-
const agent = navigator.userAgentData;
|
|
60
|
-
return agent?.platform ?? navigator.platform;
|
|
61
|
-
}
|
|
62
|
-
var pt = (v) => isDom() && v.test(getPlatform());
|
|
63
|
-
var vn = (v) => isDom() && v.test(navigator.vendor);
|
|
64
|
-
var isSafari = () => isApple() && vn(/apple/i);
|
|
65
|
-
var isApple = () => pt(/mac|iphone|ipad|ipod/i);
|
|
66
|
-
|
|
67
|
-
// ../../utilities/dom/src/query.ts
|
|
68
|
-
function isDocument(el) {
|
|
69
|
-
return el.nodeType === Node.DOCUMENT_NODE;
|
|
70
|
-
}
|
|
71
|
-
function isWindow(value) {
|
|
72
|
-
return value?.toString() === "[object Window]";
|
|
73
|
-
}
|
|
74
|
-
function isFrame(element) {
|
|
75
|
-
return element.localName === "iframe";
|
|
76
|
-
}
|
|
77
|
-
function getDocument(el) {
|
|
78
|
-
if (isWindow(el))
|
|
79
|
-
return el.document;
|
|
80
|
-
if (isDocument(el))
|
|
81
|
-
return el;
|
|
82
|
-
return el?.ownerDocument ?? document;
|
|
83
|
-
}
|
|
84
|
-
function defineDomHelpers(helpers) {
|
|
85
|
-
const dom2 = {
|
|
86
|
-
getRootNode: (ctx) => ctx.getRootNode?.() ?? document,
|
|
87
|
-
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
88
|
-
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
89
|
-
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
90
|
-
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
|
|
91
|
-
queryById: (ctx, id) => {
|
|
92
|
-
const el = dom2.getById(ctx, id);
|
|
93
|
-
if (!el)
|
|
94
|
-
throw new Error(`Element with id "${id}" not found.`);
|
|
95
|
-
return el;
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
return {
|
|
99
|
-
...dom2,
|
|
100
|
-
...helpers
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
function isHTMLElement(v) {
|
|
104
|
-
return typeof v === "object" && v?.nodeType === Node.ELEMENT_NODE && typeof v?.nodeName === "string";
|
|
105
|
-
}
|
|
106
|
-
function isVisible(el) {
|
|
107
|
-
if (!isHTMLElement(el))
|
|
108
|
-
return false;
|
|
109
|
-
return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// ../../utilities/dom/src/focusable.ts
|
|
113
|
-
var focusableSelector = "input:not([type='hidden']):not([disabled]), select:not([disabled]), textarea:not([disabled]), a[href], button:not([disabled]), [tabindex], iframe, object, embed, area[href], audio[controls], video[controls], [contenteditable]:not([contenteditable='false']), details > summary:first-of-type";
|
|
114
|
-
var getFocusables = (container, includeContainer = false) => {
|
|
115
|
-
if (!container)
|
|
116
|
-
return [];
|
|
117
|
-
const elements = Array.from(container.querySelectorAll(focusableSelector));
|
|
118
|
-
const include = includeContainer == true || includeContainer == "if-empty" && elements.length === 0;
|
|
119
|
-
if (include && isHTMLElement(container) && isFocusable(container)) {
|
|
120
|
-
elements.unshift(container);
|
|
121
|
-
}
|
|
122
|
-
const focusableElements = elements.filter(isFocusable);
|
|
123
|
-
focusableElements.forEach((element, i) => {
|
|
124
|
-
if (isFrame(element) && element.contentDocument) {
|
|
125
|
-
const frameBody = element.contentDocument.body;
|
|
126
|
-
focusableElements.splice(i, 1, ...getFocusables(frameBody));
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
return focusableElements;
|
|
130
|
-
};
|
|
131
|
-
function isFocusable(element) {
|
|
132
|
-
if (!element)
|
|
133
|
-
return false;
|
|
134
|
-
return element.matches(focusableSelector) && isVisible(element);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// ../../utilities/dom/src/keyboard-event.ts
|
|
138
|
-
var rtlKeyMap = {
|
|
139
|
-
ArrowLeft: "ArrowRight",
|
|
140
|
-
ArrowRight: "ArrowLeft"
|
|
141
|
-
};
|
|
142
|
-
var sameKeyMap = {
|
|
143
|
-
Up: "ArrowUp",
|
|
144
|
-
Down: "ArrowDown",
|
|
145
|
-
Esc: "Escape",
|
|
146
|
-
" ": "Space",
|
|
147
|
-
",": "Comma",
|
|
148
|
-
Left: "ArrowLeft",
|
|
149
|
-
Right: "ArrowRight"
|
|
150
|
-
};
|
|
151
|
-
function getEventKey(event, options = {}) {
|
|
152
|
-
const { dir = "ltr", orientation = "horizontal" } = options;
|
|
153
|
-
let { key } = event;
|
|
154
|
-
key = sameKeyMap[key] ?? key;
|
|
155
|
-
const isRtl = dir === "rtl" && orientation === "horizontal";
|
|
156
|
-
if (isRtl && key in rtlKeyMap) {
|
|
157
|
-
key = rtlKeyMap[key];
|
|
158
|
-
}
|
|
159
|
-
return key;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// ../../utilities/dom/src/next-tick.ts
|
|
163
|
-
function nextTick(fn) {
|
|
164
|
-
const set = /* @__PURE__ */ new Set();
|
|
165
|
-
function raf2(fn2) {
|
|
166
|
-
const id = globalThis.requestAnimationFrame(fn2);
|
|
167
|
-
set.add(() => globalThis.cancelAnimationFrame(id));
|
|
168
|
-
}
|
|
169
|
-
raf2(() => raf2(fn));
|
|
170
|
-
return function cleanup() {
|
|
171
|
-
set.forEach(function(fn2) {
|
|
172
|
-
fn2();
|
|
173
|
-
});
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
function raf(fn) {
|
|
177
|
-
const id = globalThis.requestAnimationFrame(fn);
|
|
178
|
-
return function cleanup() {
|
|
179
|
-
globalThis.cancelAnimationFrame(id);
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// ../../utilities/dom/src/nodelist.ts
|
|
184
|
-
function queryAll(root, selector) {
|
|
185
|
-
return Array.from(root?.querySelectorAll(selector) ?? []);
|
|
186
|
-
}
|
|
187
|
-
function itemById(v, id) {
|
|
188
|
-
return v.find((node) => node.id === id);
|
|
189
|
-
}
|
|
190
|
-
function indexOfId(v, id) {
|
|
191
|
-
const item = itemById(v, id);
|
|
192
|
-
return item ? v.indexOf(item) : -1;
|
|
193
|
-
}
|
|
194
|
-
function nextById(v, id, loop = true) {
|
|
195
|
-
let idx = indexOfId(v, id);
|
|
196
|
-
idx = loop ? (idx + 1) % v.length : Math.min(idx + 1, v.length - 1);
|
|
197
|
-
return v[idx];
|
|
198
|
-
}
|
|
199
|
-
function prevById(v, id, loop = true) {
|
|
200
|
-
let idx = indexOfId(v, id);
|
|
201
|
-
if (idx === -1)
|
|
202
|
-
return loop ? v[v.length - 1] : null;
|
|
203
|
-
idx = loop ? (idx - 1 + v.length) % v.length : Math.max(0, idx - 1);
|
|
204
|
-
return v[idx];
|
|
205
|
-
}
|
|
34
|
+
// src/tabs.connect.ts
|
|
35
|
+
var import_dom_event = require("@zag-js/dom-event");
|
|
36
|
+
var import_dom_query2 = require("@zag-js/dom-query");
|
|
206
37
|
|
|
207
38
|
// src/tabs.dom.ts
|
|
208
|
-
var
|
|
39
|
+
var import_dom_query = require("@zag-js/dom-query");
|
|
40
|
+
var import_utils = require("@zag-js/utils");
|
|
41
|
+
var dom = (0, import_dom_query.createScope)({
|
|
209
42
|
getRootId: (ctx) => ctx.ids?.root ?? `tabs:${ctx.id}`,
|
|
210
43
|
getTablistId: (ctx) => ctx.ids?.tablist ?? `tabs:${ctx.id}:list`,
|
|
211
44
|
getContentId: (ctx, id) => ctx.ids?.content ?? `tabs:${ctx.id}:content-${id}`,
|
|
@@ -219,12 +52,12 @@ var dom = defineDomHelpers({
|
|
|
219
52
|
getElements: (ctx) => {
|
|
220
53
|
const ownerId = CSS.escape(dom.getTablistId(ctx));
|
|
221
54
|
const selector = `[role=tab][data-ownedby='${ownerId}']:not([disabled])`;
|
|
222
|
-
return queryAll(dom.getTablistEl(ctx), selector);
|
|
55
|
+
return (0, import_dom_query.queryAll)(dom.getTablistEl(ctx), selector);
|
|
223
56
|
},
|
|
224
|
-
getFirstEl: (ctx) => first(dom.getElements(ctx)),
|
|
225
|
-
getLastEl: (ctx) => last(dom.getElements(ctx)),
|
|
226
|
-
getNextEl: (ctx, id) => nextById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
|
|
227
|
-
getPrevEl: (ctx, id) => prevById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
|
|
57
|
+
getFirstEl: (ctx) => (0, import_utils.first)(dom.getElements(ctx)),
|
|
58
|
+
getLastEl: (ctx) => (0, import_utils.last)(dom.getElements(ctx)),
|
|
59
|
+
getNextEl: (ctx, id) => (0, import_dom_query.nextById)(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
|
|
60
|
+
getPrevEl: (ctx, id) => (0, import_dom_query.prevById)(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
|
|
228
61
|
getActiveContentEl: (ctx) => {
|
|
229
62
|
if (!ctx.value)
|
|
230
63
|
return;
|
|
@@ -238,7 +71,7 @@ var dom = defineDomHelpers({
|
|
|
238
71
|
offsetWidth: 0,
|
|
239
72
|
offsetHeight: 0
|
|
240
73
|
};
|
|
241
|
-
const tab = itemById(dom.getElements(ctx), dom.getTriggerId(ctx, id)) ?? empty;
|
|
74
|
+
const tab = (0, import_dom_query.itemById)(dom.getElements(ctx), dom.getTriggerId(ctx, id)) ?? empty;
|
|
242
75
|
if (ctx.isVertical) {
|
|
243
76
|
return {
|
|
244
77
|
top: `${tab.offsetTop}px`,
|
|
@@ -257,12 +90,27 @@ function connect(state, send, normalize) {
|
|
|
257
90
|
const translations = state.context.translations;
|
|
258
91
|
const isFocused = state.matches("focused");
|
|
259
92
|
return {
|
|
93
|
+
/**
|
|
94
|
+
* The current value of the tabs.
|
|
95
|
+
*/
|
|
260
96
|
value: state.context.value,
|
|
97
|
+
/**
|
|
98
|
+
* The value of the tab that is currently focused.
|
|
99
|
+
*/
|
|
261
100
|
focusedValue: state.context.focusedValue,
|
|
101
|
+
/**
|
|
102
|
+
* The previous values of the tabs in sequence of selection.
|
|
103
|
+
*/
|
|
262
104
|
previousValues: Array.from(state.context.previousValues),
|
|
105
|
+
/**
|
|
106
|
+
* Sets the value of the tabs.
|
|
107
|
+
*/
|
|
263
108
|
setValue(value) {
|
|
264
109
|
send({ type: "SET_VALUE", value });
|
|
265
110
|
},
|
|
111
|
+
/**
|
|
112
|
+
* Clears the value of the tabs.
|
|
113
|
+
*/
|
|
266
114
|
clearValue() {
|
|
267
115
|
send({ type: "CLEAR_VALUE" });
|
|
268
116
|
},
|
|
@@ -270,14 +118,14 @@ function connect(state, send, normalize) {
|
|
|
270
118
|
...parts.root.attrs,
|
|
271
119
|
id: dom.getRootId(state.context),
|
|
272
120
|
"data-orientation": state.context.orientation,
|
|
273
|
-
"data-focus": dataAttr(isFocused),
|
|
121
|
+
"data-focus": (0, import_dom_query2.dataAttr)(isFocused),
|
|
274
122
|
dir: state.context.dir
|
|
275
123
|
}),
|
|
276
124
|
tablistProps: normalize.element({
|
|
277
125
|
...parts.tablist.attrs,
|
|
278
126
|
id: dom.getTablistId(state.context),
|
|
279
127
|
role: "tablist",
|
|
280
|
-
"data-focus": dataAttr(isFocused),
|
|
128
|
+
"data-focus": (0, import_dom_query2.dataAttr)(isFocused),
|
|
281
129
|
"aria-orientation": state.context.orientation,
|
|
282
130
|
"data-orientation": state.context.orientation,
|
|
283
131
|
"aria-label": translations.tablistLabel,
|
|
@@ -305,7 +153,7 @@ function connect(state, send, normalize) {
|
|
|
305
153
|
send({ type: "ENTER", value: state.context.focusedValue });
|
|
306
154
|
}
|
|
307
155
|
};
|
|
308
|
-
let key = getEventKey(event, state.context);
|
|
156
|
+
let key = (0, import_dom_event.getEventKey)(event, state.context);
|
|
309
157
|
const exec = keyMap[key];
|
|
310
158
|
if (exec) {
|
|
311
159
|
event.preventDefault();
|
|
@@ -322,11 +170,11 @@ function connect(state, send, normalize) {
|
|
|
322
170
|
type: "button",
|
|
323
171
|
disabled,
|
|
324
172
|
"data-orientation": state.context.orientation,
|
|
325
|
-
"data-disabled": dataAttr(disabled),
|
|
173
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(disabled),
|
|
326
174
|
"aria-disabled": disabled,
|
|
327
175
|
"data-value": value,
|
|
328
176
|
"aria-selected": selected,
|
|
329
|
-
"data-selected": dataAttr(selected),
|
|
177
|
+
"data-selected": (0, import_dom_query2.dataAttr)(selected),
|
|
330
178
|
"aria-controls": dom.getContentId(state.context, value),
|
|
331
179
|
"data-ownedby": dom.getTablistId(state.context),
|
|
332
180
|
id: dom.getTriggerId(state.context, value),
|
|
@@ -343,7 +191,7 @@ function connect(state, send, normalize) {
|
|
|
343
191
|
onClick(event) {
|
|
344
192
|
if (disabled)
|
|
345
193
|
return;
|
|
346
|
-
if (isSafari()) {
|
|
194
|
+
if ((0, import_dom_query2.isSafari)()) {
|
|
347
195
|
event.currentTarget.focus();
|
|
348
196
|
}
|
|
349
197
|
send({ type: "TAB_CLICK", value });
|
|
@@ -387,9 +235,12 @@ function connect(state, send, normalize) {
|
|
|
387
235
|
|
|
388
236
|
// src/tabs.machine.ts
|
|
389
237
|
var import_core = require("@zag-js/core");
|
|
238
|
+
var import_dom_query3 = require("@zag-js/dom-query");
|
|
239
|
+
var import_tabbable = require("@zag-js/tabbable");
|
|
240
|
+
var import_utils2 = require("@zag-js/utils");
|
|
390
241
|
var { not } = import_core.guards;
|
|
391
242
|
function machine(userContext) {
|
|
392
|
-
const ctx = compact(userContext);
|
|
243
|
+
const ctx = (0, import_utils2.compact)(userContext);
|
|
393
244
|
return (0, import_core.createMachine)(
|
|
394
245
|
{
|
|
395
246
|
initial: "idle",
|
|
@@ -510,31 +361,31 @@ function machine(userContext) {
|
|
|
510
361
|
ctx2.onDelete?.({ value: evt.value });
|
|
511
362
|
},
|
|
512
363
|
focusFirstTab(ctx2) {
|
|
513
|
-
raf(() => dom.getFirstEl(ctx2)?.focus());
|
|
364
|
+
(0, import_dom_query3.raf)(() => dom.getFirstEl(ctx2)?.focus());
|
|
514
365
|
},
|
|
515
366
|
focusLastTab(ctx2) {
|
|
516
|
-
raf(() => dom.getLastEl(ctx2)?.focus());
|
|
367
|
+
(0, import_dom_query3.raf)(() => dom.getLastEl(ctx2)?.focus());
|
|
517
368
|
},
|
|
518
369
|
focusNextTab(ctx2) {
|
|
519
370
|
if (!ctx2.focusedValue)
|
|
520
371
|
return;
|
|
521
372
|
const next = dom.getNextEl(ctx2, ctx2.focusedValue);
|
|
522
|
-
raf(() => next?.focus());
|
|
373
|
+
(0, import_dom_query3.raf)(() => next?.focus());
|
|
523
374
|
},
|
|
524
375
|
focusPrevTab(ctx2) {
|
|
525
376
|
if (!ctx2.focusedValue)
|
|
526
377
|
return;
|
|
527
378
|
const prev = dom.getPrevEl(ctx2, ctx2.focusedValue);
|
|
528
|
-
raf(() => prev?.focus());
|
|
379
|
+
(0, import_dom_query3.raf)(() => prev?.focus());
|
|
529
380
|
},
|
|
530
381
|
setIndicatorRect(ctx2) {
|
|
531
|
-
nextTick(() => {
|
|
382
|
+
(0, import_dom_query3.nextTick)(() => {
|
|
532
383
|
if (!ctx2.isIndicatorRendered || !ctx2.value)
|
|
533
384
|
return;
|
|
534
385
|
ctx2.indicatorRect = dom.getRectById(ctx2, ctx2.value);
|
|
535
386
|
if (ctx2.hasMeasuredRect)
|
|
536
387
|
return;
|
|
537
|
-
nextTick(() => {
|
|
388
|
+
(0, import_dom_query3.nextTick)(() => {
|
|
538
389
|
ctx2.hasMeasuredRect = true;
|
|
539
390
|
});
|
|
540
391
|
});
|
|
@@ -558,11 +409,11 @@ function machine(userContext) {
|
|
|
558
409
|
},
|
|
559
410
|
// if tab panel contains focusable elements, remove the tabindex attribute
|
|
560
411
|
setContentTabIndex(ctx2) {
|
|
561
|
-
raf(() => {
|
|
412
|
+
(0, import_dom_query3.raf)(() => {
|
|
562
413
|
const panel = dom.getActiveContentEl(ctx2);
|
|
563
414
|
if (!panel)
|
|
564
415
|
return;
|
|
565
|
-
const focusables = getFocusables(panel);
|
|
416
|
+
const focusables = (0, import_tabbable.getFocusables)(panel);
|
|
566
417
|
if (focusables.length > 0) {
|
|
567
418
|
panel.removeAttribute("tabindex");
|
|
568
419
|
} else {
|
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
connect
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-5JW3YJ3I.mjs";
|
|
4
4
|
import {
|
|
5
5
|
anatomy
|
|
6
6
|
} from "./chunk-S2KW2DT4.mjs";
|
|
7
7
|
import {
|
|
8
8
|
machine
|
|
9
|
-
} from "./chunk-
|
|
10
|
-
import "./chunk-
|
|
9
|
+
} from "./chunk-JG2VX4ST.mjs";
|
|
10
|
+
import "./chunk-5ZMNIWHF.mjs";
|
|
11
11
|
export {
|
|
12
12
|
anatomy,
|
|
13
13
|
connect,
|
package/dist/tabs.connect.d.ts
CHANGED
|
@@ -3,10 +3,25 @@ import { State, Send, TabProps } from './tabs.types.js';
|
|
|
3
3
|
import '@zag-js/core';
|
|
4
4
|
|
|
5
5
|
declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
|
|
6
|
+
/**
|
|
7
|
+
* The current value of the tabs.
|
|
8
|
+
*/
|
|
6
9
|
value: string | null;
|
|
10
|
+
/**
|
|
11
|
+
* The value of the tab that is currently focused.
|
|
12
|
+
*/
|
|
7
13
|
focusedValue: string | null;
|
|
14
|
+
/**
|
|
15
|
+
* The previous values of the tabs in sequence of selection.
|
|
16
|
+
*/
|
|
8
17
|
previousValues: string[];
|
|
18
|
+
/**
|
|
19
|
+
* Sets the value of the tabs.
|
|
20
|
+
*/
|
|
9
21
|
setValue(value: string): void;
|
|
22
|
+
/**
|
|
23
|
+
* Clears the value of the tabs.
|
|
24
|
+
*/
|
|
10
25
|
clearValue(): void;
|
|
11
26
|
rootProps: T["element"];
|
|
12
27
|
tablistProps: T["element"];
|