@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.connect.js
CHANGED
|
@@ -1,92 +1,12 @@
|
|
|
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_connect_exports = {};
|
|
22
|
-
__export(tabs_connect_exports, {
|
|
23
|
-
connect: () => connect
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(tabs_connect_exports);
|
|
26
|
-
var import_dom_event = require("@zag-js/dom-event");
|
|
27
|
-
var import_dom_query2 = require("@zag-js/dom-query");
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
28
4
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
5
|
+
const domEvent = require('@zag-js/dom-event');
|
|
6
|
+
const domQuery = require('@zag-js/dom-query');
|
|
7
|
+
const tabs_anatomy = require('./tabs.anatomy.js');
|
|
8
|
+
const tabs_dom = require('./tabs.dom.js');
|
|
33
9
|
|
|
34
|
-
// src/tabs.dom.ts
|
|
35
|
-
var import_dom_query = require("@zag-js/dom-query");
|
|
36
|
-
var import_utils = require("@zag-js/utils");
|
|
37
|
-
var dom = (0, import_dom_query.createScope)({
|
|
38
|
-
getRootId: (ctx) => ctx.ids?.root ?? `tabs:${ctx.id}`,
|
|
39
|
-
getTablistId: (ctx) => ctx.ids?.tablist ?? `tabs:${ctx.id}:list`,
|
|
40
|
-
getContentId: (ctx, id) => ctx.ids?.content ?? `tabs:${ctx.id}:content-${id}`,
|
|
41
|
-
getContentGroupId: (ctx) => ctx.ids?.contentGroup ?? `tabs:${ctx.id}:content-group`,
|
|
42
|
-
getTriggerId: (ctx, id) => ctx.ids?.trigger ?? `tabs:${ctx.id}:trigger-${id}`,
|
|
43
|
-
getIndicatorId: (ctx) => ctx.ids?.indicator ?? `tabs:${ctx.id}:indicator`,
|
|
44
|
-
getTablistEl: (ctx) => dom.getById(ctx, dom.getTablistId(ctx)),
|
|
45
|
-
getContentEl: (ctx, id) => dom.getById(ctx, dom.getContentId(ctx, id)),
|
|
46
|
-
getTriggerEl: (ctx, id) => dom.getById(ctx, dom.getTriggerId(ctx, id)),
|
|
47
|
-
getIndicatorEl: (ctx) => dom.getById(ctx, dom.getIndicatorId(ctx)),
|
|
48
|
-
getElements: (ctx) => {
|
|
49
|
-
const ownerId = CSS.escape(dom.getTablistId(ctx));
|
|
50
|
-
const selector = `[role=tab][data-ownedby='${ownerId}']:not([disabled])`;
|
|
51
|
-
return (0, import_dom_query.queryAll)(dom.getTablistEl(ctx), selector);
|
|
52
|
-
},
|
|
53
|
-
getFirstEl: (ctx) => (0, import_utils.first)(dom.getElements(ctx)),
|
|
54
|
-
getLastEl: (ctx) => (0, import_utils.last)(dom.getElements(ctx)),
|
|
55
|
-
getNextEl: (ctx, id) => (0, import_dom_query.nextById)(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
|
|
56
|
-
getPrevEl: (ctx, id) => (0, import_dom_query.prevById)(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
|
|
57
|
-
getActiveContentEl: (ctx) => {
|
|
58
|
-
if (!ctx.value)
|
|
59
|
-
return;
|
|
60
|
-
return dom.getContentEl(ctx, ctx.value);
|
|
61
|
-
},
|
|
62
|
-
getActiveTabEl: (ctx) => {
|
|
63
|
-
if (!ctx.value)
|
|
64
|
-
return;
|
|
65
|
-
return dom.getTriggerEl(ctx, ctx.value);
|
|
66
|
-
},
|
|
67
|
-
getOffsetRect: (el) => {
|
|
68
|
-
return {
|
|
69
|
-
left: el?.offsetLeft ?? 0,
|
|
70
|
-
top: el?.offsetTop ?? 0,
|
|
71
|
-
width: el?.offsetWidth ?? 0,
|
|
72
|
-
height: el?.offsetHeight ?? 0
|
|
73
|
-
};
|
|
74
|
-
},
|
|
75
|
-
getRectById: (ctx, id) => {
|
|
76
|
-
const tab = (0, import_dom_query.itemById)(dom.getElements(ctx), dom.getTriggerId(ctx, id));
|
|
77
|
-
return dom.resolveRect(dom.getOffsetRect(tab), ctx.orientation);
|
|
78
|
-
},
|
|
79
|
-
resolveRect(rect, orientation) {
|
|
80
|
-
const sizeProp = orientation === "vertical" ? "height" : "width";
|
|
81
|
-
const placementProp = orientation === "vertical" ? "top" : "left";
|
|
82
|
-
return {
|
|
83
|
-
[placementProp]: `${rect[placementProp]}px`,
|
|
84
|
-
[sizeProp]: `${rect[sizeProp]}px`
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
// src/tabs.connect.ts
|
|
90
10
|
function connect(state, send, normalize) {
|
|
91
11
|
const translations = state.context.translations;
|
|
92
12
|
const isFocused = state.matches("focused");
|
|
@@ -122,17 +42,17 @@ function connect(state, send, normalize) {
|
|
|
122
42
|
send({ type: "SET_INDICATOR_RECT", id });
|
|
123
43
|
},
|
|
124
44
|
rootProps: normalize.element({
|
|
125
|
-
...parts.root.attrs,
|
|
126
|
-
id: dom.getRootId(state.context),
|
|
45
|
+
...tabs_anatomy.parts.root.attrs,
|
|
46
|
+
id: tabs_dom.dom.getRootId(state.context),
|
|
127
47
|
"data-orientation": state.context.orientation,
|
|
128
|
-
"data-focus":
|
|
48
|
+
"data-focus": domQuery.dataAttr(isFocused),
|
|
129
49
|
dir: state.context.dir
|
|
130
50
|
}),
|
|
131
51
|
tablistProps: normalize.element({
|
|
132
|
-
...parts.tablist.attrs,
|
|
133
|
-
id: dom.getTablistId(state.context),
|
|
52
|
+
...tabs_anatomy.parts.tablist.attrs,
|
|
53
|
+
id: tabs_dom.dom.getTablistId(state.context),
|
|
134
54
|
role: "tablist",
|
|
135
|
-
"data-focus":
|
|
55
|
+
"data-focus": domQuery.dataAttr(isFocused),
|
|
136
56
|
"aria-orientation": state.context.orientation,
|
|
137
57
|
"data-orientation": state.context.orientation,
|
|
138
58
|
"aria-label": translations.tablistLabel,
|
|
@@ -160,7 +80,7 @@ function connect(state, send, normalize) {
|
|
|
160
80
|
send({ type: "ENTER", value: state.context.focusedValue });
|
|
161
81
|
}
|
|
162
82
|
};
|
|
163
|
-
let key =
|
|
83
|
+
let key = domEvent.getEventKey(event, state.context);
|
|
164
84
|
const exec = keyMap[key];
|
|
165
85
|
if (exec) {
|
|
166
86
|
event.preventDefault();
|
|
@@ -172,19 +92,19 @@ function connect(state, send, normalize) {
|
|
|
172
92
|
const { value, disabled } = props;
|
|
173
93
|
const selected = state.context.value === value;
|
|
174
94
|
return normalize.button({
|
|
175
|
-
...parts.trigger.attrs,
|
|
95
|
+
...tabs_anatomy.parts.trigger.attrs,
|
|
176
96
|
role: "tab",
|
|
177
97
|
type: "button",
|
|
178
98
|
disabled,
|
|
179
99
|
"data-orientation": state.context.orientation,
|
|
180
|
-
"data-disabled":
|
|
100
|
+
"data-disabled": domQuery.dataAttr(disabled),
|
|
181
101
|
"aria-disabled": disabled,
|
|
182
102
|
"data-value": value,
|
|
183
103
|
"aria-selected": selected,
|
|
184
|
-
"data-selected":
|
|
185
|
-
"aria-controls": dom.getContentId(state.context, value),
|
|
186
|
-
"data-ownedby": dom.getTablistId(state.context),
|
|
187
|
-
id: dom.getTriggerId(state.context, value),
|
|
104
|
+
"data-selected": domQuery.dataAttr(selected),
|
|
105
|
+
"aria-controls": tabs_dom.dom.getContentId(state.context, value),
|
|
106
|
+
"data-ownedby": tabs_dom.dom.getTablistId(state.context),
|
|
107
|
+
id: tabs_dom.dom.getTriggerId(state.context, value),
|
|
188
108
|
tabIndex: selected ? 0 : -1,
|
|
189
109
|
onFocus() {
|
|
190
110
|
send({ type: "TAB_FOCUS", value });
|
|
@@ -198,7 +118,7 @@ function connect(state, send, normalize) {
|
|
|
198
118
|
onClick(event) {
|
|
199
119
|
if (disabled)
|
|
200
120
|
return;
|
|
201
|
-
if (
|
|
121
|
+
if (domQuery.isSafari()) {
|
|
202
122
|
event.currentTarget.focus();
|
|
203
123
|
}
|
|
204
124
|
send({ type: "TAB_CLICK", value });
|
|
@@ -206,25 +126,25 @@ function connect(state, send, normalize) {
|
|
|
206
126
|
});
|
|
207
127
|
},
|
|
208
128
|
contentGroupProps: normalize.element({
|
|
209
|
-
...parts.contentGroup.attrs,
|
|
210
|
-
id: dom.getContentGroupId(state.context),
|
|
129
|
+
...tabs_anatomy.parts.contentGroup.attrs,
|
|
130
|
+
id: tabs_dom.dom.getContentGroupId(state.context),
|
|
211
131
|
"data-orientation": state.context.orientation
|
|
212
132
|
}),
|
|
213
133
|
getContentProps({ value }) {
|
|
214
134
|
const selected = state.context.value === value;
|
|
215
135
|
return normalize.element({
|
|
216
|
-
...parts.content.attrs,
|
|
217
|
-
id: dom.getContentId(state.context, value),
|
|
136
|
+
...tabs_anatomy.parts.content.attrs,
|
|
137
|
+
id: tabs_dom.dom.getContentId(state.context, value),
|
|
218
138
|
tabIndex: 0,
|
|
219
|
-
"aria-labelledby": dom.getTriggerId(state.context, value),
|
|
139
|
+
"aria-labelledby": tabs_dom.dom.getTriggerId(state.context, value),
|
|
220
140
|
role: "tabpanel",
|
|
221
|
-
"data-ownedby": dom.getTablistId(state.context),
|
|
141
|
+
"data-ownedby": tabs_dom.dom.getTablistId(state.context),
|
|
222
142
|
hidden: !selected
|
|
223
143
|
});
|
|
224
144
|
},
|
|
225
145
|
indicatorProps: normalize.element({
|
|
226
|
-
id: dom.getIndicatorId(state.context),
|
|
227
|
-
...parts.indicator.attrs,
|
|
146
|
+
id: tabs_dom.dom.getIndicatorId(state.context),
|
|
147
|
+
...tabs_anatomy.parts.indicator.attrs,
|
|
228
148
|
"data-orientation": state.context.orientation,
|
|
229
149
|
style: {
|
|
230
150
|
"--transition-duration": "150ms",
|
|
@@ -239,7 +159,5 @@ function connect(state, send, normalize) {
|
|
|
239
159
|
})
|
|
240
160
|
};
|
|
241
161
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
connect
|
|
245
|
-
});
|
|
162
|
+
|
|
163
|
+
exports.connect = connect;
|
package/dist/tabs.connect.mjs
CHANGED
|
@@ -1,8 +1,159 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { getEventKey } from '@zag-js/dom-event';
|
|
2
|
+
import { dataAttr, isSafari } from '@zag-js/dom-query';
|
|
3
|
+
import { parts } from './tabs.anatomy.mjs';
|
|
4
|
+
import { dom } from './tabs.dom.mjs';
|
|
5
|
+
|
|
6
|
+
function connect(state, send, normalize) {
|
|
7
|
+
const translations = state.context.translations;
|
|
8
|
+
const isFocused = state.matches("focused");
|
|
9
|
+
return {
|
|
10
|
+
/**
|
|
11
|
+
* The current value of the tabs.
|
|
12
|
+
*/
|
|
13
|
+
value: state.context.value,
|
|
14
|
+
/**
|
|
15
|
+
* The value of the tab that is currently focused.
|
|
16
|
+
*/
|
|
17
|
+
focusedValue: state.context.focusedValue,
|
|
18
|
+
/**
|
|
19
|
+
* The previous values of the tabs in sequence of selection.
|
|
20
|
+
*/
|
|
21
|
+
previousValues: Array.from(state.context.previousValues),
|
|
22
|
+
/**
|
|
23
|
+
* Sets the value of the tabs.
|
|
24
|
+
*/
|
|
25
|
+
setValue(value) {
|
|
26
|
+
send({ type: "SET_VALUE", value });
|
|
27
|
+
},
|
|
28
|
+
/**
|
|
29
|
+
* Clears the value of the tabs.
|
|
30
|
+
*/
|
|
31
|
+
clearValue() {
|
|
32
|
+
send({ type: "CLEAR_VALUE" });
|
|
33
|
+
},
|
|
34
|
+
/**
|
|
35
|
+
* Sets the indicator rect to the tab with the given id.
|
|
36
|
+
*/
|
|
37
|
+
setIndicatorRect(id) {
|
|
38
|
+
send({ type: "SET_INDICATOR_RECT", id });
|
|
39
|
+
},
|
|
40
|
+
rootProps: normalize.element({
|
|
41
|
+
...parts.root.attrs,
|
|
42
|
+
id: dom.getRootId(state.context),
|
|
43
|
+
"data-orientation": state.context.orientation,
|
|
44
|
+
"data-focus": dataAttr(isFocused),
|
|
45
|
+
dir: state.context.dir
|
|
46
|
+
}),
|
|
47
|
+
tablistProps: normalize.element({
|
|
48
|
+
...parts.tablist.attrs,
|
|
49
|
+
id: dom.getTablistId(state.context),
|
|
50
|
+
role: "tablist",
|
|
51
|
+
"data-focus": dataAttr(isFocused),
|
|
52
|
+
"aria-orientation": state.context.orientation,
|
|
53
|
+
"data-orientation": state.context.orientation,
|
|
54
|
+
"aria-label": translations.tablistLabel,
|
|
55
|
+
onKeyDown(event) {
|
|
56
|
+
const keyMap = {
|
|
57
|
+
ArrowDown() {
|
|
58
|
+
send("ARROW_DOWN");
|
|
59
|
+
},
|
|
60
|
+
ArrowUp() {
|
|
61
|
+
send("ARROW_UP");
|
|
62
|
+
},
|
|
63
|
+
ArrowLeft() {
|
|
64
|
+
send("ARROW_LEFT");
|
|
65
|
+
},
|
|
66
|
+
ArrowRight() {
|
|
67
|
+
send("ARROW_RIGHT");
|
|
68
|
+
},
|
|
69
|
+
Home() {
|
|
70
|
+
send("HOME");
|
|
71
|
+
},
|
|
72
|
+
End() {
|
|
73
|
+
send("END");
|
|
74
|
+
},
|
|
75
|
+
Enter() {
|
|
76
|
+
send({ type: "ENTER", value: state.context.focusedValue });
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
let key = getEventKey(event, state.context);
|
|
80
|
+
const exec = keyMap[key];
|
|
81
|
+
if (exec) {
|
|
82
|
+
event.preventDefault();
|
|
83
|
+
exec(event);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}),
|
|
87
|
+
getTriggerProps(props) {
|
|
88
|
+
const { value, disabled } = props;
|
|
89
|
+
const selected = state.context.value === value;
|
|
90
|
+
return normalize.button({
|
|
91
|
+
...parts.trigger.attrs,
|
|
92
|
+
role: "tab",
|
|
93
|
+
type: "button",
|
|
94
|
+
disabled,
|
|
95
|
+
"data-orientation": state.context.orientation,
|
|
96
|
+
"data-disabled": dataAttr(disabled),
|
|
97
|
+
"aria-disabled": disabled,
|
|
98
|
+
"data-value": value,
|
|
99
|
+
"aria-selected": selected,
|
|
100
|
+
"data-selected": dataAttr(selected),
|
|
101
|
+
"aria-controls": dom.getContentId(state.context, value),
|
|
102
|
+
"data-ownedby": dom.getTablistId(state.context),
|
|
103
|
+
id: dom.getTriggerId(state.context, value),
|
|
104
|
+
tabIndex: selected ? 0 : -1,
|
|
105
|
+
onFocus() {
|
|
106
|
+
send({ type: "TAB_FOCUS", value });
|
|
107
|
+
},
|
|
108
|
+
onBlur(event) {
|
|
109
|
+
const target = event.relatedTarget;
|
|
110
|
+
if (target?.getAttribute("role") !== "tab") {
|
|
111
|
+
send({ type: "TAB_BLUR" });
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
onClick(event) {
|
|
115
|
+
if (disabled)
|
|
116
|
+
return;
|
|
117
|
+
if (isSafari()) {
|
|
118
|
+
event.currentTarget.focus();
|
|
119
|
+
}
|
|
120
|
+
send({ type: "TAB_CLICK", value });
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
},
|
|
124
|
+
contentGroupProps: normalize.element({
|
|
125
|
+
...parts.contentGroup.attrs,
|
|
126
|
+
id: dom.getContentGroupId(state.context),
|
|
127
|
+
"data-orientation": state.context.orientation
|
|
128
|
+
}),
|
|
129
|
+
getContentProps({ value }) {
|
|
130
|
+
const selected = state.context.value === value;
|
|
131
|
+
return normalize.element({
|
|
132
|
+
...parts.content.attrs,
|
|
133
|
+
id: dom.getContentId(state.context, value),
|
|
134
|
+
tabIndex: 0,
|
|
135
|
+
"aria-labelledby": dom.getTriggerId(state.context, value),
|
|
136
|
+
role: "tabpanel",
|
|
137
|
+
"data-ownedby": dom.getTablistId(state.context),
|
|
138
|
+
hidden: !selected
|
|
139
|
+
});
|
|
140
|
+
},
|
|
141
|
+
indicatorProps: normalize.element({
|
|
142
|
+
id: dom.getIndicatorId(state.context),
|
|
143
|
+
...parts.indicator.attrs,
|
|
144
|
+
"data-orientation": state.context.orientation,
|
|
145
|
+
style: {
|
|
146
|
+
"--transition-duration": "150ms",
|
|
147
|
+
"--transition-property": "left, right, top, bottom, width, height",
|
|
148
|
+
position: "absolute",
|
|
149
|
+
willChange: "var(--transition-property)",
|
|
150
|
+
transitionProperty: "var(--transition-property)",
|
|
151
|
+
transitionDuration: state.context.canIndicatorTransition ? "var(--transition-duration)" : "0ms",
|
|
152
|
+
transitionTimingFunction: "var(--transition-timing-function)",
|
|
153
|
+
...state.context.indicatorRect
|
|
154
|
+
}
|
|
155
|
+
})
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export { connect };
|
package/dist/tabs.dom.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { MachineContext } from
|
|
2
|
-
|
|
3
|
-
import '@zag-js/types';
|
|
4
|
-
|
|
5
|
-
declare const dom: {
|
|
1
|
+
import type { MachineContext as Ctx } from "./tabs.types";
|
|
2
|
+
export declare const dom: {
|
|
6
3
|
getRootNode: (ctx: {
|
|
7
4
|
getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
|
|
8
5
|
}) => Document | ShadowRoot;
|
|
@@ -22,35 +19,33 @@ declare const dom: {
|
|
|
22
19
|
getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
|
|
23
20
|
}, id: string) => T_1;
|
|
24
21
|
} & {
|
|
25
|
-
getRootId: (ctx:
|
|
26
|
-
getTablistId: (ctx:
|
|
27
|
-
getContentId: (ctx:
|
|
28
|
-
getContentGroupId: (ctx:
|
|
29
|
-
getTriggerId: (ctx:
|
|
30
|
-
getIndicatorId: (ctx:
|
|
31
|
-
getTablistEl: (ctx:
|
|
32
|
-
getContentEl: (ctx:
|
|
33
|
-
getTriggerEl: (ctx:
|
|
34
|
-
getIndicatorEl: (ctx:
|
|
35
|
-
getElements: (ctx:
|
|
36
|
-
getFirstEl: (ctx:
|
|
37
|
-
getLastEl: (ctx:
|
|
38
|
-
getNextEl: (ctx:
|
|
39
|
-
getPrevEl: (ctx:
|
|
40
|
-
getActiveContentEl: (ctx:
|
|
41
|
-
getActiveTabEl: (ctx:
|
|
22
|
+
getRootId: (ctx: Ctx) => string;
|
|
23
|
+
getTablistId: (ctx: Ctx) => string;
|
|
24
|
+
getContentId: (ctx: Ctx, id: string) => string;
|
|
25
|
+
getContentGroupId: (ctx: Ctx) => string;
|
|
26
|
+
getTriggerId: (ctx: Ctx, id: string) => string;
|
|
27
|
+
getIndicatorId: (ctx: Ctx) => string;
|
|
28
|
+
getTablistEl: (ctx: Ctx) => HTMLElement | null;
|
|
29
|
+
getContentEl: (ctx: Ctx, id: string) => HTMLElement | null;
|
|
30
|
+
getTriggerEl: (ctx: Ctx, id: string) => HTMLElement | null;
|
|
31
|
+
getIndicatorEl: (ctx: Ctx) => HTMLElement | null;
|
|
32
|
+
getElements: (ctx: Ctx) => HTMLElement[];
|
|
33
|
+
getFirstEl: (ctx: Ctx) => HTMLElement | undefined;
|
|
34
|
+
getLastEl: (ctx: Ctx) => HTMLElement | undefined;
|
|
35
|
+
getNextEl: (ctx: Ctx, id: string) => HTMLElement;
|
|
36
|
+
getPrevEl: (ctx: Ctx, id: string) => HTMLElement | null;
|
|
37
|
+
getActiveContentEl: (ctx: Ctx) => HTMLElement | null | undefined;
|
|
38
|
+
getActiveTabEl: (ctx: Ctx) => HTMLElement | null | undefined;
|
|
42
39
|
getOffsetRect: (el: HTMLElement | undefined) => {
|
|
43
40
|
left: number;
|
|
44
41
|
top: number;
|
|
45
42
|
width: number;
|
|
46
43
|
height: number;
|
|
47
44
|
};
|
|
48
|
-
getRectById: (ctx:
|
|
45
|
+
getRectById: (ctx: Ctx, id: string) => {
|
|
49
46
|
[x: string]: string;
|
|
50
47
|
};
|
|
51
48
|
resolveRect(rect: Record<"width" | "height" | "left" | "top", number>, orientation?: "horizontal" | "vertical"): {
|
|
52
49
|
[x: string]: string;
|
|
53
50
|
};
|
|
54
51
|
};
|
|
55
|
-
|
|
56
|
-
export { dom };
|
package/dist/tabs.dom.js
CHANGED
|
@@ -1,31 +1,11 @@
|
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
var import_dom_query = require("@zag-js/dom-query");
|
|
27
|
-
var import_utils = require("@zag-js/utils");
|
|
28
|
-
var dom = (0, import_dom_query.createScope)({
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
const domQuery = require('@zag-js/dom-query');
|
|
6
|
+
const utils = require('@zag-js/utils');
|
|
7
|
+
|
|
8
|
+
const dom = domQuery.createScope({
|
|
29
9
|
getRootId: (ctx) => ctx.ids?.root ?? `tabs:${ctx.id}`,
|
|
30
10
|
getTablistId: (ctx) => ctx.ids?.tablist ?? `tabs:${ctx.id}:list`,
|
|
31
11
|
getContentId: (ctx, id) => ctx.ids?.content ?? `tabs:${ctx.id}:content-${id}`,
|
|
@@ -39,12 +19,12 @@ var dom = (0, import_dom_query.createScope)({
|
|
|
39
19
|
getElements: (ctx) => {
|
|
40
20
|
const ownerId = CSS.escape(dom.getTablistId(ctx));
|
|
41
21
|
const selector = `[role=tab][data-ownedby='${ownerId}']:not([disabled])`;
|
|
42
|
-
return
|
|
22
|
+
return domQuery.queryAll(dom.getTablistEl(ctx), selector);
|
|
43
23
|
},
|
|
44
|
-
getFirstEl: (ctx) =>
|
|
45
|
-
getLastEl: (ctx) =>
|
|
46
|
-
getNextEl: (ctx, id) =>
|
|
47
|
-
getPrevEl: (ctx, id) =>
|
|
24
|
+
getFirstEl: (ctx) => utils.first(dom.getElements(ctx)),
|
|
25
|
+
getLastEl: (ctx) => utils.last(dom.getElements(ctx)),
|
|
26
|
+
getNextEl: (ctx, id) => domQuery.nextById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
|
|
27
|
+
getPrevEl: (ctx, id) => domQuery.prevById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
|
|
48
28
|
getActiveContentEl: (ctx) => {
|
|
49
29
|
if (!ctx.value)
|
|
50
30
|
return;
|
|
@@ -64,7 +44,7 @@ var dom = (0, import_dom_query.createScope)({
|
|
|
64
44
|
};
|
|
65
45
|
},
|
|
66
46
|
getRectById: (ctx, id) => {
|
|
67
|
-
const tab =
|
|
47
|
+
const tab = domQuery.itemById(dom.getElements(ctx), dom.getTriggerId(ctx, id));
|
|
68
48
|
return dom.resolveRect(dom.getOffsetRect(tab), ctx.orientation);
|
|
69
49
|
},
|
|
70
50
|
resolveRect(rect, orientation) {
|
|
@@ -76,7 +56,5 @@ var dom = (0, import_dom_query.createScope)({
|
|
|
76
56
|
};
|
|
77
57
|
}
|
|
78
58
|
});
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
dom
|
|
82
|
-
});
|
|
59
|
+
|
|
60
|
+
exports.dom = dom;
|
package/dist/tabs.dom.mjs
CHANGED
|
@@ -1,6 +1,56 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
1
|
+
import { createScope, queryAll, nextById, prevById, itemById } from '@zag-js/dom-query';
|
|
2
|
+
import { first, last } from '@zag-js/utils';
|
|
3
|
+
|
|
4
|
+
const 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 { dom };
|
package/dist/tabs.machine.d.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
|
|
6
|
-
|
|
7
|
-
export { machine };
|
|
1
|
+
import { Machine, StateMachine } from '@zag-js/core';
|
|
2
|
+
import type { MachineContext, MachineState, UserDefinedContext } from "./tabs.types";
|
|
3
|
+
export declare function machine(userContext: UserDefinedContext): Machine<MachineContext, MachineState, StateMachine.AnyEventObject>;
|