@zag-js/tabs 0.1.15 → 0.2.1
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 +1 -1
- package/dist/index.js +56 -20
- package/dist/index.mjs +56 -20
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -110,6 +110,6 @@ declare function connect<T extends PropTypes>(state: State, send: Send, normaliz
|
|
|
110
110
|
indicatorProps: T["element"];
|
|
111
111
|
};
|
|
112
112
|
|
|
113
|
-
declare function machine(
|
|
113
|
+
declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
|
|
114
114
|
|
|
115
115
|
export { UserDefinedContext as Context, connect, machine };
|
package/dist/index.js
CHANGED
|
@@ -31,8 +31,9 @@ var dataAttr = (guard) => {
|
|
|
31
31
|
};
|
|
32
32
|
var isDom = () => typeof window !== "undefined";
|
|
33
33
|
function getPlatform() {
|
|
34
|
+
var _a;
|
|
34
35
|
const agent = navigator.userAgentData;
|
|
35
|
-
return (agent == null ? void 0 : agent.platform)
|
|
36
|
+
return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
|
|
36
37
|
}
|
|
37
38
|
var pt = (v) => isDom() && v.test(getPlatform());
|
|
38
39
|
var vn = (v) => isDom() && v.test(navigator.vendor);
|
|
@@ -48,22 +49,44 @@ function isFrame(element) {
|
|
|
48
49
|
return element.localName === "iframe";
|
|
49
50
|
}
|
|
50
51
|
function getDocument(el) {
|
|
52
|
+
var _a;
|
|
51
53
|
if (isWindow(el))
|
|
52
54
|
return el.document;
|
|
53
55
|
if (isDocument(el))
|
|
54
56
|
return el;
|
|
55
|
-
return (el == null ? void 0 : el.ownerDocument)
|
|
57
|
+
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
56
58
|
}
|
|
57
59
|
function defineDomHelpers(helpers) {
|
|
58
60
|
const dom2 = {
|
|
59
61
|
getRootNode: (ctx) => {
|
|
60
|
-
var _a;
|
|
61
|
-
return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx))
|
|
62
|
+
var _a, _b;
|
|
63
|
+
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
62
64
|
},
|
|
63
65
|
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
64
|
-
getWin: (ctx) =>
|
|
66
|
+
getWin: (ctx) => {
|
|
67
|
+
var _a;
|
|
68
|
+
return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
|
|
69
|
+
},
|
|
65
70
|
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
66
|
-
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
71
|
+
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
|
|
72
|
+
createEmitter: (ctx, target) => {
|
|
73
|
+
const win = dom2.getWin(ctx);
|
|
74
|
+
return function emit(evt, detail, options) {
|
|
75
|
+
const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
|
|
76
|
+
const eventName = `zag:${evt}`;
|
|
77
|
+
const init = { bubbles, cancelable, composed, detail };
|
|
78
|
+
const event = new win.CustomEvent(eventName, init);
|
|
79
|
+
target.dispatchEvent(event);
|
|
80
|
+
};
|
|
81
|
+
},
|
|
82
|
+
createListener: (target) => {
|
|
83
|
+
return function listen(evt, handler) {
|
|
84
|
+
const eventName = `zag:${evt}`;
|
|
85
|
+
const listener = (e) => handler(e);
|
|
86
|
+
target.addEventListener(eventName, listener);
|
|
87
|
+
return () => target.removeEventListener(eventName, listener);
|
|
88
|
+
};
|
|
89
|
+
}
|
|
67
90
|
};
|
|
68
91
|
return {
|
|
69
92
|
...dom2,
|
|
@@ -115,9 +138,10 @@ var sameKeyMap = {
|
|
|
115
138
|
Right: "ArrowRight"
|
|
116
139
|
};
|
|
117
140
|
function getEventKey(event, options = {}) {
|
|
141
|
+
var _a;
|
|
118
142
|
const { dir = "ltr", orientation = "horizontal" } = options;
|
|
119
143
|
let { key } = event;
|
|
120
|
-
key = sameKeyMap[key]
|
|
144
|
+
key = (_a = sameKeyMap[key]) != null ? _a : key;
|
|
121
145
|
const isRtl = dir === "rtl" && orientation === "horizontal";
|
|
122
146
|
if (isRtl && key in rtlKeyMap) {
|
|
123
147
|
key = rtlKeyMap[key];
|
|
@@ -144,7 +168,8 @@ function raf(fn) {
|
|
|
144
168
|
};
|
|
145
169
|
}
|
|
146
170
|
function queryAll(root, selector) {
|
|
147
|
-
|
|
171
|
+
var _a;
|
|
172
|
+
return Array.from((_a = root == null ? void 0 : root.querySelectorAll(selector)) != null ? _a : []);
|
|
148
173
|
}
|
|
149
174
|
function itemById(v, id) {
|
|
150
175
|
return v.find((node) => node.id === id);
|
|
@@ -169,28 +194,37 @@ function prevById(v, id, loop = true) {
|
|
|
169
194
|
// ../../utilities/core/dist/index.mjs
|
|
170
195
|
var first = (v) => v[0];
|
|
171
196
|
var last = (v) => v[v.length - 1];
|
|
197
|
+
var isArray = (v) => Array.isArray(v);
|
|
198
|
+
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
199
|
+
function compact(obj) {
|
|
200
|
+
if (obj === void 0)
|
|
201
|
+
return obj;
|
|
202
|
+
return Object.fromEntries(
|
|
203
|
+
Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
|
|
204
|
+
);
|
|
205
|
+
}
|
|
172
206
|
|
|
173
207
|
// src/tabs.dom.ts
|
|
174
208
|
var dom = defineDomHelpers({
|
|
175
209
|
getRootId: (ctx) => {
|
|
176
|
-
var _a;
|
|
177
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.root)
|
|
210
|
+
var _a, _b;
|
|
211
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `tabs:${ctx.id}`;
|
|
178
212
|
},
|
|
179
213
|
getTriggerGroupId: (ctx) => {
|
|
180
|
-
var _a;
|
|
181
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.triggerGroup)
|
|
214
|
+
var _a, _b;
|
|
215
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.triggerGroup) != null ? _b : `tabs:${ctx.id}:trigger-group`;
|
|
182
216
|
},
|
|
183
217
|
getContentId: (ctx, id) => {
|
|
184
|
-
var _a;
|
|
185
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.content)
|
|
218
|
+
var _a, _b;
|
|
219
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.content) != null ? _b : `tabs:${ctx.id}:content-${id}`;
|
|
186
220
|
},
|
|
187
221
|
getContentGroupId: (ctx) => {
|
|
188
|
-
var _a;
|
|
189
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.contentGroup)
|
|
222
|
+
var _a, _b;
|
|
223
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.contentGroup) != null ? _b : `tabs:${ctx.id}:content-group`;
|
|
190
224
|
},
|
|
191
225
|
getTriggerId: (ctx, id) => {
|
|
192
|
-
var _a;
|
|
193
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.trigger)
|
|
226
|
+
var _a, _b;
|
|
227
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.trigger) != null ? _b : `tabs:${ctx.id}:trigger-${id}`;
|
|
194
228
|
},
|
|
195
229
|
getIndicatorId: (ctx) => `tabs:${ctx.id}:indicator`,
|
|
196
230
|
getTriggerGroupEl: (ctx) => dom.getById(ctx, dom.getTriggerGroupId(ctx)),
|
|
@@ -213,13 +247,14 @@ var dom = defineDomHelpers({
|
|
|
213
247
|
return dom.getById(ctx, id);
|
|
214
248
|
},
|
|
215
249
|
getRectById: (ctx, id) => {
|
|
250
|
+
var _a;
|
|
216
251
|
const empty = {
|
|
217
252
|
offsetLeft: 0,
|
|
218
253
|
offsetTop: 0,
|
|
219
254
|
offsetWidth: 0,
|
|
220
255
|
offsetHeight: 0
|
|
221
256
|
};
|
|
222
|
-
const tab = itemById(dom.getElements(ctx), dom.getTriggerId(ctx, id))
|
|
257
|
+
const tab = (_a = itemById(dom.getElements(ctx), dom.getTriggerId(ctx, id))) != null ? _a : empty;
|
|
223
258
|
if (ctx.isVertical) {
|
|
224
259
|
return {
|
|
225
260
|
top: `${tab.offsetTop}px`,
|
|
@@ -379,7 +414,8 @@ function connect(state, send, normalize) {
|
|
|
379
414
|
// src/tabs.machine.ts
|
|
380
415
|
var import_core = require("@zag-js/core");
|
|
381
416
|
var { not } = import_core.guards;
|
|
382
|
-
function machine(
|
|
417
|
+
function machine(userContext) {
|
|
418
|
+
const ctx = compact(userContext);
|
|
383
419
|
return (0, import_core.createMachine)(
|
|
384
420
|
{
|
|
385
421
|
initial: "unknown",
|
package/dist/index.mjs
CHANGED
|
@@ -4,8 +4,9 @@ var dataAttr = (guard) => {
|
|
|
4
4
|
};
|
|
5
5
|
var isDom = () => typeof window !== "undefined";
|
|
6
6
|
function getPlatform() {
|
|
7
|
+
var _a;
|
|
7
8
|
const agent = navigator.userAgentData;
|
|
8
|
-
return (agent == null ? void 0 : agent.platform)
|
|
9
|
+
return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
|
|
9
10
|
}
|
|
10
11
|
var pt = (v) => isDom() && v.test(getPlatform());
|
|
11
12
|
var vn = (v) => isDom() && v.test(navigator.vendor);
|
|
@@ -21,22 +22,44 @@ function isFrame(element) {
|
|
|
21
22
|
return element.localName === "iframe";
|
|
22
23
|
}
|
|
23
24
|
function getDocument(el) {
|
|
25
|
+
var _a;
|
|
24
26
|
if (isWindow(el))
|
|
25
27
|
return el.document;
|
|
26
28
|
if (isDocument(el))
|
|
27
29
|
return el;
|
|
28
|
-
return (el == null ? void 0 : el.ownerDocument)
|
|
30
|
+
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
29
31
|
}
|
|
30
32
|
function defineDomHelpers(helpers) {
|
|
31
33
|
const dom2 = {
|
|
32
34
|
getRootNode: (ctx) => {
|
|
33
|
-
var _a;
|
|
34
|
-
return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx))
|
|
35
|
+
var _a, _b;
|
|
36
|
+
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
35
37
|
},
|
|
36
38
|
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
37
|
-
getWin: (ctx) =>
|
|
39
|
+
getWin: (ctx) => {
|
|
40
|
+
var _a;
|
|
41
|
+
return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
|
|
42
|
+
},
|
|
38
43
|
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
39
|
-
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
44
|
+
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
|
|
45
|
+
createEmitter: (ctx, target) => {
|
|
46
|
+
const win = dom2.getWin(ctx);
|
|
47
|
+
return function emit(evt, detail, options) {
|
|
48
|
+
const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
|
|
49
|
+
const eventName = `zag:${evt}`;
|
|
50
|
+
const init = { bubbles, cancelable, composed, detail };
|
|
51
|
+
const event = new win.CustomEvent(eventName, init);
|
|
52
|
+
target.dispatchEvent(event);
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
createListener: (target) => {
|
|
56
|
+
return function listen(evt, handler) {
|
|
57
|
+
const eventName = `zag:${evt}`;
|
|
58
|
+
const listener = (e) => handler(e);
|
|
59
|
+
target.addEventListener(eventName, listener);
|
|
60
|
+
return () => target.removeEventListener(eventName, listener);
|
|
61
|
+
};
|
|
62
|
+
}
|
|
40
63
|
};
|
|
41
64
|
return {
|
|
42
65
|
...dom2,
|
|
@@ -88,9 +111,10 @@ var sameKeyMap = {
|
|
|
88
111
|
Right: "ArrowRight"
|
|
89
112
|
};
|
|
90
113
|
function getEventKey(event, options = {}) {
|
|
114
|
+
var _a;
|
|
91
115
|
const { dir = "ltr", orientation = "horizontal" } = options;
|
|
92
116
|
let { key } = event;
|
|
93
|
-
key = sameKeyMap[key]
|
|
117
|
+
key = (_a = sameKeyMap[key]) != null ? _a : key;
|
|
94
118
|
const isRtl = dir === "rtl" && orientation === "horizontal";
|
|
95
119
|
if (isRtl && key in rtlKeyMap) {
|
|
96
120
|
key = rtlKeyMap[key];
|
|
@@ -117,7 +141,8 @@ function raf(fn) {
|
|
|
117
141
|
};
|
|
118
142
|
}
|
|
119
143
|
function queryAll(root, selector) {
|
|
120
|
-
|
|
144
|
+
var _a;
|
|
145
|
+
return Array.from((_a = root == null ? void 0 : root.querySelectorAll(selector)) != null ? _a : []);
|
|
121
146
|
}
|
|
122
147
|
function itemById(v, id) {
|
|
123
148
|
return v.find((node) => node.id === id);
|
|
@@ -142,28 +167,37 @@ function prevById(v, id, loop = true) {
|
|
|
142
167
|
// ../../utilities/core/dist/index.mjs
|
|
143
168
|
var first = (v) => v[0];
|
|
144
169
|
var last = (v) => v[v.length - 1];
|
|
170
|
+
var isArray = (v) => Array.isArray(v);
|
|
171
|
+
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
172
|
+
function compact(obj) {
|
|
173
|
+
if (obj === void 0)
|
|
174
|
+
return obj;
|
|
175
|
+
return Object.fromEntries(
|
|
176
|
+
Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
|
|
177
|
+
);
|
|
178
|
+
}
|
|
145
179
|
|
|
146
180
|
// src/tabs.dom.ts
|
|
147
181
|
var dom = defineDomHelpers({
|
|
148
182
|
getRootId: (ctx) => {
|
|
149
|
-
var _a;
|
|
150
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.root)
|
|
183
|
+
var _a, _b;
|
|
184
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `tabs:${ctx.id}`;
|
|
151
185
|
},
|
|
152
186
|
getTriggerGroupId: (ctx) => {
|
|
153
|
-
var _a;
|
|
154
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.triggerGroup)
|
|
187
|
+
var _a, _b;
|
|
188
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.triggerGroup) != null ? _b : `tabs:${ctx.id}:trigger-group`;
|
|
155
189
|
},
|
|
156
190
|
getContentId: (ctx, id) => {
|
|
157
|
-
var _a;
|
|
158
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.content)
|
|
191
|
+
var _a, _b;
|
|
192
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.content) != null ? _b : `tabs:${ctx.id}:content-${id}`;
|
|
159
193
|
},
|
|
160
194
|
getContentGroupId: (ctx) => {
|
|
161
|
-
var _a;
|
|
162
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.contentGroup)
|
|
195
|
+
var _a, _b;
|
|
196
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.contentGroup) != null ? _b : `tabs:${ctx.id}:content-group`;
|
|
163
197
|
},
|
|
164
198
|
getTriggerId: (ctx, id) => {
|
|
165
|
-
var _a;
|
|
166
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.trigger)
|
|
199
|
+
var _a, _b;
|
|
200
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.trigger) != null ? _b : `tabs:${ctx.id}:trigger-${id}`;
|
|
167
201
|
},
|
|
168
202
|
getIndicatorId: (ctx) => `tabs:${ctx.id}:indicator`,
|
|
169
203
|
getTriggerGroupEl: (ctx) => dom.getById(ctx, dom.getTriggerGroupId(ctx)),
|
|
@@ -186,13 +220,14 @@ var dom = defineDomHelpers({
|
|
|
186
220
|
return dom.getById(ctx, id);
|
|
187
221
|
},
|
|
188
222
|
getRectById: (ctx, id) => {
|
|
223
|
+
var _a;
|
|
189
224
|
const empty = {
|
|
190
225
|
offsetLeft: 0,
|
|
191
226
|
offsetTop: 0,
|
|
192
227
|
offsetWidth: 0,
|
|
193
228
|
offsetHeight: 0
|
|
194
229
|
};
|
|
195
|
-
const tab = itemById(dom.getElements(ctx), dom.getTriggerId(ctx, id))
|
|
230
|
+
const tab = (_a = itemById(dom.getElements(ctx), dom.getTriggerId(ctx, id))) != null ? _a : empty;
|
|
196
231
|
if (ctx.isVertical) {
|
|
197
232
|
return {
|
|
198
233
|
top: `${tab.offsetTop}px`,
|
|
@@ -352,7 +387,8 @@ function connect(state, send, normalize) {
|
|
|
352
387
|
// src/tabs.machine.ts
|
|
353
388
|
import { createMachine, guards } from "@zag-js/core";
|
|
354
389
|
var { not } = guards;
|
|
355
|
-
function machine(
|
|
390
|
+
function machine(userContext) {
|
|
391
|
+
const ctx = compact(userContext);
|
|
356
392
|
return createMachine(
|
|
357
393
|
{
|
|
358
394
|
initial: "unknown",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/tabs",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Core logic for the tabs widget implemented as a state machine",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -29,12 +29,12 @@
|
|
|
29
29
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@zag-js/core": "0.1
|
|
33
|
-
"@zag-js/types": "0.
|
|
32
|
+
"@zag-js/core": "0.2.1",
|
|
33
|
+
"@zag-js/types": "0.3.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@zag-js/dom-utils": "0.
|
|
37
|
-
"@zag-js/utils": "0.
|
|
36
|
+
"@zag-js/dom-utils": "0.2.0",
|
|
37
|
+
"@zag-js/utils": "0.3.0"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build-fast": "tsup src/index.ts --format=esm,cjs",
|