@zag-js/tabs 2.0.0-next.2 → 2.0.0-next.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.mts +7 -8
- package/dist/index.d.ts +7 -8
- package/dist/index.js +16 -38
- package/dist/index.mjs +2 -7
- package/dist/tabs.anatomy.d.mts +2 -6
- package/dist/tabs.anatomy.d.ts +2 -6
- package/dist/tabs.anatomy.js +8 -33
- package/dist/tabs.anatomy.mjs +4 -7
- package/dist/tabs.connect.d.mts +4 -7
- package/dist/tabs.connect.d.ts +4 -7
- package/dist/tabs.connect.js +253 -231
- package/dist/tabs.connect.mjs +249 -204
- package/dist/tabs.dom.d.mts +27 -33
- package/dist/tabs.dom.d.ts +27 -33
- package/dist/tabs.dom.js +77 -84
- package/dist/tabs.dom.mjs +57 -44
- package/dist/tabs.machine.d.mts +2 -7
- package/dist/tabs.machine.d.ts +2 -7
- package/dist/tabs.machine.js +301 -329
- package/dist/tabs.machine.mjs +298 -294
- package/dist/tabs.props.d.mts +7 -12
- package/dist/tabs.props.d.ts +7 -12
- package/dist/tabs.props.js +33 -61
- package/dist/tabs.props.mjs +24 -31
- package/dist/tabs.types.d.mts +252 -194
- package/dist/tabs.types.d.ts +252 -194
- package/dist/tabs.types.js +4 -18
- package/dist/tabs.types.mjs +1 -0
- package/package.json +7 -7
package/dist/tabs.connect.js
CHANGED
|
@@ -1,234 +1,256 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/tabs.connect.ts
|
|
31
|
-
var tabs_connect_exports = {};
|
|
32
|
-
__export(tabs_connect_exports, {
|
|
33
|
-
connect: () => connect
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
34
4
|
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
5
|
+
const require_tabs_anatomy = require("./tabs.anatomy.js");
|
|
6
|
+
const require_tabs_dom = require("./tabs.dom.js");
|
|
7
|
+
let _zag_js_dom_query = require("@zag-js/dom-query");
|
|
8
|
+
let _zag_js_utils = require("@zag-js/utils");
|
|
9
|
+
// src/tabs.connect.ts
|
|
40
10
|
function connect(service, normalize) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
11
|
+
const { state, send, context, prop, scope, computed } = service;
|
|
12
|
+
const translations = prop("translations");
|
|
13
|
+
const focused = state.matches("focused");
|
|
14
|
+
const isVertical = prop("orientation") === "vertical";
|
|
15
|
+
const isHorizontal = prop("orientation") === "horizontal";
|
|
16
|
+
const virtualFocus = prop("virtualFocus");
|
|
17
|
+
const tabStopValue = context.get("tabStopValue") ?? context.get("value");
|
|
18
|
+
const activationDirection = computed("activationDirection");
|
|
19
|
+
const indicatorRect = context.get("indicatorRect");
|
|
20
|
+
const indicatorPending = context.get("ssr") || indicatorRect != null && isRectEmpty(indicatorRect);
|
|
21
|
+
function moveFocus(to) {
|
|
22
|
+
send({
|
|
23
|
+
type: "FOCUS.MOVE",
|
|
24
|
+
to,
|
|
25
|
+
src: "keyboard"
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function getRootState() {
|
|
29
|
+
return {
|
|
30
|
+
focused,
|
|
31
|
+
orientation: prop("orientation"),
|
|
32
|
+
activationDirection
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function getTriggerState(props) {
|
|
36
|
+
return {
|
|
37
|
+
selected: context.get("value") === props.value,
|
|
38
|
+
focused: context.get("focusedValue") === props.value,
|
|
39
|
+
disabled: !!props.disabled
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function getContentState(props) {
|
|
43
|
+
return {
|
|
44
|
+
...getRootState(),
|
|
45
|
+
selected: context.get("value") === props.value
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function getIndicatorState() {
|
|
49
|
+
const rect = context.get("indicatorRect");
|
|
50
|
+
return {
|
|
51
|
+
...getRootState(),
|
|
52
|
+
visible: !isRectEmpty(rect),
|
|
53
|
+
instant: context.get("indicatorInstant")
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
value: context.get("value"),
|
|
58
|
+
focusedValue: context.get("focusedValue"),
|
|
59
|
+
activationDirection,
|
|
60
|
+
setValue(value, reason = "script") {
|
|
61
|
+
send({
|
|
62
|
+
type: "VALUE.SET",
|
|
63
|
+
value,
|
|
64
|
+
src: reason
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
clearValue() {
|
|
68
|
+
send({
|
|
69
|
+
type: "VALUE.SET",
|
|
70
|
+
value: null,
|
|
71
|
+
src: "script"
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
setIndicatorRect(value) {
|
|
75
|
+
send({
|
|
76
|
+
type: "INDICATOR.SET",
|
|
77
|
+
value
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
syncTabIndex() {
|
|
81
|
+
send({ type: "CONTENT.SYNC" });
|
|
82
|
+
},
|
|
83
|
+
selectNext(fromValue) {
|
|
84
|
+
send({
|
|
85
|
+
type: "VALUE.STEP",
|
|
86
|
+
step: 1,
|
|
87
|
+
from: fromValue,
|
|
88
|
+
src: "script"
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
selectPrevious(fromValue) {
|
|
92
|
+
send({
|
|
93
|
+
type: "VALUE.STEP",
|
|
94
|
+
step: -1,
|
|
95
|
+
from: fromValue,
|
|
96
|
+
src: "script"
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
focus() {
|
|
100
|
+
const value = context.get("value");
|
|
101
|
+
if (!value) return;
|
|
102
|
+
require_tabs_dom.getTriggerEl(scope, value)?.focus();
|
|
103
|
+
},
|
|
104
|
+
getRootState,
|
|
105
|
+
getRootProps() {
|
|
106
|
+
const rootState = getRootState();
|
|
107
|
+
return normalize.element({
|
|
108
|
+
...require_tabs_anatomy.parts.root.attrs(scope.id),
|
|
109
|
+
"data-orientation": rootState.orientation,
|
|
110
|
+
"data-focus": (0, _zag_js_dom_query.dataAttr)(rootState.focused),
|
|
111
|
+
"data-activation-direction": rootState.activationDirection,
|
|
112
|
+
dir: prop("dir")
|
|
113
|
+
});
|
|
114
|
+
},
|
|
115
|
+
getListProps() {
|
|
116
|
+
const rootState = getRootState();
|
|
117
|
+
return normalize.element({
|
|
118
|
+
...require_tabs_anatomy.parts.list.attrs(scope.id),
|
|
119
|
+
role: "tablist",
|
|
120
|
+
dir: prop("dir"),
|
|
121
|
+
"data-focus": (0, _zag_js_dom_query.dataAttr)(rootState.focused),
|
|
122
|
+
"aria-orientation": rootState.orientation,
|
|
123
|
+
"data-orientation": rootState.orientation,
|
|
124
|
+
"data-activation-direction": rootState.activationDirection,
|
|
125
|
+
"aria-label": translations?.listLabel,
|
|
126
|
+
onKeyDown(event) {
|
|
127
|
+
if (event.defaultPrevented) return;
|
|
128
|
+
if ((0, _zag_js_dom_query.isComposingEvent)(event)) return;
|
|
129
|
+
if ((0, _zag_js_dom_query.isModifierKey)(event) || event.shiftKey) return;
|
|
130
|
+
if (!(0, _zag_js_dom_query.contains)(event.currentTarget, (0, _zag_js_dom_query.getEventTarget)(event))) return;
|
|
131
|
+
const exec = {
|
|
132
|
+
ArrowDown() {
|
|
133
|
+
if (isHorizontal) return;
|
|
134
|
+
moveFocus("next");
|
|
135
|
+
},
|
|
136
|
+
ArrowUp() {
|
|
137
|
+
if (isHorizontal) return;
|
|
138
|
+
moveFocus("prev");
|
|
139
|
+
},
|
|
140
|
+
ArrowLeft() {
|
|
141
|
+
if (isVertical) return;
|
|
142
|
+
moveFocus("prev");
|
|
143
|
+
},
|
|
144
|
+
ArrowRight() {
|
|
145
|
+
if (isVertical) return;
|
|
146
|
+
moveFocus("next");
|
|
147
|
+
},
|
|
148
|
+
Home() {
|
|
149
|
+
moveFocus("first");
|
|
150
|
+
},
|
|
151
|
+
End() {
|
|
152
|
+
moveFocus("last");
|
|
153
|
+
}
|
|
154
|
+
}[(0, _zag_js_dom_query.getEventKey)(event, {
|
|
155
|
+
dir: prop("dir"),
|
|
156
|
+
orientation: prop("orientation")
|
|
157
|
+
})];
|
|
158
|
+
if (exec) {
|
|
159
|
+
event.preventDefault();
|
|
160
|
+
exec(event);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
},
|
|
166
|
+
getTriggerState,
|
|
167
|
+
getTriggerProps(props) {
|
|
168
|
+
const { value, disabled } = props;
|
|
169
|
+
const triggerState = getTriggerState(props);
|
|
170
|
+
return normalize.button({
|
|
171
|
+
...require_tabs_anatomy.parts.trigger.attrs(scope.id),
|
|
172
|
+
role: "tab",
|
|
173
|
+
type: "button",
|
|
174
|
+
disabled,
|
|
175
|
+
dir: prop("dir"),
|
|
176
|
+
"data-orientation": prop("orientation"),
|
|
177
|
+
"data-disabled": (0, _zag_js_dom_query.dataAttr)(disabled),
|
|
178
|
+
"aria-disabled": disabled,
|
|
179
|
+
"data-value": value,
|
|
180
|
+
"aria-selected": triggerState.selected,
|
|
181
|
+
"data-selected": (0, _zag_js_dom_query.dataAttr)(triggerState.selected),
|
|
182
|
+
"data-focus": (0, _zag_js_dom_query.dataAttr)(triggerState.focused),
|
|
183
|
+
"aria-controls": triggerState.selected ? require_tabs_dom.getContentId(scope, value) : void 0,
|
|
184
|
+
"data-indicator-pending": (0, _zag_js_dom_query.dataAttr)(indicatorPending),
|
|
185
|
+
"data-activation-direction": activationDirection,
|
|
186
|
+
id: require_tabs_dom.getTriggerId(scope, value),
|
|
187
|
+
tabIndex: !virtualFocus && tabStopValue === value ? 0 : -1,
|
|
188
|
+
onFocus() {
|
|
189
|
+
send({
|
|
190
|
+
type: "TRIGGER.FOCUS",
|
|
191
|
+
value
|
|
192
|
+
});
|
|
193
|
+
},
|
|
194
|
+
onBlur(event) {
|
|
195
|
+
if ((0, _zag_js_dom_query.contains)(require_tabs_dom.getListEl(scope), event.relatedTarget)) return;
|
|
196
|
+
send({ type: "TRIGGER.BLUR" });
|
|
197
|
+
},
|
|
198
|
+
onClick(event) {
|
|
199
|
+
if (event.defaultPrevented) return;
|
|
200
|
+
if ((0, _zag_js_dom_query.isDownloadingEvent)(event)) return;
|
|
201
|
+
if ((0, _zag_js_dom_query.isOpeningInNewTab)(event)) return;
|
|
202
|
+
if (event.shiftKey && (0, _zag_js_dom_query.isAnchorElement)(event.currentTarget)) return;
|
|
203
|
+
if (disabled) return;
|
|
204
|
+
if ((0, _zag_js_dom_query.isSafari)()) event.currentTarget.focus();
|
|
205
|
+
const node = event.currentTarget;
|
|
206
|
+
if (prop("navigate") != null && (0, _zag_js_dom_query.isAnchorElement)(node)) event.preventDefault();
|
|
207
|
+
send({
|
|
208
|
+
type: "TRIGGER.CLICK",
|
|
209
|
+
value,
|
|
210
|
+
src: "trigger-click"
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
},
|
|
215
|
+
getContentState,
|
|
216
|
+
getContentProps(props) {
|
|
217
|
+
const { value } = props;
|
|
218
|
+
const contentState = getContentState(props);
|
|
219
|
+
return normalize.element({
|
|
220
|
+
...require_tabs_anatomy.parts.content.attrs(scope.id),
|
|
221
|
+
dir: prop("dir"),
|
|
222
|
+
id: require_tabs_dom.getContentId(scope, value),
|
|
223
|
+
tabIndex: virtualFocus ? -1 : contentState.selected && context.get("hasFocusableContent") ? void 0 : 0,
|
|
224
|
+
"aria-labelledby": require_tabs_dom.getTriggerId(scope, value),
|
|
225
|
+
role: "tabpanel",
|
|
226
|
+
"data-selected": (0, _zag_js_dom_query.dataAttr)(contentState.selected),
|
|
227
|
+
"data-orientation": contentState.orientation,
|
|
228
|
+
"data-activation-direction": contentState.activationDirection,
|
|
229
|
+
hidden: !contentState.selected
|
|
230
|
+
});
|
|
231
|
+
},
|
|
232
|
+
getIndicatorState,
|
|
233
|
+
getIndicatorProps() {
|
|
234
|
+
const indicatorState = getIndicatorState();
|
|
235
|
+
const rect = context.get("indicatorRect");
|
|
236
|
+
return normalize.element({
|
|
237
|
+
...require_tabs_anatomy.parts.indicator.attrs(scope.id),
|
|
238
|
+
dir: prop("dir"),
|
|
239
|
+
"data-orientation": indicatorState.orientation,
|
|
240
|
+
"data-instant": (0, _zag_js_dom_query.dataAttr)(indicatorState.instant),
|
|
241
|
+
"data-activation-direction": indicatorState.activationDirection,
|
|
242
|
+
hidden: !indicatorState.visible,
|
|
243
|
+
style: {
|
|
244
|
+
"--left": (0, _zag_js_utils.toPx)(rect?.x),
|
|
245
|
+
"--top": (0, _zag_js_utils.toPx)(rect?.y),
|
|
246
|
+
"--width": (0, _zag_js_utils.toPx)(rect?.width),
|
|
247
|
+
"--height": (0, _zag_js_utils.toPx)(rect?.height),
|
|
248
|
+
position: "absolute",
|
|
249
|
+
[isHorizontal ? "left" : "top"]: isHorizontal ? "var(--left)" : "var(--top)"
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
};
|
|
229
254
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
0 && (module.exports = {
|
|
233
|
-
connect
|
|
234
|
-
});
|
|
255
|
+
const isRectEmpty = (rect) => rect == null || rect.width === 0 && rect.height === 0 && rect.x === 0 && rect.y === 0;
|
|
256
|
+
exports.connect = connect;
|