@zag-js/tabs 0.2.11 → 0.2.13

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.
@@ -23,103 +23,8 @@ __export(tabs_connect_exports, {
23
23
  connect: () => connect
24
24
  });
25
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
- const agent = navigator.userAgentData;
40
- return agent?.platform ?? navigator.platform;
41
- }
42
- var pt = (v) => isDom() && v.test(getPlatform());
43
- var vn = (v) => isDom() && v.test(navigator.vendor);
44
- var isSafari = () => isApple() && vn(/apple/i);
45
- var isApple = () => pt(/mac|iphone|ipad|ipod/i);
46
-
47
- // ../../utilities/dom/src/query.ts
48
- function isDocument(el) {
49
- return el.nodeType === Node.DOCUMENT_NODE;
50
- }
51
- function isWindow(value) {
52
- return value?.toString() === "[object Window]";
53
- }
54
- function getDocument(el) {
55
- if (isWindow(el))
56
- return el.document;
57
- if (isDocument(el))
58
- return el;
59
- return el?.ownerDocument ?? document;
60
- }
61
- function defineDomHelpers(helpers) {
62
- const dom2 = {
63
- getRootNode: (ctx) => ctx.getRootNode?.() ?? document,
64
- getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
65
- getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
66
- getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
67
- getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
68
- };
69
- return {
70
- ...dom2,
71
- ...helpers
72
- };
73
- }
74
-
75
- // ../../utilities/dom/src/keyboard-event.ts
76
- var rtlKeyMap = {
77
- ArrowLeft: "ArrowRight",
78
- ArrowRight: "ArrowLeft"
79
- };
80
- var sameKeyMap = {
81
- Up: "ArrowUp",
82
- Down: "ArrowDown",
83
- Esc: "Escape",
84
- " ": "Space",
85
- ",": "Comma",
86
- Left: "ArrowLeft",
87
- Right: "ArrowRight"
88
- };
89
- function getEventKey(event, options = {}) {
90
- const { dir = "ltr", orientation = "horizontal" } = options;
91
- let { key } = event;
92
- key = sameKeyMap[key] ?? key;
93
- const isRtl = dir === "rtl" && orientation === "horizontal";
94
- if (isRtl && key in rtlKeyMap) {
95
- key = rtlKeyMap[key];
96
- }
97
- return key;
98
- }
99
-
100
- // ../../utilities/dom/src/nodelist.ts
101
- function queryAll(root, selector) {
102
- return Array.from(root?.querySelectorAll(selector) ?? []);
103
- }
104
- function itemById(v, id) {
105
- return v.find((node) => node.id === id);
106
- }
107
- function indexOfId(v, id) {
108
- const item = itemById(v, id);
109
- return item ? v.indexOf(item) : -1;
110
- }
111
- function nextById(v, id, loop = true) {
112
- let idx = indexOfId(v, id);
113
- idx = loop ? (idx + 1) % v.length : Math.min(idx + 1, v.length - 1);
114
- return v[idx];
115
- }
116
- function prevById(v, id, loop = true) {
117
- let idx = indexOfId(v, id);
118
- if (idx === -1)
119
- return loop ? v[v.length - 1] : null;
120
- idx = loop ? (idx - 1 + v.length) % v.length : Math.max(0, idx - 1);
121
- return v[idx];
122
- }
26
+ var import_dom_event = require("@zag-js/dom-event");
27
+ var import_dom_query2 = require("@zag-js/dom-query");
123
28
 
124
29
  // src/tabs.anatomy.ts
125
30
  var import_anatomy = require("@zag-js/anatomy");
