@zag-js/tabs 0.0.0-dev-20220627213436 → 0.0.0-dev-20220703125047

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,40 @@ 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 getCache() {
66
- const g = globalThis;
67
- g.__styleCache__ = g.__styleCache__ || /* @__PURE__ */ new WeakMap();
68
- return g.__styleCache__;
69
- }
70
- function getComputedStyle(el) {
71
- var _a;
72
- if (!el)
73
- return {};
74
- const cache = getCache();
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;
46
+ function isFrame(element) {
47
+ return element.localName === "iframe";
82
48
  }
83
49
  function isHTMLElement(v) {
84
50
  return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
85
51
  }
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;
52
+ function isVisible(el) {
53
+ if (!isHTMLElement(el))
54
+ return false;
55
+ return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
118
56
  }
119
- var getFocusables = (el, includeContainer = false) => {
120
- if (!el)
57
+ 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";
58
+ var getFocusables = (container, includeContainer = false) => {
59
+ if (!container)
121
60
  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);
61
+ const elements = Array.from(container.querySelectorAll(focusableSelector));
62
+ const include = includeContainer == true || includeContainer == "if-empty" && elements.length === 0;
63
+ if (include && isHTMLElement(container) && isFocusable(container)) {
64
+ elements.unshift(container);
126
65
  }
127
- return els.filter((el2) => isFocusable(el2) && !isHidden(el2));
66
+ const focusableElements = elements.filter(isFocusable);
67
+ focusableElements.forEach((element, i) => {
68
+ if (isFrame(element) && element.contentDocument) {
69
+ const frameBody = element.contentDocument.body;
70
+ focusableElements.splice(i, 1, ...getFocusables(frameBody));
71
+ }
72
+ });
73
+ return focusableElements;
128
74
  };
129
- var isFocusable = (el) => {
130
- if (!isHTMLElement(el) || isHidden(el) || isDisabled(el))
75
+ function isFocusable(element) {
76
+ if (!element)
131
77
  return false;
132
- return el == null ? void 0 : el.matches(focusableSelector);
133
- };
78
+ return element.matches(focusableSelector) && isVisible(element);
79
+ }
134
80
  var rtlKeyMap = {
135
81
  ArrowLeft: "ArrowRight",
136
82
  ArrowRight: "ArrowLeft",
@@ -157,6 +103,25 @@ function getEventKey(event, options = {}) {
157
103
  }
158
104
  return key;
159
105
  }
106
+ function nextTick(fn) {
107
+ const set = /* @__PURE__ */ new Set();
108
+ function raf2(fn2) {
109
+ const id = globalThis.requestAnimationFrame(fn2);
110
+ set.add(() => globalThis.cancelAnimationFrame(id));
111
+ }
112
+ raf2(() => raf2(fn));
113
+ return function cleanup() {
114
+ set.forEach(function(fn2) {
115
+ fn2();
116
+ });
117
+ };
118
+ }
119
+ function raf(fn) {
120
+ const id = globalThis.requestAnimationFrame(fn);
121
+ return function cleanup() {
122
+ globalThis.cancelAnimationFrame(id);
123
+ };
124
+ }
160
125
  function queryAll(root, selector) {
161
126
  var _a;
162
127
  return Array.from((_a = root == null ? void 0 : root.querySelectorAll(selector)) != null ? _a : []);
@@ -181,16 +146,6 @@ function prevById(v, id, loop = true) {
181
146
  return v[idx];
182
147
  }
183
148
 
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
149
  // ../../utilities/core/dist/index.mjs
195
150
  var first = (v) => v[0];
196
151
  var last = (v) => v[v.length - 1];
@@ -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
@@ -20,94 +20,40 @@ var __spreadValues = (a, b) => {
20
20
  var dataAttr = (guard) => {
21
21
  return guard ? "" : void 0;
22
22
  };
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 getCache() {
43
- const g = globalThis;
44
- g.__styleCache__ = g.__styleCache__ || /* @__PURE__ */ new WeakMap();
45
- return g.__styleCache__;
46
- }
47
- function getComputedStyle(el) {
48
- var _a;
49
- if (!el)
50
- return {};
51
- const cache = getCache();
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;
23
+ function isFrame(element) {
24
+ return element.localName === "iframe";
59
25
  }
60
26
  function isHTMLElement(v) {
61
27
  return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
62
28
  }
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;
29
+ function isVisible(el) {
30
+ if (!isHTMLElement(el))
31
+ return false;
32
+ return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
95
33
  }
96
- var getFocusables = (el, includeContainer = false) => {
97
- if (!el)
34
+ 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";
35
+ var getFocusables = (container, includeContainer = false) => {
36
+ if (!container)
98
37
  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);
38
+ const elements = Array.from(container.querySelectorAll(focusableSelector));
39
+ const include = includeContainer == true || includeContainer == "if-empty" && elements.length === 0;
40
+ if (include && isHTMLElement(container) && isFocusable(container)) {
41
+ elements.unshift(container);
103
42
  }
104
- return els.filter((el2) => isFocusable(el2) && !isHidden(el2));
43
+ const focusableElements = elements.filter(isFocusable);
44
+ focusableElements.forEach((element, i) => {
45
+ if (isFrame(element) && element.contentDocument) {
46
+ const frameBody = element.contentDocument.body;
47
+ focusableElements.splice(i, 1, ...getFocusables(frameBody));
48
+ }
49
+ });
50
+ return focusableElements;
105
51
  };
106
- var isFocusable = (el) => {
107
- if (!isHTMLElement(el) || isHidden(el) || isDisabled(el))
52
+ function isFocusable(element) {
53
+ if (!element)
108
54
  return false;
109
- return el == null ? void 0 : el.matches(focusableSelector);
110
- };
55
+ return element.matches(focusableSelector) && isVisible(element);
56
+ }
111
57
  var rtlKeyMap = {
112
58
  ArrowLeft: "ArrowRight",
113
59
  ArrowRight: "ArrowLeft",
@@ -134,6 +80,25 @@ function getEventKey(event, options = {}) {
134
80
  }
135
81
  return key;
136
82
  }
83
+ function nextTick(fn) {
84
+ const set = /* @__PURE__ */ new Set();
85
+ function raf2(fn2) {
86
+ const id = globalThis.requestAnimationFrame(fn2);
87
+ set.add(() => globalThis.cancelAnimationFrame(id));
88
+ }
89
+ raf2(() => raf2(fn));
90
+ return function cleanup() {
91
+ set.forEach(function(fn2) {
92
+ fn2();
93
+ });
94
+ };
95
+ }
96
+ function raf(fn) {
97
+ const id = globalThis.requestAnimationFrame(fn);
98
+ return function cleanup() {
99
+ globalThis.cancelAnimationFrame(id);
100
+ };
101
+ }
137
102
  function queryAll(root, selector) {
138
103
  var _a;
139
104
  return Array.from((_a = root == null ? void 0 : root.querySelectorAll(selector)) != null ? _a : []);
@@ -158,16 +123,6 @@ function prevById(v, id, loop = true) {
158
123
  return v[idx];
159
124
  }
160
125
 
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
126
  // ../../utilities/core/dist/index.mjs
172
127
  var first = (v) => v[0];
173
128
  var last = (v) => v[v.length - 1];
@@ -255,7 +210,7 @@ var dom = {
255
210
  };
256
211
 
257
212
  // src/tabs.connect.ts
258
- function connect(state, send, normalize = normalizeProp) {
213
+ function connect(state, send, normalize) {
259
214
  const messages = state.context.messages;
260
215
  const isFocused = state.matches("focused");
261
216
  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[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/tabs",
3
- "version": "0.0.0-dev-20220627213436",
3
+ "version": "0.0.0-dev-20220703125047",
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.0.0-dev-20220627213436",
33
- "@zag-js/dom-utils": "0.0.0-dev-20220627213436",
34
- "@zag-js/types": "0.2.0",
32
+ "@zag-js/core": "0.0.0-dev-20220703125047",
33
+ "@zag-js/dom-utils": "0.0.0-dev-20220703125047",
34
+ "@zag-js/types": "0.0.0-dev-20220703125047",
35
35
  "@zag-js/utils": "0.1.2"
36
36
  },
37
37
  "scripts": {