@zag-js/tabs 0.1.8 → 0.1.9

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.js CHANGED
@@ -43,94 +43,50 @@ module.exports = __toCommonJS(src_exports);
43
43
  var dataAttr = (guard) => {
44
44
  return guard ? "" : void 0;
45
45
  };
46
- function nextTick(fn) {
47
- const set = /* @__PURE__ */ new Set();
48
- function raf2(fn2) {
49
- const id = globalThis.requestAnimationFrame(fn2);
50
- set.add(() => globalThis.cancelAnimationFrame(id));
51
- }
52
- raf2(() => raf2(fn));
53
- return function cleanup() {
54
- set.forEach(function(fn2) {
55
- fn2();
56
- });
57
- };
58
- }
59
- function raf(fn) {
60
- const id = globalThis.requestAnimationFrame(fn);
61
- return function cleanup() {
62
- globalThis.cancelAnimationFrame(id);
63
- };
64
- }
65
- function getStyleCache() {
66
- ;
67
- globalThis.__styleCache__ = globalThis.__styleCache__ || /* @__PURE__ */ new WeakMap();
68
- return globalThis.__styleCache__;
69
- }
70
- function getComputedStyle(el) {
46
+ var isDom = () => typeof window !== "undefined";
47
+ function getPlatform() {
71
48
  var _a;
72
- if (!el)
73
- return {};
74
- const cache = getStyleCache();
75
- let style = cache.get(el);
76
- if (!style) {
77
- const win = (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
78
- style = win.getComputedStyle(el);
79
- cache.set(el, style);
80
- }
81
- return style;
49
+ const agent = navigator.userAgentData;
50
+ return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
51
+ }
52
+ var pt = (v) => isDom() && v.test(getPlatform());
53
+ var vn = (v) => isDom() && v.test(navigator.vendor);
54
+ var isSafari = () => isApple() && vn(/apple/i);
55
+ var isApple = () => pt(/mac|iphone|ipad|ipod/i);
56
+ function isFrame(element) {
57
+ return element.localName === "iframe";
82
58
  }
83
59
  function isHTMLElement(v) {
84
60
  return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
85
61
  }
86
- var isDisabled = (el) => {
87
- return (el == null ? void 0 : el.getAttribute("disabled")) != null || !!(el == null ? void 0 : el.getAttribute("aria-disabled")) === true;
88
- };
89
- var focusableSelector = /* @__PURE__ */ [
90
- "input:not([disabled]):not([type=hidden])",
91
- "select:not([disabled])",
92
- "textarea:not([disabled])",
93
- "button:not([disabled])",
94
- "embed",
95
- "iframe",
96
- "object",
97
- "a[href]",
98
- "area[href]",
99
- "[tabindex]",
100
- "audio[controls]",
101
- "video[controls]",
102
- "*[tabindex]:not([aria-disabled])",
103
- "[contenteditable]:not([contenteditable=false])",
104
- "details > summary:first-of-type"
105
- ].join(",");
106
- function isHidden(el, until) {
107
- const style = getComputedStyle(el);
108
- if (!el || style.getPropertyValue("visibility") === "hidden")
109
- return true;
110
- while (el) {
111
- if (until != null && el === until)
112
- return false;
113
- if (style.getPropertyValue("display") === "none")
114
- return true;
115
- el = el.parentElement;
116
- }
117
- return false;
62
+ function isVisible(el) {
63
+ if (!isHTMLElement(el))
64
+ return false;
65
+ return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
118
66
  }
119
- var getFocusables = (el, includeContainer = false) => {
120
- if (!el)
67
+ 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";
68
+ var getFocusables = (container, includeContainer = false) => {
69
+ if (!container)
121
70
  return [];
122
- let els = Array.from(el.querySelectorAll(focusableSelector));
123
- const shouldAddContainer = includeContainer == true || includeContainer == "if-empty" && els.length === 0;
124
- if (shouldAddContainer && isHTMLElement(el)) {
125
- els.unshift(el);
71
+ const elements = Array.from(container.querySelectorAll(focusableSelector));
72
+ const include = includeContainer == true || includeContainer == "if-empty" && elements.length === 0;
73
+ if (include && isHTMLElement(container) && isFocusable(container)) {
74
+ elements.unshift(container);
126
75
  }
127
- return els.filter((el2) => isFocusable(el2) && !isHidden(el2));
76
+ const focusableElements = elements.filter(isFocusable);
77
+ focusableElements.forEach((element, i) => {
78
+ if (isFrame(element) && element.contentDocument) {
79
+ const frameBody = element.contentDocument.body;
80
+ focusableElements.splice(i, 1, ...getFocusables(frameBody));
81
+ }
82
+ });
83
+ return focusableElements;
128
84
  };
129
- var isFocusable = (el) => {
130
- if (!isHTMLElement(el) || isHidden(el) || isDisabled(el))
85
+ function isFocusable(element) {
86
+ if (!element)
131
87
  return false;
132
- return el == null ? void 0 : el.matches(focusableSelector);
133
- };
88
+ return element.matches(focusableSelector) && isVisible(element);
89
+ }
134
90
  var rtlKeyMap = {
135
91
  ArrowLeft: "ArrowRight",
136
92
  ArrowRight: "ArrowLeft",
@@ -157,6 +113,25 @@ function getEventKey(event, options = {}) {
157
113
  }
158
114
  return key;
159
115
  }
116
+ function nextTick(fn) {
117
+ const set = /* @__PURE__ */ new Set();
118
+ function raf2(fn2) {
119
+ const id = globalThis.requestAnimationFrame(fn2);
120
+ set.add(() => globalThis.cancelAnimationFrame(id));
121
+ }
122
+ raf2(() => raf2(fn));
123
+ return function cleanup() {
124
+ set.forEach(function(fn2) {
125
+ fn2();
126
+ });
127
+ };
128
+ }
129
+ function raf(fn) {
130
+ const id = globalThis.requestAnimationFrame(fn);
131
+ return function cleanup() {
132
+ globalThis.cancelAnimationFrame(id);
133
+ };
134
+ }
160
135
  function queryAll(root, selector) {
161
136
  var _a;
162
137
  return Array.from((_a = root == null ? void 0 : root.querySelectorAll(selector)) != null ? _a : []);
@@ -181,29 +156,9 @@ function prevById(v, id, loop = true) {
181
156
  return v[idx];
182
157
  }
183
158
 
184
- // ../../types/dist/index.mjs
185
- function createNormalizer(fn) {
186
- return new Proxy({}, {
187
- get() {
188
- return fn;
189
- }
190
- });
191
- }
192
- var normalizeProp = createNormalizer((v) => v);
193
-
194
159
  // ../../utilities/core/dist/index.mjs
195
160
  var first = (v) => v[0];
196
161
  var last = (v) => v[v.length - 1];
197
- var isDom = () => typeof window !== "undefined";
198
- function getPlatform() {
199
- var _a;
200
- const agent = navigator.userAgentData;
201
- return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
202
- }
203
- var pt = (v) => isDom() && v.test(getPlatform());
204
- var vn = (v) => isDom() && v.test(navigator.vendor);
205
- var isSafari = () => isApple() && vn(/apple/i);
206
- var isApple = () => pt(/mac|iphone|ipad|ipod/i);
207
162
 
208
163
  // src/tabs.dom.ts
209
164
  var dom = {
@@ -278,7 +233,7 @@ var dom = {
278
233
  };
279
234
 
280
235
  // src/tabs.connect.ts
281
- function connect(state, send, normalize = normalizeProp) {
236
+ function connect(state, send, normalize) {
282
237
  const messages = state.context.messages;
283
238
  const isFocused = state.matches("focused");
284
239
  return {
package/dist/index.mjs CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __defProp = Object.defineProperty;
3
2
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
4
3
  var __hasOwnProp = Object.prototype.hasOwnProperty;
@@ -20,94 +19,50 @@ var __spreadValues = (a, b) => {
20
19
  var dataAttr = (guard) => {
21
20
  return guard ? "" : void 0;
22
21
  };
23
- function nextTick(fn) {
24
- const set = /* @__PURE__ */ new Set();
25
- function raf2(fn2) {
26
- const id = globalThis.requestAnimationFrame(fn2);
27
- set.add(() => globalThis.cancelAnimationFrame(id));
28
- }
29
- raf2(() => raf2(fn));
30
- return function cleanup() {
31
- set.forEach(function(fn2) {
32
- fn2();
33
- });
34
- };
35
- }
36
- function raf(fn) {
37
- const id = globalThis.requestAnimationFrame(fn);
38
- return function cleanup() {
39
- globalThis.cancelAnimationFrame(id);
40
- };
41
- }
42
- function getStyleCache() {
43
- ;
44
- globalThis.__styleCache__ = globalThis.__styleCache__ || /* @__PURE__ */ new WeakMap();
45
- return globalThis.__styleCache__;
46
- }
47
- function getComputedStyle(el) {
22
+ var isDom = () => typeof window !== "undefined";
23
+ function getPlatform() {
48
24
  var _a;
49
- if (!el)
50
- return {};
51
- const cache = getStyleCache();
52
- let style = cache.get(el);
53
- if (!style) {
54
- const win = (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
55
- style = win.getComputedStyle(el);
56
- cache.set(el, style);
57
- }
58
- return style;
25
+ const agent = navigator.userAgentData;
26
+ return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
27
+ }
28
+ var pt = (v) => isDom() && v.test(getPlatform());
29
+ var vn = (v) => isDom() && v.test(navigator.vendor);
30
+ var isSafari = () => isApple() && vn(/apple/i);
31
+ var isApple = () => pt(/mac|iphone|ipad|ipod/i);
32
+ function isFrame(element) {
33
+ return element.localName === "iframe";
59
34
  }
60
35
  function isHTMLElement(v) {
61
36
  return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
62
37
  }
63
- var isDisabled = (el) => {
64
- return (el == null ? void 0 : el.getAttribute("disabled")) != null || !!(el == null ? void 0 : el.getAttribute("aria-disabled")) === true;
65
- };
66
- var focusableSelector = /* @__PURE__ */ [
67
- "input:not([disabled]):not([type=hidden])",
68
- "select:not([disabled])",
69
- "textarea:not([disabled])",
70
- "button:not([disabled])",
71
- "embed",
72
- "iframe",
73
- "object",
74
- "a[href]",
75
- "area[href]",
76
- "[tabindex]",
77
- "audio[controls]",
78
- "video[controls]",
79
- "*[tabindex]:not([aria-disabled])",
80
- "[contenteditable]:not([contenteditable=false])",
81
- "details > summary:first-of-type"
82
- ].join(",");
83
- function isHidden(el, until) {
84
- const style = getComputedStyle(el);
85
- if (!el || style.getPropertyValue("visibility") === "hidden")
86
- return true;
87
- while (el) {
88
- if (until != null && el === until)
89
- return false;
90
- if (style.getPropertyValue("display") === "none")
91
- return true;
92
- el = el.parentElement;
93
- }
94
- return false;
38
+ function isVisible(el) {
39
+ if (!isHTMLElement(el))
40
+ return false;
41
+ return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
95
42
  }
96
- var getFocusables = (el, includeContainer = false) => {
97
- if (!el)
43
+ 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";
44
+ var getFocusables = (container, includeContainer = false) => {
45
+ if (!container)
98
46
  return [];
99
- let els = Array.from(el.querySelectorAll(focusableSelector));
100
- const shouldAddContainer = includeContainer == true || includeContainer == "if-empty" && els.length === 0;
101
- if (shouldAddContainer && isHTMLElement(el)) {
102
- els.unshift(el);
47
+ const elements = Array.from(container.querySelectorAll(focusableSelector));
48
+ const include = includeContainer == true || includeContainer == "if-empty" && elements.length === 0;
49
+ if (include && isHTMLElement(container) && isFocusable(container)) {
50
+ elements.unshift(container);
103
51
  }
104
- return els.filter((el2) => isFocusable(el2) && !isHidden(el2));
52
+ const focusableElements = elements.filter(isFocusable);
53
+ focusableElements.forEach((element, i) => {
54
+ if (isFrame(element) && element.contentDocument) {
55
+ const frameBody = element.contentDocument.body;
56
+ focusableElements.splice(i, 1, ...getFocusables(frameBody));
57
+ }
58
+ });
59
+ return focusableElements;
105
60
  };
106
- var isFocusable = (el) => {
107
- if (!isHTMLElement(el) || isHidden(el) || isDisabled(el))
61
+ function isFocusable(element) {
62
+ if (!element)
108
63
  return false;
109
- return el == null ? void 0 : el.matches(focusableSelector);
110
- };
64
+ return element.matches(focusableSelector) && isVisible(element);
65
+ }
111
66
  var rtlKeyMap = {
112
67
  ArrowLeft: "ArrowRight",
113
68
  ArrowRight: "ArrowLeft",
@@ -134,6 +89,25 @@ function getEventKey(event, options = {}) {
134
89
  }
135
90
  return key;
136
91
  }
92
+ function nextTick(fn) {
93
+ const set = /* @__PURE__ */ new Set();
94
+ function raf2(fn2) {
95
+ const id = globalThis.requestAnimationFrame(fn2);
96
+ set.add(() => globalThis.cancelAnimationFrame(id));
97
+ }
98
+ raf2(() => raf2(fn));
99
+ return function cleanup() {
100
+ set.forEach(function(fn2) {
101
+ fn2();
102
+ });
103
+ };
104
+ }
105
+ function raf(fn) {
106
+ const id = globalThis.requestAnimationFrame(fn);
107
+ return function cleanup() {
108
+ globalThis.cancelAnimationFrame(id);
109
+ };
110
+ }
137
111
  function queryAll(root, selector) {
138
112
  var _a;
139
113
  return Array.from((_a = root == null ? void 0 : root.querySelectorAll(selector)) != null ? _a : []);
@@ -158,29 +132,9 @@ function prevById(v, id, loop = true) {
158
132
  return v[idx];
159
133
  }
160
134
 
161
- // ../../types/dist/index.mjs
162
- function createNormalizer(fn) {
163
- return new Proxy({}, {
164
- get() {
165
- return fn;
166
- }
167
- });
168
- }
169
- var normalizeProp = createNormalizer((v) => v);
170
-
171
135
  // ../../utilities/core/dist/index.mjs
172
136
  var first = (v) => v[0];
173
137
  var last = (v) => v[v.length - 1];
174
- var isDom = () => typeof window !== "undefined";
175
- function getPlatform() {
176
- var _a;
177
- const agent = navigator.userAgentData;
178
- return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
179
- }
180
- var pt = (v) => isDom() && v.test(getPlatform());
181
- var vn = (v) => isDom() && v.test(navigator.vendor);
182
- var isSafari = () => isApple() && vn(/apple/i);
183
- var isApple = () => pt(/mac|iphone|ipad|ipod/i);
184
138
 
185
139
  // src/tabs.dom.ts
186
140
  var dom = {
@@ -255,7 +209,7 @@ var dom = {
255
209
  };
256
210
 
257
211
  // src/tabs.connect.ts
258
- function connect(state, send, normalize = normalizeProp) {
212
+ function connect(state, send, normalize) {
259
213
  const messages = state.context.messages;
260
214
  const isFocused = state.matches("focused");
261
215
  return {
@@ -1,6 +1,6 @@
1
- import { PropTypes, ReactPropTypes } from "@zag-js/types";
1
+ import type { NormalizeProps, PropTypes } from "@zag-js/types";
2
2
  import type { Send, State, TabProps } from "./tabs.types";
3
- export declare function connect<T extends PropTypes = ReactPropTypes>(state: State, send: Send, normalize?: import("@zag-js/types").NormalizeProps): {
3
+ export declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
4
4
  value: string;
5
5
  focusedValue: string;
6
6
  previousValues: string[];
@@ -1,4 +1,4 @@
1
- import { MachineContext as Ctx } from "./tabs.types";
1
+ import type { MachineContext as Ctx } from "./tabs.types";
2
2
  export declare const dom: {
3
3
  getDoc: (ctx: Ctx) => Document;
4
4
  getRootNode: (ctx: Ctx) => Document | ShadowRoot;
@@ -1,2 +1,2 @@
1
- import { MachineContext, MachineState, UserDefinedContext } from "./tabs.types";
1
+ import type { MachineContext, MachineState, UserDefinedContext } from "./tabs.types";
2
2
  export declare function machine(ctx?: UserDefinedContext): import("@zag-js/core").Machine<MachineContext, MachineState, import("@zag-js/core").StateMachine.AnyEventObject>;
@@ -1,5 +1,5 @@
1
- import { StateMachine as S } from "@zag-js/core";
2
- import { Context, DirectionProperty } from "@zag-js/types";
1
+ import type { StateMachine as S } from "@zag-js/core";
2
+ import type { Context, DirectionProperty } from "@zag-js/types";
3
3
  declare type IntlMessages = {
4
4
  tablistLabel?: string;
5
5
  deleteLabel?(value: string): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/tabs",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "Core logic for the tabs widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -29,9 +29,9 @@
29
29
  "url": "https://github.com/chakra-ui/zag/issues"
30
30
  },
31
31
  "dependencies": {
32
- "@zag-js/core": "0.1.6",
33
- "@zag-js/dom-utils": "0.1.5",
34
- "@zag-js/types": "0.2.0",
32
+ "@zag-js/core": "0.1.7",
33
+ "@zag-js/dom-utils": "0.1.6",
34
+ "@zag-js/types": "0.2.1",
35
35
  "@zag-js/utils": "0.1.2"
36
36
  },
37
37
  "scripts": {