@@ -127,7 +32,9 @@ var anatomy = (0, import_anatomy.createAnatomy)("tabs").parts("root", "tablist",
127
32
  var parts = anatomy.build();
128
33
 
129
34
  // src/tabs.dom.ts
130
- var dom = defineDomHelpers({
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)({
131
38
  getRootId: (ctx) => ctx.ids?.root ?? `tabs:${ctx.id}`,
132
39
  getTablistId: (ctx) => ctx.ids?.tablist ?? `tabs:${ctx.id}:list`,
133
40
  getContentId: (ctx, id) => ctx.ids?.content ?? `tabs:${ctx.id}:content-${id}`,
@@ -141,12 +48,12 @@ var dom = defineDomHelpers({
141
48
  getElements: (ctx) => {
142
49
  const ownerId = CSS.escape(dom.getTablistId(ctx));
143
50
  const selector = `[role=tab][data-ownedby='${ownerId}']:not([disabled])`;
144
- return queryAll(dom.getTablistEl(ctx), selector);
51
+ return (0, import_dom_query.queryAll)(dom.getTablistEl(ctx), selector);
145
52
  },
146
- getFirstEl: (ctx) => first(dom.getElements(ctx)),
147
- getLastEl: (ctx) => last(dom.getElements(ctx)),
148
- getNextEl: (ctx, id) => nextById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
149
- getPrevEl: (ctx, id) => prevById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
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),
150
57
  getActiveContentEl: (ctx) => {
151
58
  if (!ctx.value)
152
59
  return;
@@ -160,7 +67,7 @@ var dom = defineDomHelpers({
160
67
  offsetWidth: 0,
161
68
  offsetHeight: 0
162
69
  };
163
- const tab = itemById(dom.getElements(ctx), dom.getTriggerId(ctx, id)) ?? empty;
70
+ const tab = (0, import_dom_query.itemById)(dom.getElements(ctx), dom.getTriggerId(ctx, id)) ?? empty;
164
71
  if (ctx.isVertical) {
165
72
  return {
166
73
  top: `${tab.offsetTop}px`,
@@ -179,12 +86,27 @@ function connect(state, send, normalize) {
179
86
  const translations = state.context.translations;
180
87
  const isFocused = state.matches("focused");
181
88
  return {
89
+ /**
90
+ * The current value of the tabs.
91
+ */
182
92
  value: state.context.value,
93
+ /**
94
+ * The value of the tab that is currently focused.
95
+ */
183
96
  focusedValue: state.context.focusedValue,
97
+ /**
98
+ * The previous values of the tabs in sequence of selection.
99
+ */
184
100
  previousValues: Array.from(state.context.previousValues),
101
+ /**
102
+ * Sets the value of the tabs.
103
+ */
185
104
  setValue(value) {
186
105
  send({ type: "SET_VALUE", value });
187
106
  },
107
+ /**
108
+ * Clears the value of the tabs.
109
+ */
188
110
  clearValue() {
189
111
  send({ type: "CLEAR_VALUE" });
190
112
  },
@@ -192,14 +114,14 @@ function connect(state, send, normalize) {
192
114
  ...parts.root.attrs,
193
115
  id: dom.getRootId(state.context),
194
116
  "data-orientation": state.context.orientation,
195
- "data-focus": dataAttr(isFocused),
117
+ "data-focus": (0, import_dom_query2.dataAttr)(isFocused),
196
118
  dir: state.context.dir
197
119
  }),
198
120
  tablistProps: normalize.element({
199
121
  ...parts.tablist.attrs,
200
122
  id: dom.getTablistId(state.context),
201
123
  role: "tablist",
202
- "data-focus": dataAttr(isFocused),
124
+ "data-focus": (0, import_dom_query2.dataAttr)(isFocused),
203
125
  "aria-orientation": state.context.orientation,
204
126
  "data-orientation": state.context.orientation,
205
127
  "aria-label": translations.tablistLabel,
@@ -227,7 +149,7 @@ function connect(state, send, normalize) {
227
149
  send({ type: "ENTER", value: state.context.focusedValue });
228
150
  }
229
151
  };
230
- let key = getEventKey(event, state.context);
152
+ let key = (0, import_dom_event.getEventKey)(event, state.context);
231
153
  const exec = keyMap[key];
232
154
  if (exec) {
233
155
  event.preventDefault();
@@ -244,11 +166,11 @@ function connect(state, send, normalize) {
244
166
  type: "button",
245
167
  disabled,
246
168
  "data-orientation": state.context.orientation,
247
- "data-disabled": dataAttr(disabled),
169
+ "data-disabled": (0, import_dom_query2.dataAttr)(disabled),
248
170
  "aria-disabled": disabled,
249
171
  "data-value": value,
250
172
  "aria-selected": selected,
251
- "data-selected": dataAttr(selected),
173
+ "data-selected": (0, import_dom_query2.dataAttr)(selected),
252
174
  "aria-controls": dom.getContentId(state.context, value),
253
175
  "data-ownedby": dom.getTablistId(state.context),
254
176
  id: dom.getTriggerId(state.context, value),
@@ -265,7 +187,7 @@ function connect(state, send, normalize) {
265
187
  onClick(event) {
266
188
  if (disabled)
267
189
  return;
268
- if (isSafari()) {
190
+ if ((0, import_dom_query2.isSafari)()) {
269
191
  event.currentTarget.focus();
270
192
  }
271
193
  send({ type: "TAB_CLICK", value });
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  connect
3
- } from "./chunk-IVTIBLCN.mjs";
3
+ } from "./chunk-5JW3YJ3I.mjs";
4
4
  import "./chunk-S2KW2DT4.mjs";
5
- import "./chunk-4CROPD6E.mjs";
5
+ import "./chunk-5ZMNIWHF.mjs";
6
6
  export {
7
7
  connect
8
8
  };
@@ -4,20 +4,23 @@ import '@zag-js/types';
4
4
 
5
5
  declare const dom: {
6
6
  getRootNode: (ctx: {
7
- getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
7
+ getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
8
8
  }) => Document | ShadowRoot;
9
9
  getDoc: (ctx: {
10
- getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
10
+ getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
11
11
  }) => Document;
12
12
  getWin: (ctx: {
13
- getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
13
+ getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
14
14
  }) => Window & typeof globalThis;
15
15
  getActiveElement: (ctx: {
16
- getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
16
+ getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
17
17
  }) => HTMLElement | null;
18
- getById: <T = HTMLElement>(ctx: {
19
- getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
18
+ getById: <T extends HTMLElement = HTMLElement>(ctx: {
19
+ getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
20
20
  }, id: string) => T | null;
21
+ queryById: <T_1 extends HTMLElement = HTMLElement>(ctx: {
22
+ getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
23
+ }, id: string) => T_1;
21
24
  } & {
22
25
  getRootId: (ctx: MachineContext) => string;
23
26
  getTablistId: (ctx: MachineContext) => string;
package/dist/tabs.dom.js CHANGED
@@ -23,65 +23,9 @@ __export(tabs_dom_exports, {
23
23
  dom: () => dom
24
24
  });
25
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?.toString() === "[object Window]";
37
- }
38
- function getDocument(el) {
39
- if (isWindow(el))
40
- return el.document;
41
- if (isDocument(el))
42
- return el;
43
- return el?.ownerDocument ?? document;
44
- }
45
- function defineDomHelpers(helpers) {
46
- const dom2 = {
47
- getRootNode: (ctx) => ctx.getRootNode?.() ?? document,
48
- getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
49
- getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
50
- getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
51
- getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
52
- };
53
- return {
54
- ...dom2,
55
- ...helpers
56
- };
57
- }
58
-
59
- // ../../utilities/dom/src/nodelist.ts
60
- function queryAll(root, selector) {
61
- return Array.from(root?.querySelectorAll(selector) ?? []);
62
- }
63
- function itemById(v, id) {
64
- return v.find((node) => node.id === id);
65
- }
66
- function indexOfId(v, id) {
67
- const item = itemById(v, id);
68
- return item ? v.indexOf(item) : -1;
69
- }
70
- function nextById(v, id, loop = true) {
71
- let idx = indexOfId(v, id);
72
- idx = loop ? (idx + 1) % v.length : Math.min(idx + 1, v.length - 1);
73
- return v[idx];
74
- }
75
- function prevById(v, id, loop = true) {
76
- let idx = indexOfId(v, id);
77
- if (idx === -1)
78
- return loop ? v[v.length - 1] : null;
79
- idx = loop ? (idx - 1 + v.length) % v.length : Math.max(0, idx - 1);
80
- return v[idx];
81
- }
82
-
83
- // src/tabs.dom.ts
84
- var dom = defineDomHelpers({
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)({
85
29
  getRootId: (ctx) => ctx.ids?.root ?? `tabs:${ctx.id}`,
86
30
  getTablistId: (ctx) => ctx.ids?.tablist ?? `tabs:${ctx.id}:list`,
87
31
  getContentId: (ctx, id) => ctx.ids?.content ?? `tabs:${ctx.id}:content-${id}`,
@@ -95,12 +39,12 @@ var dom = defineDomHelpers({
95
39
  getElements: (ctx) => {
96
40
  const ownerId = CSS.escape(dom.getTablistId(ctx));
97
41
  const selector = `[role=tab][data-ownedby='${ownerId}']:not([disabled])`;
98
- return queryAll(dom.getTablistEl(ctx), selector);
42
+ return (0, import_dom_query.queryAll)(dom.getTablistEl(ctx), selector);
99
43
  },
100
- getFirstEl: (ctx) => first(dom.getElements(ctx)),
101
- getLastEl: (ctx) => last(dom.getElements(ctx)),
102
- getNextEl: (ctx, id) => nextById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
103
- getPrevEl: (ctx, id) => prevById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
44
+ getFirstEl: (ctx) => (0, import_utils.first)(dom.getElements(ctx)),
45
+ getLastEl: (ctx) => (0, import_utils.last)(dom.getElements(ctx)),
46
+ getNextEl: (ctx, id) => (0, import_dom_query.nextById)(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
47
+ getPrevEl: (ctx, id) => (0, import_dom_query.prevById)(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
104
48
  getActiveContentEl: (ctx) => {
105
49
  if (!ctx.value)
106
50
  return;
@@ -114,7 +58,7 @@ var dom = defineDomHelpers({
114
58
  offsetWidth: 0,
115
59
  offsetHeight: 0
116
60
  };
117
- const tab = itemById(dom.getElements(ctx), dom.getTriggerId(ctx, id)) ?? empty;
61
+ const tab = (0, import_dom_query.itemById)(dom.getElements(ctx), dom.getTriggerId(ctx, id)) ?? empty;
118
62
  if (ctx.isVertical) {
119
63
  return {
120
64
  top: `${tab.offsetTop}px`,
package/dist/tabs.dom.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  dom
3
- } from "./chunk-4CROPD6E.mjs";
3
+ } from "./chunk-5ZMNIWHF.mjs";
4
4
  export {
5
5
  dom
6
6
  };
@@ -24,135 +24,14 @@ __export(tabs_machine_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(tabs_machine_exports);
26
26
  var import_core = require("@zag-js/core");
27
-
28
- // ../../utilities/core/src/array.ts
29
- var first = (v) => v[0];
30
- var last = (v) => v[v.length - 1];
31
-
32
- // ../../utilities/core/src/guard.ts
33
- var isArray = (v) => Array.isArray(v);
34
- var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
35
-
36
- // ../../utilities/core/src/object.ts
37
- function compact(obj) {
38
- if (obj === void 0)
39
- return obj;
40
- return Object.fromEntries(
41
- Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
42
- );
43
- }
44
-
45
- // ../../utilities/dom/src/query.ts
46
- function isDocument(el) {
47
- return el.nodeType === Node.DOCUMENT_NODE;
48
- }
49
- function isWindow(value) {
50
- return value?.toString() === "[object Window]";
51
- }
52
- function isFrame(element) {
53
- return element.localName === "iframe";
54
- }
55
- function getDocument(el) {
56
- if (isWindow(el))
57
- return el.document;
58
- if (isDocument(el))
59
- return el;
60
- return el?.ownerDocument ?? document;
61
- }
62
- function defineDomHelpers(helpers) {
63
- const dom2 = {
64
- getRootNode: (ctx) => ctx.getRootNode?.() ?? document,
65
- getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
66
- getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
67
- getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
68
- getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
69
- };
70
- return {
71
- ...dom2,
72
- ...helpers
73
- };
74
- }
75
- function isHTMLElement(v) {
76
- return typeof v === "object" && v?.nodeType === Node.ELEMENT_NODE && typeof v?.nodeName === "string";
77
- }
78
- function isVisible(el) {
79
- if (!isHTMLElement(el))
80
- return false;
81
- return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
82
- }
83
-
84
- // ../../utilities/dom/src/focusable.ts
85
- 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";
86
- var getFocusables = (container, includeContainer = false) => {
87
- if (!container)
88
- return [];
89
- const elements = Array.from(container.querySelectorAll(focusableSelector));
90
- const include = includeContainer == true || includeContainer == "if-empty" && elements.length === 0;
91
- if (include && isHTMLElement(container) && isFocusable(container)) {
92
- elements.unshift(container);
93
- }
94
- const focusableElements = elements.filter(isFocusable);
95
- focusableElements.forEach((element, i) => {
96
- if (isFrame(element) && element.contentDocument) {
97
- const frameBody = element.contentDocument.body;
98
- focusableElements.splice(i, 1, ...getFocusables(frameBody));
99
- }
100
- });
101
- return focusableElements;
102
- };
103
- function isFocusable(element) {
104
- if (!element)
105
- return false;
106
- return element.matches(focusableSelector) && isVisible(element);
107
- }
108
-
109
- // ../../utilities/dom/src/next-tick.ts
110
- function nextTick(fn) {
111
- const set = /* @__PURE__ */ new Set();
112
- function raf2(fn2) {
113
- const id = globalThis.requestAnimationFrame(fn2);
114
- set.add(() => globalThis.cancelAnimationFrame(id));
115
- }
116
- raf2(() => raf2(fn));
117
- return function cleanup() {
118
- set.forEach(function(fn2) {
119
- fn2();
120
- });
121
- };
122
- }
123
- function raf(fn) {
124
- const id = globalThis.requestAnimationFrame(fn);
125
- return function cleanup() {
126
- globalThis.cancelAnimationFrame(id);
127
- };
128
- }
129
-
130
- // ../../utilities/dom/src/nodelist.ts
131
- function queryAll(root, selector) {
132
- return Array.from(root?.querySelectorAll(selector) ?? []);
133
- }
134
- function itemById(v, id) {
135
- return v.find((node) => node.id === id);
136
- }
137
- function indexOfId(v, id) {
138
- const item = itemById(v, id);
139
- return item ? v.indexOf(item) : -1;
140
- }
141
- function nextById(v, id, loop = true) {
142
- let idx = indexOfId(v, id);
143
- idx = loop ? (idx + 1) % v.length : Math.min(idx + 1, v.length - 1);
144
- return v[idx];
145
- }
146
- function prevById(v, id, loop = true) {
147
- let idx = indexOfId(v, id);
148
- if (idx === -1)
149
- return loop ? v[v.length - 1] : null;
150
- idx = loop ? (idx - 1 + v.length) % v.length : Math.max(0, idx - 1);
151
- return v[idx];
152
- }
27
+ var import_dom_query2 = require("@zag-js/dom-query");
28
+ var import_tabbable = require("@zag-js/tabbable");
29
+ var import_utils2 = require("@zag-js/utils");
153
30
 
154
31
  // src/tabs.dom.ts
155
- var dom = defineDomHelpers({
32
+ var import_dom_query = require("@zag-js/dom-query");
33
+ var import_utils = require("@zag-js/utils");
34
+ var dom = (0, import_dom_query.createScope)({
156
35
  getRootId: (ctx) => ctx.ids?.root ?? `tabs:${ctx.id}`,
157
36
  getTablistId: (ctx) => ctx.ids?.tablist ?? `tabs:${ctx.id}:list`,
158
37
  getContentId: (ctx, id) => ctx.ids?.content ?? `tabs:${ctx.id}:content-${id}`,
@@ -166,12 +45,12 @@ var dom = defineDomHelpers({
166
45
  getElements: (ctx) => {
167
46
  const ownerId = CSS.escape(dom.getTablistId(ctx));
168
47
  const selector = `[role=tab][data-ownedby='${ownerId}']:not([disabled])`;
169
- return queryAll(dom.getTablistEl(ctx), selector);
48
+ return (0, import_dom_query.queryAll)(dom.getTablistEl(ctx), selector);
170
49
  },
171
- getFirstEl: (ctx) => first(dom.getElements(ctx)),
172
- getLastEl: (ctx) => last(dom.getElements(ctx)),
173
- getNextEl: (ctx, id) => nextById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
174
- getPrevEl: (ctx, id) => prevById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
50
+ getFirstEl: (ctx) => (0, import_utils.first)(dom.getElements(ctx)),
51
+ getLastEl: (ctx) => (0, import_utils.last)(dom.getElements(ctx)),
52
+ getNextEl: (ctx, id) => (0, import_dom_query.nextById)(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
53
+ getPrevEl: (ctx, id) => (0, import_dom_query.prevById)(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
175
54
  getActiveContentEl: (ctx) => {
176
55
  if (!ctx.value)
177
56
  return;
@@ -185,7 +64,7 @@ var dom = defineDomHelpers({
185
64
  offsetWidth: 0,
186
65
  offsetHeight: 0
187
66
  };
188
- const tab = itemById(dom.getElements(ctx), dom.getTriggerId(ctx, id)) ?? empty;
67
+ const tab = (0, import_dom_query.itemById)(dom.getElements(ctx), dom.getTriggerId(ctx, id)) ?? empty;
189
68
  if (ctx.isVertical) {
190
69
  return {
191
70
  top: `${tab.offsetTop}px`,
@@ -202,7 +81,7 @@ var dom = defineDomHelpers({
202
81
  // src/tabs.machine.ts
203
82
  var { not } = import_core.guards;
204
83
  function machine(userContext) {
205
- const ctx = compact(userContext);
84
+ const ctx = (0, import_utils2.compact)(userContext);
206
85
  return (0, import_core.createMachine)(
207
86
  {
208
87
  initial: "idle",
@@ -323,31 +202,31 @@ function machine(userContext) {
323
202
  ctx2.onDelete?.({ value: evt.value });
324
203
  },
325
204
  focusFirstTab(ctx2) {
326
- raf(() => dom.getFirstEl(ctx2)?.focus());
205
+ (0, import_dom_query2.raf)(() => dom.getFirstEl(ctx2)?.focus());
327
206
  },
328
207
  focusLastTab(ctx2) {
329
- raf(() => dom.getLastEl(ctx2)?.focus());
208
+ (0, import_dom_query2.raf)(() => dom.getLastEl(ctx2)?.focus());
330
209
  },
331
210
  focusNextTab(ctx2) {
332
211
  if (!ctx2.focusedValue)
333
212
  return;
334
213
  const next = dom.getNextEl(ctx2, ctx2.focusedValue);
335
- raf(() => next?.focus());
214
+ (0, import_dom_query2.raf)(() => next?.focus());
336
215
  },
337
216
  focusPrevTab(ctx2) {
338
217
  if (!ctx2.focusedValue)
339
218
  return;
340
219
  const prev = dom.getPrevEl(ctx2, ctx2.focusedValue);
341
- raf(() => prev?.focus());
220
+ (0, import_dom_query2.raf)(() => prev?.focus());
342
221
  },
343
222
  setIndicatorRect(ctx2) {
344
- nextTick(() => {
223
+ (0, import_dom_query2.nextTick)(() => {
345
224
  if (!ctx2.isIndicatorRendered || !ctx2.value)
346
225
  return;
347
226
  ctx2.indicatorRect = dom.getRectById(ctx2, ctx2.value);
348
227
  if (ctx2.hasMeasuredRect)
349
228
  return;
350
- nextTick(() => {
229
+ (0, import_dom_query2.nextTick)(() => {
351
230
  ctx2.hasMeasuredRect = true;
352
231
  });
353
232
  });
@@ -369,12 +248,13 @@ function machine(userContext) {
369
248
  ctx2.previousValues = pushUnique(Array.from(ctx2.previousValues), ctx2.value);
370
249
  }
371
250
  },
251
+ // if tab panel contains focusable elements, remove the tabindex attribute
372
252
  setContentTabIndex(ctx2) {
373
- raf(() => {
253
+ (0, import_dom_query2.raf)(() => {
374
254
  const panel = dom.getActiveContentEl(ctx2);
375
255
  if (!panel)
376
256
  return;
377
- const focusables = getFocusables(panel);
257
+ const focusables = (0, import_tabbable.getFocusables)(panel);
378
258
  if (focusables.length > 0) {
379
259
  panel.removeAttribute("tabindex");
380
260
  } else {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  machine
3
- } from "./chunk-3DBUWLYX.mjs";
4
- import "./chunk-4CROPD6E.mjs";
3
+ } from "./chunk-JG2VX4ST.mjs";
4
+ import "./chunk-5ZMNIWHF.mjs";
5
5
  export {
6
6
  machine
7
7
  };
@@ -25,10 +25,6 @@ type PublicContext = DirectionProperty & CommonProperties & {
25
25
  * @default true
26
26
  */
27
27
  loop: boolean;
28
- /**
29
- * Whether the indicator is rendered.
30
- */
31
- isIndicatorRendered: boolean;
32
28
  /**
33
29
  * The selected tab id
34
30
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/tabs",
3
- "version": "0.2.11",
3
+ "version": "0.2.13",
4
4
  "description": "Core logic for the tabs widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -27,13 +27,15 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@zag-js/anatomy": "0.1.4",
30
- "@zag-js/core": "0.2.9",
30
+ "@zag-js/dom-query": "0.1.4",
31
+ "@zag-js/dom-event": "0.0.1",
32
+ "@zag-js/tabbable": "0.0.1",
33
+ "@zag-js/utils": "0.3.3",
34
+ "@zag-js/core": "0.2.10",
31
35
  "@zag-js/types": "0.3.4"
32
36
  },
33
37
  "devDependencies": {
34
- "clean-package": "2.2.0",
35
- "@zag-js/dom-utils": "0.2.4",
36
- "@zag-js/utils": "0.3.3"
38
+ "clean-package": "2.2.0"
37
39
  },
38
40
  "clean-package": "../../../clean-package.config.json",
39
41
  "main": "dist/index.js",